-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart-unnamed.sh
executable file
·197 lines (178 loc) · 6.08 KB
/
quickstart-unnamed.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# compatibility cargo-contract v3.0.1
#
# start a fresh substrate-contracts-node and upload the "unnamed" ink!
# smart contracts to it and then instantiate and call a method
#
# if you want to sky dry run then find/replace `--skip-dry-run` with `#--skip-dry-run`
# to comment those lines out
trap "echo; exit" INT
trap "echo; exit" HUP
# if they call this script from project root or from within docker/ folder then
# in both cases the PARENT_DIR will refer to the project root where the .env file is.
PARENT_DIR=$( echo $(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")") )
echo "Building contracts..."
cd $PARENT_DIR/dapps/xcm/unnamed
PROJECT_ROOT=$PARENT_DIR/dapps/xcm/unnamed
cargo contract build \
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/Cargo.toml
cargo contract build \
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/oracle_contract/Cargo.toml
cd $PROJECT_ROOT
echo "Uploading sub-contract..."
# upload sub-contract
#
# note: provide args variable so able to comment out all `--skip-dry-run` options in bulk
# since it breaks command if comment out a multiline command option `#--skip-dry-run \`
# see https://stackoverflow.com/a/9522766/3208553
args=(
--suri //Alice
--execute
--skip-dry-run
--skip-confirm
$PARENT_DIR/target/ink/oracle_contract/oracle_contract.wasm
)
OUTPUT_CODE_HASH_SUB=$(
cargo contract upload "${args[@]}" | tail -1
)
echo "Finished uploading contract..."
# example: ' Code hash "0x..."'
echo $OUTPUT_CODE_HASH_SUB
# remove text 'Code hash' and the outer double quotes of the code hash
OUTPUT_CODE_HASH_SUB_REMOVED_LABEL=$(echo "$OUTPUT_CODE_HASH_SUB" | sed 's/Code hash//;s/$//' | tr -d '"')
# trim whitespace
CODE_HASH_SUB=$(echo $OUTPUT_CODE_HASH_SUB_REMOVED_LABEL)
echo $CODE_HASH_SUB
echo "Uploading main-contract..."
# upload main-contract
#
args=(
--suri //Alice
--execute
# --skip-dry-run
--skip-confirm
$PARENT_DIR/target/ink/unnamed/unnamed.wasm
)
OUTPUT_CODE_HASH_MAIN=$(
cargo contract upload "${args[@]}" | tail -1
)
echo "Finished uploading contract..."
# example: ' Code hash "0x..."'
echo $OUTPUT_CODE_HASH_MAIN
# remove text 'Code hash' and the outer double quotes of the code hash
OUTPUT_CODE_HASH_MAIN_REMOVED_LABEL=$(echo "$OUTPUT_CODE_HASH_MAIN" | sed 's/Code hash//;s/$//' | tr -d '"')
# trim whitespace
CODE_HASH_MAIN=$(echo $OUTPUT_CODE_HASH_MAIN_REMOVED_LABEL)
echo $CODE_HASH_MAIN
ARG_ID_MARKET="\"my_id\""
# Note: The id_market is stored as Vec<u8> format instead of String.
# Paste the following at https://play.rust-lang.org/?version=stable&mode=debug&edition=2021
# then press the "Run" button and it will output `[109, 121, 95, 105, 100]`
# ```rust
# fn main() -> Result<(), std::io::Error> {
# let s = "my_id".to_string();
# let b = s.as_bytes();
# println!("{:?}", b);
# let _y = String::from_utf8(b.to_vec());
# Ok(())
# }
# ```
cd $PROJECT_ROOT
echo "Instantiating sub-contract..."
args=(
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/oracle_contract/Cargo.toml
--suri //Alice
--constructor new
--args $ARG_ID_MARKET "100" "228" "500"
--execute
--gas 1000000000000
--proof-size 1000000000000
# --skip-dry-run
--skip-confirm
)
OUTPUT_CONTRACT_ADDR_SUB=$(
cargo contract instantiate "${args[@]}" | tail -1
)
# example: ' Contract 5...'
echo $OUTPUT_CONTRACT_ADDR_SUB
# remove text 'Contract'
OUTPUT_CONTRACT_ADDR_SUB_REMOVED_LABEL=$(echo "$OUTPUT_CONTRACT_ADDR_SUB" | sed 's/Contract//;s/$//')
# trim whitespace using `echo ...`
CONTRACT_ADDR_SUB=$(echo $OUTPUT_CONTRACT_ADDR_SUB_REMOVED_LABEL)
echo $CONTRACT_ADDR_SUB
# instantiate "main" contract, providing the code hash generated from uploading the "sub" contract
echo "Instantiating main-contract..."
args=(
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/Cargo.toml
--suri //Alice
--constructor new
--args $CODE_HASH_SUB $CONTRACT_ADDR_SUB $ARG_ID_MARKET "100" "228" "500"
--execute
--gas 1000000000000
--proof-size 1000000000000
# --skip-dry-run
--skip-confirm
)
OUTPUT_CONTRACT_ADDR_MAIN=$(
cargo contract instantiate "${args[@]}" | tail -1
)
# example: ' Contract 5...'
echo $OUTPUT_CONTRACT_ADDR_MAIN
# remove text 'Contract'
OUTPUT_CONTRACT_ADDR_MAIN_REMOVED_LABEL=$(echo "$OUTPUT_CONTRACT_ADDR_MAIN" | sed 's/Contract//;s/$//')
# trim whitespace using `echo ...`
CONTRACT_ADDR_MAIN=$(echo $OUTPUT_CONTRACT_ADDR_MAIN_REMOVED_LABEL)
echo $CONTRACT_ADDR_MAIN
ARG_BLOCK_HASH_ENTROPY="\"aef6eca62ae61934a7ab5ad3814f6e319abd3e4e4aa1a3386466ad197d1c4dea\""
echo "Calling contract method set_block_for_entropy_for_market_id..."
args=(
--suri //Alice
--contract $CONTRACT_ADDR_MAIN
--message set_block_for_entropy_for_market_id
--args $ARG_ID_MARKET "228" $ARG_BLOCK_HASH_ENTROPY
--execute
--gas 1000000000000
--proof-size 1000000000000
# --skip-dry-run
--skip-confirm
)
cargo contract call "${args[@]}" | grep --color=always -z 'data'
# # TODO - change this to try and make it work via `$CONTRACT_ADDR_MAIN`
# echo "Calling contract method set_entropy_for_market_id ..."
# args=(
# --suri //Alice
# --contract $CONTRACT_ADDR_MAIN
# --message set_entropy_for_market_id
# --args $ARG_ID_MARKET "228" $ARG_BLOCK_HASH_ENTROPY "0" "0"
# --execute
# --gas 1000000000000
# --proof-size 1000000000000
# # --skip-dry-run
# --skip-confirm
# )
# cargo contract call "${args[@]}" | grep --color=always -z 'data'
# TODO - change this to try and make it work via `$CONTRACT_ADDR_MAIN`
echo "Calling contract method get_entropy_for_market_id ..."
args=(
--suri //Alice
--contract $CONTRACT_ADDR_MAIN
--message get_entropy_for_market_id
--args $ARG_ID_MARKET
--execute
--gas 1000000000000
--proof-size 1000000000000
# --skip-dry-run
--skip-confirm
)
cargo contract call "${args[@]}" | grep --color=always -z 'data'
# highlight the `data` line in output containing the value of the emitted `Retrieve` event
echo "Calling contract method get_oracle_contract_address ..."
args=(
--suri //Alice
--contract $CONTRACT_ADDR_MAIN
--message get_oracle_contract_address
--execute
# --skip-dry-run
--skip-confirm
)
cargo contract call "${args[@]}" | grep --color=always -z 'data'