Skip to content

Commit 7b3af71

Browse files
add demo et fix bugs
1 parent 818d02a commit 7b3af71

13 files changed

+498
-263
lines changed

2-oracles/tweeter-oracle/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
> ✨ Bootstrapped with Create Snowpack App (CSA).
44
5-
### ./scrypto/build.sh
6-
75
## Available Scripts
86

97
### npm start

2-oracles/tweeter-oracle/public/index.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ <h2>11.Check if retweeter </h2>
103103
<p>Is liker ? :<br><pre id="checkIfRetweeterResponse"></pre></p>
104104
<p>Check if liker Receipt:<br><pre id="checkIfRetweeterReceipt"></pre></p>
105105

106-
<h2>12. Fetch User Account Address</h2>
107-
<p><button id="fetchAccountAddress">Change Account on PTE and Click me</button> to get the account address of the PTE Browser Extension user.</p>
108-
<p>Account Address: <pre id="accountAddress"></pre></p>
109-
110-
<h2>13.Airdrop Component</h2>
106+
<h2>12. Instanciate airdrop component with oracle tweeter component</h2>
111107
<p>
112108
accounts to follow (use ; as separator) <input type="text" id="accountsToFollow" />
113109
</p>
@@ -120,5 +116,10 @@ <h2>13.Airdrop Component</h2>
120116
<p><button id="instantiateAirdropComponent">Instantiate</button></p>
121117
<p>Airdrop Component Address:<br> <pre id="airdropComponentAddress"></pre></p>
122118

119+
<h2>13. Find and store airdrop recipients </h2>
120+
121+
<p><button id="findAndStoreAirdropRecipients">Find and store airdrop recipients</button></p>
122+
<p>Find and store airdrop recipients:<br> <pre id="findAndStoreAirdropRecipientsReceipt"></pre></p>
123+
123124
</body>
124125
</html>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
source ./create_components.sh
2+
3+
#
4+
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYOVER $AIRDROP_REGISTER_PVKEY_CYOVER
5+
#tweeter account cyover registring to the airdrop
6+
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"register\" \"cyover\" ;" > tx.rtm
7+
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_REGISTER_ADDRESS_CYOVER\") \"deposit_batch\";" >> tx.rtm
8+
resim run tx.rtm
9+
10+
# tweeter account cyrolsi registring to the airdrop
11+
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYROLSI $AIRDROP_REGISTER_PVKEY_CYROLSI
12+
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"register\" \"cyrolsi\" ;" > tx.rtm
13+
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_REGISTER_ADDRESS_CYROLSI\") \"deposit_batch\";" >> tx.rtm
14+
resim run tx.rtm
15+
16+
17+
#cyover has completed alls tasks need by the airdrop (like radixdlt, like and reweet tweet1) in contrast to cyrolsi
18+
resim set-default-account $TWEETER_ORACLE_ADMIN_ADDRESS $TWEETER_ORACLE_ADMIN_PVKEY
19+
#inserting datas by TWEETER_ORACLE_ADMIN_ADDRESS
20+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
21+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_account_followers\" \"radixdlt\" HashSet<String>(\"cyover\",\"ade\");" >> tx.rtm
22+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_tweets_likers\" \"tweet1\" HashSet<String>(\"cyover\",\"cyrolsi\",\"vivi\");" >> tx.rtm
23+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_tweets_retweeters\" \"tweet1\" HashSet<String>(\"cyover\",\"cyrolsi\");" >> tx.rtm
24+
resim run tx.rtm
25+
26+
27+
#AIRDROP_ADMIN_ADDRESS find and store airdrop recipeints and finalize it
28+
resim set-default-account $AIRDROP_ADMIN_ADDRESS $AIRDROP_ADMIN_PVKEY
29+
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
30+
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"find_and_store_airdrop_recipients\" ;" >> tx.rtm
31+
resim run tx.rtm
32+
33+
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
34+
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
36+
echo "CALL_METHOD ComponentAddress(\"$AIRDROP_WITH_TWEETER_ORACLE_COMPONENT\") \"finalize_airdrop\" Bucket(\"xrd_bucket\") ;" >> tx.rtm
37+
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"deposit_batch\";" >> tx.rtm
38+
resim run tx.rtm
39+
rm tx.rtm
40+
41+
42+
#withdraw
43+
44+
#cyover withdraw is success
45+
resim show $AIRDROP_REGISTER_ADDRESS_CYOVER
46+
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYOVER $AIRDROP_REGISTER_PVKEY_CYOVER
47+
resim call-method $AIRDROP_WITH_TWEETER_ORACLE_COMPONENT "withdraw" 1,$AIRDROP_WITH_TWEETER_ORACLE_PARTICIPANT_BADGE
48+
resim show $AIRDROP_REGISTER_ADDRESS_CYOVER
49+
50+
51+
#cyrolsi try to withdraw and get error because he is not a recipient
52+
resim show $AIRDROP_REGISTER_ADDRESS_CYROLSI
53+
resim set-default-account $AIRDROP_REGISTER_ADDRESS_CYROLSI $AIRDROP_REGISTER_PVKEY_CYROLSI
54+
resim call-method $AIRDROP_WITH_TWEETER_ORACLE_COMPONENT "withdraw" 1,$AIRDROP_WITH_TWEETER_ORACLE_PARTICIPANT_BADGE
55+
resim show $AIRDROP_REGISTER_ADDRESS_CYROLSI
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env sh
2+
set -x
3+
set -e
4+
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+
28+
resim reset
29+
30+
XRD=030000000000000000000000000000000000000000000000000004
31+
# initial
32+
# resim publish ../target/wasm32-unknown-unknown/release/tweeter_oracle.wasm
33+
PACKAGE=`resim publish ../target/wasm32-unknown-unknown/release/tweeter_oracle.wasm | tee /dev/tty | awk '/Package:/ {print $NF}'`
34+
echo $PACKAGE
35+
36+
# baseline Oracle Admin account
37+
echo "Oracle Admin account"
38+
out=`resim new-account | tee /dev/tty | awk '/Account component address:|Public key:|Private key:/ {print $NF}'`
39+
TWEETER_ORACLE_ADMIN_ADDRESS=`echo $out | cut -d " " -f1`
40+
TWEETER_ORACLE_ADMIN_PUBKEY=`echo $out | cut -d " " -f2`
41+
TWEETER_ORACLE_ADMIN_PVKEY=`echo $out | cut -d " " -f3`
42+
43+
echo "AIRDROP_ADMIN account (a System Account)"
44+
out=`resim new-account | tee /dev/tty | awk '/Account component address:|Public key:|Private key:/ {print $NF}'`
45+
AIRDROP_ADMIN_ADDRESS=`echo $out | cut -d " " -f1`
46+
AIRDROP_ADMIN_PUBKEY=`echo $out | cut -d " " -f2`
47+
AIRDROP_ADMIN_PVKEY=`echo $out | cut -d " " -f3`
48+
49+
out=`resim new-account | tee /dev/tty | awk '/Account component address:|Public key:|Private key:/ {print $NF}'`
50+
AIRDROP_REGISTER_ADDRESS_CYOVER=`echo $out | cut -d " " -f1`
51+
AIRDROP_REGISTER_UBKEY_CYOVER=`echo $out | cut -d " " -f2`
52+
AIRDROP_REGISTER_PVKEY_CYOVER=`echo $out | cut -d " " -f3`
53+
54+
55+
out=`resim new-account | tee /dev/tty | awk '/Account component address:|Public key:|Private key:/ {print $NF}'`
56+
AIRDROP_REGISTER_ADDRESS_CYROLSI=`echo $out | cut -d " " -f1`
57+
AIRDROP_REGISTER_UBKEY_CYROLSI=`echo $out | cut -d " " -f2`
58+
AIRDROP_REGISTER_PVKEY_CYROLSI=`echo $out | cut -d " " -f3`
59+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
source ./baseline.sh
2+
3+
# instanciating TweeterOracle Component by TWEETER_ORACLE_ADMIN_ADDRESS
4+
resim set-default-account $TWEETER_ORACLE_ADMIN_ADDRESS $TWEETER_ORACLE_ADMIN_PVKEY
5+
out=`resim call-function $PACKAGE TweeterOracle instantiate_tweeter_oracle | tee /dev/tty | awk '/Component:|Resource:/ {print $NF}'`
6+
TWEETER_ORACLE_COMPONENT=`echo $out | cut -d " " -f1`
7+
TWEETER_ORACLE_ADMIN_BADGE=`echo $out | cut -d " " -f2`
8+
9+
#instanciating AirdropWithTweeterOracle Compoenent by AIRDROP_ADMIN_ADDRESS
10+
resim set-default-account $AIRDROP_ADMIN_ADDRESS $AIRDROP_ADMIN_PVKEY
11+
echo "CALL_FUNCTION PackageAddress(\"$PACKAGE\") \"AirdropWithTweeterOracle\" \"new\" ResourceAddress(\"030000000000000000000000000000000000000000000000000004\") Vec<String>(\"radixdlt\") Vec<String>(\"tweet1\") Vec<String>(\"tweet1\") ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\");" > tx.rtm
12+
echo "CALL_METHOD_WITH_ALL_RESOURCES ComponentAddress(\"$AIRDROP_ADMIN_ADDRESS\") \"deposit_batch\";" >> tx.rtm
13+
RESULT=$(resim run "tx.rtm")
14+
15+
16+
17+
export AIRDROP_WITH_TWEETER_ORACLE_COMPONENT=$(echo "$RESULT" | sed -nr "s/└─ Component: ([[:alnum:]_]+)/\1/p")
18+
export AIRDROP_WITH_TWEETER_ORACLE_ADMIN_BADGE=$(echo "$RESULT" | sed -nr "s/.*Resource: ([[:alnum:]_]+)/\1/p" | sed '1!d')
19+
export AIRDROP_WITH_TWEETER_ORACLE_PARTICIPANT_BADGE=$(echo "$RESULT" | sed -nr "s/.*Resource: ([[:alnum:]_]+)/\1/p" | sed '3!d')
20+
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
source ./create_components.sh
2+
3+
#Inserting datas to update
4+
# Any users can call these methods
5+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"add_accounts_to_follows\" Vec<String>(\"radixdlt\");" > tx.rtm
6+
resim run tx.rtm
7+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"add_tweets_to_like\" Vec<String>(\"tweet1\");" > tx.rtm
8+
resim run tx.rtm
9+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"add_tweets_to_retweet\" Vec<String>(\"tweet1\");" > tx.rtm
10+
resim run tx.rtm
11+
# get datas to updates
12+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"get_datas_to_update\";" > tx.rtm
13+
resim run tx.rtm
14+
15+
resim set-default-account $TWEETER_ORACLE_ADMIN_ADDRESS $TWEETER_ORACLE_ADMIN_PVKEY
16+
#inserting datas by TWEETER_ORACLE_ADMIN_ADDRESS
17+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_ADMIN_ADDRESS\") \"create_proof_by_amount\" Decimal(\"1\") ResourceAddress(\"$TWEETER_ORACLE_ADMIN_BADGE\");" > tx.rtm
18+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_account_followers\" \"radixdlt\" HashSet<String>(\"cyover\",\"ade\");" >> tx.rtm
19+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_tweets_likers\" \"tweet1\" HashSet<String>(\"cyover\",\"cyrolsi\",\"vivi\");" >> tx.rtm
20+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"insert_tweets_retweeters\" \"tweet1\" HashSet<String>(\"cyover\",\"cyrolsi\");" >> tx.rtm
21+
resim run tx.rtm
22+
23+
24+
#checking datas
25+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_account_follower\" \"radixdlt\" \"cyover\";" > tx.rtm
26+
resim run tx.rtm
27+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_liker\" \"tweet1\" \"cyover\";" > tx.rtm
28+
resim run tx.rtm
29+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_liker\" \"tweet1\" \"titi\";" > tx.rtm
30+
resim run tx.rtm
31+
echo "CALL_METHOD ComponentAddress(\"$TWEETER_ORACLE_COMPONENT\") \"is_tweet_retweeter\" \"tweet1\" \"cyover\";" > tx.rtm
32+
resim run tx.rtm
33+
#cyover user follow radixdlt, like and retweet tweet1
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CALL_METHOD ComponentAddress("024ee26dda1fc426032af8834ee63e0803658268fa65ad31e95b01") "is_tweet_retweeter" "tweet1" "cyover";

0 commit comments

Comments
 (0)