Skip to content

Commit baa7215

Browse files
add is_recipient
1 parent c998893 commit baa7215

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed
Binary file not shown.

2-oracles/tweeter-oracle/scrypto/tweeter-oracle/demo/airdrop_with_tweeter_oracle.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ rm tx.rtm
4545

4646
#withdraw
4747

48-
#cyover withdraw is success
48+
#cyover withdrawal is a success
4949
echo 'cyover withdrawal is a success '
5050
resim show $AIRDROP_REGISTER_ADDRESS_CYOVER
5151
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYOVER $AIRDROP_REGISTER_PVKEY_CYOVER
5252
resim call-method $AIRDROP_WITH_TWEETER_ORACLE_COMPONENT "withdraw" 1,$AIRDROP_WITH_TWEETER_ORACLE_PARTICIPANT_BADGE
5353
resim show $AIRDROP_REGISTER_ADDRESS_CYOVER
5454

5555

56-
#cyrolsi try to withdraw and get error
56+
#cyrolsi withdrawal is a failure
5757
echo 'cyrolsi withdrawal is a failure'
5858
resim show $AIRDROP_REGISTER_ADDRESS_CYROLSI
5959
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYROLSI $AIRDROP_REGISTER_PVKEY_CYROLSI

2-oracles/tweeter-oracle/scrypto/tweeter-oracle/src/airdrop_with_tweeter_oracle.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub struct AirdropWithTweeterOracleData {
66
token_type: ResourceAddress,
77
#[scrypto(mutable)]
88
is_collected: bool,
9+
#[scrypto(mutable)]
10+
is_recipient: bool
911
}
1012

1113
blueprint! {
@@ -159,6 +161,7 @@ blueprint! {
159161
AirdropWithTweeterOracleData {
160162
token_type: self.tokens.resource_address(),
161163
is_collected: false,
164+
is_recipient: false
162165
},
163166
)
164167
});
@@ -202,24 +205,34 @@ blueprint! {
202205
"token address must match"
203206
);
204207

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+
205214
//clear the recipients
206215
self.recipients.clear();
207216

208217
// find and store recipients
209218
self.find_and_store_airdrop_recipients();
210219

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+
211230
// check recipients
212231
assert!(
213232
self.recipients.len() > 0,
214233
"there is no recipient for the airdrop"
215234
);
216235

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-
223236
// Calculate the amount of tokens each recipient can receive
224237
let amount_per_recipient =
225238
tokens.amount() / Decimal::from(self.recipients.len() as i128);
@@ -254,14 +267,15 @@ blueprint! {
254267
);
255268
// checking badge amount
256269
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();
258272

259273
// checking if current user completed all tasks
260274
assert!(
261-
self.recipients.contains(&nft_id),
275+
nft_data.is_recipient,
262276
"you cannot receive the airdrop because you have not excuted all tasks"
263277
);
264-
let mut nft_data = auth.non_fungible::<AirdropWithTweeterOracleData>().data();
278+
265279

266280
// checking if withdrawal is already done
267281
assert!(!nft_data.is_collected, "withdraw is already done");

0 commit comments

Comments
 (0)