@@ -6,6 +6,8 @@ pub struct AirdropWithTweeterOracleData {
6
6
token_type : ResourceAddress ,
7
7
#[ scrypto( mutable) ]
8
8
is_collected : bool ,
9
+ #[ scrypto( mutable) ]
10
+ is_recipient : bool
9
11
}
10
12
11
13
blueprint ! {
@@ -159,6 +161,7 @@ blueprint! {
159
161
AirdropWithTweeterOracleData {
160
162
token_type: self . tokens. resource_address( ) ,
161
163
is_collected: false ,
164
+ is_recipient: false
162
165
} ,
163
166
)
164
167
} ) ;
@@ -202,24 +205,34 @@ blueprint! {
202
205
"token address must match"
203
206
) ;
204
207
208
+ // Check if the airdrop have already been finalized
209
+ assert!(
210
+ self . amount_per_recipient == Decimal :: zero( ) ,
211
+ "The airdrop have already been finalized"
212
+ ) ;
213
+
205
214
//clear the recipients
206
215
self . recipients. clear( ) ;
207
216
208
217
// find and store recipients
209
218
self . find_and_store_airdrop_recipients( ) ;
210
219
220
+ for nft_id in self . recipients. iter( ) {
221
+ let mut nft_data : AirdropWithTweeterOracleData = borrow_resource_manager!( self . participant_badge_address)
222
+ . get_non_fungible_data( nft_id) ;
223
+ nft_data. is_recipient = true ;
224
+ self . minter_badge_vault. authorize( || {
225
+ borrow_resource_manager!( self . participant_badge_address)
226
+ . update_non_fungible_data( nft_id , nft_data) ;
227
+ } ) ;
228
+ }
229
+
211
230
// check recipients
212
231
assert!(
213
232
self . recipients. len( ) > 0 ,
214
233
"there is no recipient for the airdrop"
215
234
) ;
216
235
217
- // Check if the airdrop have already been finalized
218
- assert!(
219
- self . amount_per_recipient == Decimal :: zero( ) ,
220
- "The airdrop have already been finalized"
221
- ) ;
222
-
223
236
// Calculate the amount of tokens each recipient can receive
224
237
let amount_per_recipient =
225
238
tokens. amount( ) / Decimal :: from( self . recipients. len( ) as i128 ) ;
@@ -254,14 +267,15 @@ blueprint! {
254
267
) ;
255
268
// checking badge amount
256
269
assert_eq!( auth. amount( ) , dec!( "1" ) , "Invalid Badge Provided" ) ;
257
- let nft_id = auth. non_fungible:: <AirdropWithTweeterOracleData >( ) . id( ) ;
270
+
271
+ let mut nft_data = auth. non_fungible:: <AirdropWithTweeterOracleData >( ) . data( ) ;
258
272
259
273
// checking if current user completed all tasks
260
274
assert!(
261
- self . recipients . contains ( & nft_id ) ,
275
+ nft_data . is_recipient ,
262
276
"you cannot receive the airdrop because you have not excuted all tasks"
263
277
) ;
264
- let mut nft_data = auth . non_fungible :: < AirdropWithTweeterOracleData > ( ) . data ( ) ;
278
+
265
279
266
280
// checking if withdrawal is already done
267
281
assert!( !nft_data. is_collected, "withdraw is already done" ) ;
0 commit comments