Skip to content

Commit c998893

Browse files
more comments + fix bugs
1 parent 7b3af71 commit c998893

File tree

8 files changed

+57
-76
lines changed

8 files changed

+57
-76
lines changed

2-oracles/tweeter-oracle/README.md

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
# TwitterOracle
1+
# TweeterOracle
22

3-
> ✨ Bootstrapped with Create Snowpack App (CSA).
3+
This oracle stores data from the twitter API. Instantiating this component makes it possible to administer this data and make it available to those who need it within the data ledger
4+
For example is the radixdlt user account followed by the cyover user account? Or has a tweet been liked by cyover user account ?
5+
This data can be useful for automating airdrops. An example of component automating the airdrop was created to test this Oracle (AirdropWithTweeterOracle)
46

5-
## Available Scripts
7+
## Quick Start
68

7-
### npm start
9+
1. Build scrypto : `./scrypto/build.sh`
10+
2. Test TweeterOracle with shell: `cd ./tweeter-oracle/scrypto/tweeter-oracle/demo && ./tweeter_oracle.sh`
11+
3. Test TweeterOracle on web browser : `npm install && npm start` and Open http://localhost:8080 to view it in the browser.
812

9-
Runs the app in the development mode.
10-
Open http://localhost:8080 to view it in the browser.
13+
# AirdropWithTweeterOracle
14+
This component allows airdrop automation. A certain number of tasks are defined by the creators of the airdrop component : Follow 1 and/or more accounts, like a tweet and/or more tweets and/retweet one or more tweets.
15+
Users register for the airdrop via the Register method by specifying their tweeter account and receive in return a non-fungible token to claim the amount of the airdrop when possible.
16+
At the stage of finalizing the airdrop method (finalize_airdrop) the Tweeter_oracle component is used to verify that all tasks have been executed by subscribers.
1117

12-
The page will reload if you make edits.
13-
You will also see any lint errors in the console.
14-
15-
### npm run build
16-
17-
Builds a static copy of your site to the `build/` folder.
18-
Your app is ready to be deployed!
19-
20-
**For the best production performance:** Add a build bundler plugin like [@snowpack/plugin-webpack](https://github.com/snowpackjs/snowpack/tree/main/plugins/plugin-webpack) or [snowpack-plugin-rollup-bundle](https://github.com/ParamagicDev/snowpack-plugin-rollup-bundle) to your `snowpack.config.mjs` config file.
21-
22-
### Q: What about Eject?
23-
24-
No eject needed! Snowpack guarantees zero lock-in, and CSA strives for the same.
18+
## Quick Start
19+
1. tests AirdropWithTweeterOracle with shell: `cd ./tweeter-oracle/scrypto/tweeter-oracle/demo && ./airdrop_with_tweeter_oracle.sh`
318 Bytes
Binary file not shown.

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ source ./create_components.sh
22

33
#
44
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYOVER $AIRDROP_REGISTER_PVKEY_CYOVER
5-
#tweeter account cyover registring to the airdrop
5+
#tweeter account cyover subscribe to the airdrop
6+
echo 'account cyover subscribe to the airdrop'
67
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"register\" \"cyover\" ;" > tx.rtm
78
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_REGISTER_ADDRESS_CYOVER\") \"deposit_batch\";" >> tx.rtm
89
resim run tx.rtm
910

10-
# tweeter account cyrolsi registring to the airdrop
11+
# tweeter account cyrolsi subscribe to the airdrop
12+
echo 'tweeter account cyrolsi subscribe to the airdrop'
1113
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYROLSI $AIRDROP_REGISTER_PVKEY_CYROLSI
1214
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"register\" \"cyrolsi\" ;" > tx.rtm
1315
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_REGISTER_ADDRESS_CYROLSI\") \"deposit_batch\";" >> tx.rtm
1416
resim run tx.rtm
1517

1618

1719
#cyover has completed alls tasks need by the airdrop (like radixdlt, like and reweet tweet1) in contrast to cyrolsi
20+
echo 'cyover has completed alls tasks need by the airdrop (like radixdlt, like and reweet tweet1) in contrast to cyrolsi '
1821
resim set-default-account $TWEETER_ORACLE_ADMIN_ADDRESS $TWEETER_ORACLE_ADMIN_PVKEY
1922
#inserting datas by TWEETER_ORACLE_ADMIN_ADDRESS
2023
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
@@ -24,15 +27,16 @@ echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_tweet
2427
resim run tx.rtm
2528

2629

27-
#AIRDROP_ADMIN_ADDRESS find and store airdrop recipeints and finalize it
30+
#AIRDROP_ADMIN_ADDRESS find and store airdrop recipients and finalize it
31+
echo 'AIRDROP_ADMIN_ADDRESS find and store airdrop recipients and finalize it'
2832
resim set-default-account $AIRDROP_ADMIN_ADDRESS $AIRDROP_ADMIN_PVKEY
2933
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
3034
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"find_and_store_airdrop_recipients\" ;" >> tx.rtm
3135
resim run tx.rtm
3236

3337
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
3438
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"withdraw\" ResourceAddress(\"$XRD\");" >> tx.rtm
35-
echo "TAKE_FROM_WORKTOP_BY_AMOUNT Decimal(\"100\") ResourceAddress(\"$XRD\") Bucket(\"xrd_bucket\");" >> tx.rtm
39+
echo "TAKE_FROM_WORKTOP_BY_AMOUNT Decimal(\"1000\") ResourceAddress(\"$XRD\") Bucket(\"xrd_bucket\");" >> tx.rtm
3640
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"finalize_airdrop\" Bucket(\"xrd_bucket\") ;" >> tx.rtm
3741
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"deposit_batch\";" >> tx.rtm
3842
resim run tx.rtm
@@ -42,13 +46,15 @@ rm tx.rtm
4246
#withdraw
4347

4448
#cyover withdraw is success
49+
echo 'cyover withdrawal is a success '
4550
resim show $AIRDROP_REGISTER_ADDRESS_CYOVER
4651
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYOVER $AIRDROP_REGISTER_PVKEY_CYOVER
4752
resim call-method $AIRDROP_WITH_TWEETER_ORACLE_COMPONENT "withdraw" 1,$AIRDROP_WITH_TWEETER_ORACLE_PARTICIPANT_BADGE
4853
resim show $AIRDROP_REGISTER_ADDRESS_CYOVER
4954

5055

51-
#cyrolsi try to withdraw and get error because he is not a recipient
56+
#cyrolsi try to withdraw and get error
57+
echo 'cyrolsi withdrawal is a failure'
5258
resim show $AIRDROP_REGISTER_ADDRESS_CYROLSI
5359
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYROLSI $AIRDROP_REGISTER_PVKEY_CYROLSI
5460
resim call-method $AIRDROP_WITH_TWEETER_ORACLE_COMPONENT "withdraw" 1,$AIRDROP_WITH_TWEETER_ORACLE_PARTICIPANT_BADGE

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

-23
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,6 @@
22
set -x
33
set -e
44

5-
# Setup a baseline environment with 2 users each holding a resource they would
6-
# trade.
7-
#
8-
# To avoid parsing resim output I've manually set the variables based on their
9-
# (deterministic) values.
10-
#
11-
# The "Maker" has a pre-swap setup phase where they make sure they have an
12-
# account to fund trades from and instantate the Maker Component to handle
13-
# exzecution of their orders by a sender. This only needs to be done once, no
14-
# matter how many trades they sign of any resource type.
15-
#
16-
# The "Taker" has a pre-swap setup phase where they nominate (or create) a
17-
# unique resource they own to act as a badge to prevent frontrunning the
18-
# transaction submission. Note their transaction signing key could be used as
19-
# a virtual badge for this purpose to avoid a pre-swap ledger interaction by
20-
# the Taker. But, I'm choosing to be explicit for readability/flexibility to
21-
# show this need not be directly tied to a given public key. Anyone with the
22-
# badge could submit the signed order.
23-
24-
25-
##############################
26-
27-
285
resim reset
296

307
XRD=030000000000000000000000000000000000000000000000000004

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,25 @@ echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_tweet
2121
resim run tx.rtm
2222

2323

24-
#checking datas
24+
#checking datas after inserting
2525
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_account_follower\" \"radixdlt\" \"cyover\";" > tx.rtm
2626
resim run tx.rtm
2727
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_liker\" \"tweet1\" \"cyover\";" > tx.rtm
2828
resim run tx.rtm
2929
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_liker\" \"tweet1\" \"titi\";" > tx.rtm
3030
resim run tx.rtm
31-
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_retweeter\" \"tweet1\" \"cyover\";" > tx.rtm
31+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_retweeter\" \"tweet1\" \"cyrolsi\";" > tx.rtm
3232
resim run tx.rtm
3333
#cyover user follow radixdlt, like and retweet tweet1
3434

35+
resim set-default-account $TWEETER_ORACLE_ADMIN_ADDRESS $TWEETER_ORACLE_ADMIN_PVKEY
36+
#removing datas by TWEETER_ORACLE_ADMIN_ADDRESS
37+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
38+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"remove_account_followers\" \"radixdlt\" HashSet<String>(\"cyover\");" >> tx.rtm
39+
resim run tx.rtm
40+
41+
#checking data after removing
42+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_account_follower\" \"radixdlt\" \"cyover\";" > tx.rtm
43+
resim run tx.rtm
44+
45+
rm tx.rtm

2-oracles/tweeter-oracle/scrypto/tweeter-oracle/demo/tx.rtm

-1
This file was deleted.

2-oracles/tweeter-oracle/scrypto/tweeter-oracle/src/airdrop_with_twitter_oracle.rs renamed to 2-oracles/tweeter-oracle/scrypto/tweeter-oracle/src/airdrop_with_tweeter_oracle.rs

+18-25
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ blueprint! {
137137
"already registered to this airdrop"
138138
);
139139

140-
// Check if the airdrop were already finalize
140+
// Check if the airdrop has already been finalized
141141
assert!(
142142
self.amount_per_recipient == Decimal::zero(),
143-
"The airdrop were already finalize"
143+
"The airdrop has already been finalized"
144144
);
145145
// Generate NonFungibleId for participant
146146
let id = NonFungibleId::random();
@@ -167,7 +167,7 @@ blueprint! {
167167
return participant_badge;
168168
}
169169

170-
//This find the participants that have completed the tasks and to store them
170+
//This find the participants who have completed the tasks and to store them
171171
pub fn find_and_store_airdrop_recipients(&mut self) -> usize {
172172
//find partcipants who made all tasks
173173
for nft_id in self.airdrop_participants.keys() {
@@ -185,7 +185,7 @@ blueprint! {
185185
return self.recipients.len();
186186
}
187187

188-
// this method makes it possible to finalize the airdrop
188+
// this method allows to finalize the airdrop
189189
// #Arguments
190190
// * `tokens` Bucket containing the tokens to distribute
191191
pub fn finalize_airdrop(&mut self, mut tokens: Bucket) -> Bucket {
@@ -202,36 +202,27 @@ blueprint! {
202202
"token address must match"
203203
);
204204

205+
//clear the recipients
206+
self.recipients.clear();
207+
208+
// find and store recipients
209+
self.find_and_store_airdrop_recipients();
210+
205211
// check recipients
206212
assert!(
207213
self.recipients.len() > 0,
208214
"there is no recipient for the airdrop"
209215
);
210216

211-
// Check if the airdrop were already finalize
217+
// Check if the airdrop have already been finalized
212218
assert!(
213219
self.amount_per_recipient == Decimal::zero(),
214-
"The airdrop were already finalize"
220+
"The airdrop have already been finalized"
215221
);
216222

217-
// check tokens quantity for NonFungible
218-
// assert!(
219-
// borrow_resource_manager!(tokens.resource_address()).resource_type()
220-
// == ResourceType::NonFungible && tokens.amount() >= Decimal::from(self.recipients.len() as i128 ) ,
221-
// "For non-fungible tokens, a number at least equal to the number of recipients is required"
222-
// );
223-
224223
// Calculate the amount of tokens each recipient can receive
225-
let mut amount_per_recipient =
224+
let amount_per_recipient =
226225
tokens.amount() / Decimal::from(self.recipients.len() as i128);
227-
228-
// // Special case for NonFongible Token
229-
// if borrow_resource_manager!(tokens.resource_address()).resource_type()
230-
// == ResourceType::NonFungible
231-
// {
232-
// amount_per_recipient =
233-
// Decimal::from(amount_per_recipient.round(18, RoundingMode::TowardsZero));
234-
// }
235226

236227
self.amount_per_recipient = amount_per_recipient;
237228

@@ -246,7 +237,7 @@ blueprint! {
246237

247238
//This method allows recipients to withdraw their tokens
248239
//#Arguments
249-
//* `auth` Aidrop registration proof
240+
//* `auth` Airdrop registration proof
250241
//#Return
251242
// This function return a bucket containing the quantity of tokens to be distributed
252243
pub fn withdraw(&mut self, auth: Proof) -> Bucket {
@@ -264,14 +255,16 @@ blueprint! {
264255
// checking badge amount
265256
assert_eq!(auth.amount(), dec!("1"), "Invalid Badge Provided");
266257
let nft_id = auth.non_fungible::<AirdropWithTweeterOracleData>().id();
258+
267259
// checking if current user completed all tasks
268260
assert!(
269261
self.recipients.contains(&nft_id),
270262
"you cannot receive the airdrop because you have not excuted all tasks"
271263
);
272264
let mut nft_data = auth.non_fungible::<AirdropWithTweeterOracleData>().data();
265+
273266
// checking if withdrawal is already done
274-
assert!(!nft_data.is_collected, "withdraw already done");
267+
assert!(!nft_data.is_collected, "withdraw is already done");
275268
nft_data.is_collected = true;
276269
let amount = self.amount_per_recipient;
277270
// update nft data
@@ -280,13 +273,13 @@ blueprint! {
280273
auth.non_fungible().update_data(nft_data);
281274
}
282275
});
276+
283277
info!("withdraw_token : {}", amount);
284278
// return tokens to caller
285279
return self.tokens.take(amount);
286280
}
287281

288282
fn has_completed_all_tasks(&self, participant_tweeter_account: String) -> bool {
289-
290283
let is_follower = self.accounts_to_follow.len() == 0
291284
|| self.accounts_to_follow.clone().into_iter().all(|x| {
292285
self.tweeter_oracle
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mod airdrop_with_twitter_oracle;
1+
mod airdrop_with_tweeter_oracle;
22
mod tweeter_oracle;
33
mod utils;

0 commit comments

Comments
 (0)