@@ -84,22 +84,19 @@ export default class DigitalMarketplace extends arc4.Contract {
84
84
asset : new arc4 . UintN64 ( xfer . xferAsset . id ) ,
85
85
nonce : nonce ,
86
86
} )
87
- assert ( ! this . listings . has ( key ) )
87
+ assert ( ! this . listings ( key ) . exists )
88
88
89
89
assert ( xfer . sender === Txn . sender )
90
90
assert ( xfer . assetReceiver === Global . currentApplicationAddress )
91
91
assert ( xfer . assetAmount > 0 )
92
92
93
- this . listings . set (
94
- key ,
95
- new ListingValue ( {
96
- deposited : new arc4 . UintN64 ( xfer . assetAmount ) ,
97
- unitaryPrice : unitaryPrice ,
98
- bidder : new arc4 . Address ( ) ,
99
- bid : new arc4 . UintN64 ( ) ,
100
- bidUnitaryPrice : new arc4 . UintN64 ( ) ,
101
- } ) ,
102
- )
93
+ this . listings ( key ) . value = new ListingValue ( {
94
+ deposited : new arc4 . UintN64 ( xfer . assetAmount ) ,
95
+ unitaryPrice : unitaryPrice ,
96
+ bidder : new arc4 . Address ( ) ,
97
+ bid : new arc4 . UintN64 ( ) ,
98
+ bidUnitaryPrice : new arc4 . UintN64 ( ) ,
99
+ } )
103
100
}
104
101
105
102
@arc4 . abimethod ( )
@@ -114,17 +111,14 @@ export default class DigitalMarketplace extends arc4.Contract {
114
111
assert ( xfer . assetReceiver === Global . currentApplicationAddress )
115
112
assert ( xfer . assetAmount > 0 )
116
113
117
- const existing = this . listings . get ( key )
118
- this . listings . set (
119
- key ,
120
- new ListingValue ( {
121
- bid : existing . bid ,
122
- bidUnitaryPrice : existing . bidUnitaryPrice ,
123
- bidder : existing . bidder ,
124
- unitaryPrice : existing . unitaryPrice ,
125
- deposited : new arc4 . UintN64 ( existing . deposited . native + xfer . assetAmount ) ,
126
- } ) ,
127
- )
114
+ const existing = this . listings ( key ) . value
115
+ this . listings ( key ) . value = new ListingValue ( {
116
+ bid : existing . bid ,
117
+ bidUnitaryPrice : existing . bidUnitaryPrice ,
118
+ bidder : existing . bidder ,
119
+ unitaryPrice : existing . unitaryPrice ,
120
+ deposited : new arc4 . UintN64 ( existing . deposited . native + xfer . assetAmount ) ,
121
+ } )
128
122
}
129
123
130
124
@arc4 . abimethod ( )
@@ -135,17 +129,14 @@ export default class DigitalMarketplace extends arc4.Contract {
135
129
nonce : nonce ,
136
130
} )
137
131
138
- const existing = this . listings . get ( key )
139
- this . listings . set (
140
- key ,
141
- new ListingValue ( {
142
- bid : existing . bid ,
143
- bidUnitaryPrice : existing . bidUnitaryPrice ,
144
- bidder : existing . bidder ,
145
- deposited : existing . deposited ,
146
- unitaryPrice : unitaryPrice ,
147
- } ) ,
148
- )
132
+ const existing = this . listings ( key ) . value
133
+ this . listings ( key ) . value = new ListingValue ( {
134
+ bid : existing . bid ,
135
+ bidUnitaryPrice : existing . bidUnitaryPrice ,
136
+ bidder : existing . bidder ,
137
+ deposited : existing . deposited ,
138
+ unitaryPrice : unitaryPrice ,
139
+ } )
149
140
}
150
141
151
142
@arc4 . abimethod ( )
@@ -156,24 +147,21 @@ export default class DigitalMarketplace extends arc4.Contract {
156
147
nonce : nonce ,
157
148
} )
158
149
159
- const listing = this . listings . get ( key )
150
+ const listing = this . listings ( key ) . value
160
151
161
152
const amountToBePaid = this . quantityPrice ( quantity , listing . unitaryPrice . native , asset . decimals )
162
153
163
154
assert ( buyPay . sender === Txn . sender )
164
155
assert ( buyPay . receiver . bytes === owner . bytes )
165
156
assert ( buyPay . amount === amountToBePaid )
166
157
167
- this . listings . set (
168
- key ,
169
- new ListingValue ( {
170
- bid : listing . bid ,
171
- bidUnitaryPrice : listing . bidUnitaryPrice ,
172
- bidder : listing . bidder ,
173
- unitaryPrice : listing . unitaryPrice ,
174
- deposited : new arc4 . UintN64 ( listing . deposited . native - quantity ) ,
175
- } ) ,
176
- )
158
+ this . listings ( key ) . value = new ListingValue ( {
159
+ bid : listing . bid ,
160
+ bidUnitaryPrice : listing . bidUnitaryPrice ,
161
+ bidder : listing . bidder ,
162
+ unitaryPrice : listing . unitaryPrice ,
163
+ deposited : new arc4 . UintN64 ( listing . deposited . native - quantity ) ,
164
+ } )
177
165
178
166
itxn
179
167
. assetTransfer ( {
@@ -192,13 +180,13 @@ export default class DigitalMarketplace extends arc4.Contract {
192
180
nonce : nonce ,
193
181
} )
194
182
195
- const listing = this . listings . get ( key )
183
+ const listing = this . listings ( key ) . value
196
184
if ( listing . bidder !== new arc4 . Address ( ) ) {
197
185
const currentBidDeposit = this . quantityPrice ( listing . bid . native , listing . bidUnitaryPrice . native , asset . decimals )
198
186
itxn . payment ( { receiver : listing . bidder . native , amount : currentBidDeposit } ) . submit ( )
199
187
}
200
188
201
- this . listings . delete ( key )
189
+ this . listings ( key ) . delete ( )
202
190
203
191
itxn . payment ( { receiver : Txn . sender , amount : this . listingsBoxMbr ( ) } ) . submit ( )
204
192
@@ -215,7 +203,7 @@ export default class DigitalMarketplace extends arc4.Contract {
215
203
bid ( owner : arc4 . Address , asset : Asset , nonce : arc4 . UintN64 , bidPay : gtxn . PaymentTxn , quantity : arc4 . UintN64 , unitaryPrice : arc4 . UintN64 ) {
216
204
const key = new ListingKey ( { owner, asset : new arc4 . UintN64 ( asset . id ) , nonce } )
217
205
218
- const listing = this . listings . get ( key )
206
+ const listing = this . listings ( key ) . value
219
207
if ( listing . bidder !== new arc4 . Address ( ) ) {
220
208
assert ( unitaryPrice . native > listing . bidUnitaryPrice . native )
221
209
@@ -230,23 +218,20 @@ export default class DigitalMarketplace extends arc4.Contract {
230
218
assert ( bidPay . receiver === Global . currentApplicationAddress )
231
219
assert ( bidPay . amount === amountToBeBid )
232
220
233
- this . listings . set (
234
- key ,
235
- new ListingValue ( {
236
- deposited : listing . deposited ,
237
- unitaryPrice : listing . unitaryPrice ,
238
- bidder : new arc4 . Address ( Txn . sender ) ,
239
- bid : quantity ,
240
- bidUnitaryPrice : unitaryPrice ,
241
- } ) ,
242
- )
221
+ this . listings ( key ) . value = new ListingValue ( {
222
+ deposited : listing . deposited ,
223
+ unitaryPrice : listing . unitaryPrice ,
224
+ bidder : new arc4 . Address ( Txn . sender ) ,
225
+ bid : quantity ,
226
+ bidUnitaryPrice : unitaryPrice ,
227
+ } )
243
228
}
244
229
245
230
@arc4 . abimethod ( )
246
231
acceptBid ( asset : Asset , nonce : arc4 . UintN64 ) {
247
232
const key = new ListingKey ( { owner : new arc4 . Address ( Txn . sender ) , asset : new arc4 . UintN64 ( asset . id ) , nonce } )
248
233
249
- const listing = this . listings . get ( key )
234
+ const listing = this . listings ( key ) . value
250
235
assert ( listing . bidder !== new arc4 . Address ( ) )
251
236
252
237
const minQuantity = listing . deposited . native < listing . bid . native ? listing . deposited . native : listing . bid . native
@@ -263,15 +248,12 @@ export default class DigitalMarketplace extends arc4.Contract {
263
248
} )
264
249
. submit ( )
265
250
266
- this . listings . set (
267
- key ,
268
- new ListingValue ( {
269
- bidder : listing . bidder ,
270
- bidUnitaryPrice : listing . bidUnitaryPrice ,
271
- unitaryPrice : listing . unitaryPrice ,
272
- deposited : new arc4 . UintN64 ( listing . deposited . native - minQuantity ) ,
273
- bid : new arc4 . UintN64 ( listing . bid . native - minQuantity ) ,
274
- } ) ,
275
- )
251
+ this . listings ( key ) . value = new ListingValue ( {
252
+ bidder : listing . bidder ,
253
+ bidUnitaryPrice : listing . bidUnitaryPrice ,
254
+ unitaryPrice : listing . unitaryPrice ,
255
+ deposited : new arc4 . UintN64 ( listing . deposited . native - minQuantity ) ,
256
+ bid : new arc4 . UintN64 ( listing . bid . native - minQuantity ) ,
257
+ } )
276
258
}
277
259
}
0 commit comments