@@ -84,22 +84,19 @@ export default class DigitalMarketplace extends arc4.Contract {
8484 asset : new arc4 . UintN64 ( xfer . xferAsset . id ) ,
8585 nonce : nonce ,
8686 } )
87- assert ( ! this . listings . has ( key ) )
87+ assert ( ! this . listings ( key ) . exists )
8888
8989 assert ( xfer . sender === Txn . sender )
9090 assert ( xfer . assetReceiver === Global . currentApplicationAddress )
9191 assert ( xfer . assetAmount > 0 )
9292
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+ } )
103100 }
104101
105102 @arc4 . abimethod ( )
@@ -114,17 +111,14 @@ export default class DigitalMarketplace extends arc4.Contract {
114111 assert ( xfer . assetReceiver === Global . currentApplicationAddress )
115112 assert ( xfer . assetAmount > 0 )
116113
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+ } )
128122 }
129123
130124 @arc4 . abimethod ( )
@@ -135,17 +129,14 @@ export default class DigitalMarketplace extends arc4.Contract {
135129 nonce : nonce ,
136130 } )
137131
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+ } )
149140 }
150141
151142 @arc4 . abimethod ( )
@@ -156,24 +147,21 @@ export default class DigitalMarketplace extends arc4.Contract {
156147 nonce : nonce ,
157148 } )
158149
159- const listing = this . listings . get ( key )
150+ const listing = this . listings ( key ) . value
160151
161152 const amountToBePaid = this . quantityPrice ( quantity , listing . unitaryPrice . native , asset . decimals )
162153
163154 assert ( buyPay . sender === Txn . sender )
164155 assert ( buyPay . receiver . bytes === owner . bytes )
165156 assert ( buyPay . amount === amountToBePaid )
166157
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+ } )
177165
178166 itxn
179167 . assetTransfer ( {
@@ -192,13 +180,13 @@ export default class DigitalMarketplace extends arc4.Contract {
192180 nonce : nonce ,
193181 } )
194182
195- const listing = this . listings . get ( key )
183+ const listing = this . listings ( key ) . value
196184 if ( listing . bidder !== new arc4 . Address ( ) ) {
197185 const currentBidDeposit = this . quantityPrice ( listing . bid . native , listing . bidUnitaryPrice . native , asset . decimals )
198186 itxn . payment ( { receiver : listing . bidder . native , amount : currentBidDeposit } ) . submit ( )
199187 }
200188
201- this . listings . delete ( key )
189+ this . listings ( key ) . delete ( )
202190
203191 itxn . payment ( { receiver : Txn . sender , amount : this . listingsBoxMbr ( ) } ) . submit ( )
204192
@@ -215,7 +203,7 @@ export default class DigitalMarketplace extends arc4.Contract {
215203 bid ( owner : arc4 . Address , asset : Asset , nonce : arc4 . UintN64 , bidPay : gtxn . PaymentTxn , quantity : arc4 . UintN64 , unitaryPrice : arc4 . UintN64 ) {
216204 const key = new ListingKey ( { owner, asset : new arc4 . UintN64 ( asset . id ) , nonce } )
217205
218- const listing = this . listings . get ( key )
206+ const listing = this . listings ( key ) . value
219207 if ( listing . bidder !== new arc4 . Address ( ) ) {
220208 assert ( unitaryPrice . native > listing . bidUnitaryPrice . native )
221209
@@ -230,23 +218,20 @@ export default class DigitalMarketplace extends arc4.Contract {
230218 assert ( bidPay . receiver === Global . currentApplicationAddress )
231219 assert ( bidPay . amount === amountToBeBid )
232220
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+ } )
243228 }
244229
245230 @arc4 . abimethod ( )
246231 acceptBid ( asset : Asset , nonce : arc4 . UintN64 ) {
247232 const key = new ListingKey ( { owner : new arc4 . Address ( Txn . sender ) , asset : new arc4 . UintN64 ( asset . id ) , nonce } )
248233
249- const listing = this . listings . get ( key )
234+ const listing = this . listings ( key ) . value
250235 assert ( listing . bidder !== new arc4 . Address ( ) )
251236
252237 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 {
263248 } )
264249 . submit ( )
265250
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+ } )
276258 }
277259}
0 commit comments