-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
executable file
·69 lines (50 loc) · 1.84 KB
/
compile.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
#!/bin/bash
# pass in the env name to this command
COMP_NETWORK=$1
TARGET="DNARegistry_comp"
OUTPUT_DIR=compile/registry
if [ ! -f "$COMP_NETWORK".env ]; then
echo "$COMP_NETWORK.env does not exist..."
exit 1
fi
if [ ! -f ~/smartpy-cli/SmartPy.sh ]; then
echo "~/smartpy-cli/SmartPy.sh does not exist..."
exit 1
fi
if [ ! -d node_modules ]; then
echo "Dependencies not installed, run 'npm install' first..."
exit 1
fi
echo "[*] Prepare DNA Registry"
echo "[i] Network: $COMP_NETWORK"
export $(cat $COMP_NETWORK.env | xargs)
cd contract > /dev/null
echo "[*] Compiling Registry"
~/smartpy-cli/SmartPy.sh compile compile.py $OUTPUT_DIR
echo "[*] Generated TZIP-16 Metadata"
echo "[i] Existing CID: $COMP_TZIP16"
NEW_TZIP16=$(ipfs add --cid-version 1 $OUTPUT_DIR/$TARGET/step_000_cont_0_metadata.metadata.json -Q)
echo "[i] Generated CID: $NEW_TZIP16"
if [ "$COMP_TZIP16" != "$NEW_TZIP16" ]; then
echo "[i] Metadata has changed, adding new metadata"
ipfs pin add $NEW_TZIP16
echo "[i] Pinning..."
PINRES=$(curl -X 'POST' \
'https://api.nft.storage/upload' \
-H 'accept: application/json' \
-H "Authorization: Bearer $STORAGE_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary "@$OUTPUT_DIR/$TARGET/step_000_cont_0_metadata.metadata.json")
echo "[i] Finished pinning new metadata, updating configurations"
sed -i.bak "s/COMP_TZIP16=.*/COMP_TZIP16='${NEW_TZIP16}'/" ../$COMP_NETWORK.env
COMP_TZIP16=$NEW_TZIP16
echo "[i] Recompiling with new metadata CID..."
~/smartpy-cli/SmartPy.sh compile compile.py $OUTPUT_DIR
else
echo "[i] Metadata verified"
fi
echo "[*] Originating Registry"
cd - > /dev/null
CONTRACT_ADDR=$(node cli/originate.js contract/$OUTPUT_DIR/$TARGET/step_000_cont_0_contract.json contract/$OUTPUT_DIR/$TARGET/step_000_cont_0_storage.json)
#
echo "[i] Originated ${CONTRACT_ADDR}"