-
Notifications
You must be signed in to change notification settings - Fork 1
/
initialize.sh
executable file
·100 lines (82 loc) · 2.89 KB
/
initialize.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
#!/bin/bash
echo "Creating an empty src/contract_ids.json file"
echo '{"standalone": {"title_id": "undefined"}, "futurenet": {"title_id": "undefined"}}' > src/contract_ids.json
set -e
echo Build the title contract
cd contract
make build
cd ..
for NETWORK in standalone futurenet
do
case "$NETWORK" in
standalone)
echo "Using standalone network"
SOROBAN_RPC_HOST="http://stellar-standalone:8000"
SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
FRIENDBOT_URL="$SOROBAN_RPC_HOST/friendbot"
NEW_TITLE="I love Standalone"
;;
futurenet)
echo "Using Futurenet network"
SOROBAN_RPC_HOST="http://stellar-futurenet:8000"
SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"
SOROBAN_NETWORK_PASSPHRASE="Test SDF Future Network ; October 2022"
FRIENDBOT_URL="https://friendbot-futurenet.stellar.org/"
NEW_TITLE="I prefer Futurenet"
;;
*)
echo "Usage: $0 standalone|futurenet"
exit 1
;;
esac
echo Add the $NETWORK network to cli client
soroban config network add "$NETWORK" \
--rpc-url "$SOROBAN_RPC_URL" \
--network-passphrase "$SOROBAN_NETWORK_PASSPHRASE"
echo "--"
echo "--"
echo Creating the title-admin identity
soroban config identity generate title-admin
TOKEN_ADMIN_ADDRESS="$(soroban config identity address title-admin)"
echo "--"
echo "--"
# This will fail if the account already exists, but it'll still be fine.
echo Fund title-admin account from friendbot
curl -X POST "$FRIENDBOT_URL?addr=$TOKEN_ADMIN_ADDRESS"
echo "--"
echo "--"
ARGS="--network $NETWORK --source title-admin"
echo "Using ARGS: $ARGS"
echo "--"
echo "--"
echo Deploy the title contract
WASM_PATH="contract/target/wasm32-unknown-unknown/release/title_contract.wasm"
TITLE_ID="$(soroban contract deploy $ARGS --wasm $WASM_PATH)"
echo "Contract deployed in $NETWORK network succesfully with ID: $TITLE_ID"
echo "--"
echo "--"
sleep 3
tmp=$(mktemp)
jq ".$NETWORK.title_id = \"$TITLE_ID\"" src/contract_ids.json > "$tmp" && mv "$tmp" src/contract_ids.json
echo "Setting the first title: My $NETWORK title"
soroban contract invoke \
$ARGS \
--wasm $WASM_PATH \
--id $TITLE_ID \
-- \
set_title \
--title "{\"string\":\"$NEW_TITLE\"}"
echo "--"
echo "--"
echo "Reading the read_title function value"
soroban contract invoke \
$ARGS \
--wasm $WASM_PATH \
--id $TITLE_ID \
-- \
read_title
chmod 777 src/contract_ids.json # Give permission after each network in case future net is not ready yet
done
echo "We have our src/contract_ids.json file:"
cat src/contract_ids.json