-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathentrypoint.sh
199 lines (158 loc) · 9.26 KB
/
entrypoint.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
198
199
#! /bin/bash
chmod 600 /keys/*
chmod +x /busybox
chmod 777 /shared
echo "Calculating target time for synchronised chain start..."
target_time=$(( ($(date +%s) / 10 + 1) * 10 ))
echo "$target_time" > /shared/cardano.start
byron_startTime=$target_time
shelley_systemStart=$(date --utc +"%Y-%m-%dT%H:%M:%SZ" --date="@$target_time")
/busybox sed "s/\"startTime\": [0-9]*/\"startTime\": $byron_startTime/" /shared/byron/genesis.json.base > /shared/byron/genesis.json
echo "Updated startTime value in Byron genesis.json to: $byron_startTime"
/busybox sed "s/\"systemStart\": \"[^\"]*\"/\"systemStart\": \"$shelley_systemStart\"/" /shared/shelley/genesis.json.base > /shared/shelley/genesis.json
echo "Updated systemStart value in Shelley genesis.json to: $shelley_systemStart"
echo "Parsing epochLength and slotLength from Shelley genesis.json..."
/busybox awk -F':|,' '/"epochLength"/ {print $2}' /shared/shelley/genesis.json.base > /shared/mc-epoch-length
echo "Created /shared/mc-epoch-length with value: $(cat /shared/mc-epoch-length)"
/busybox awk -F':|,' '/"slotLength"/ {print $2}' /shared/shelley/genesis.json.base > /shared/mc-slot-length
echo "Created /shared/mc-slot-length with value: $(cat /shared/mc-slot-length)"
cp /shared/conway/genesis.conway.json.base /shared/conway/genesis.conway.json
cp /shared/shelley/genesis.alonzo.json.base /shared/shelley/genesis.alonzo.json
echo "Created /shared/conway/genesis.conway.json and /shared/shelley/genesis.alonzo.json"
byron_hash=$(/bin/cardano-cli byron genesis print-genesis-hash --genesis-json /shared/byron/genesis.json)
shelley_hash=$(/bin/cardano-cli latest genesis hash --genesis /shared/shelley/genesis.json)
alonzo_hash=$(/bin/cardano-cli latest genesis hash --genesis /shared/shelley/genesis.alonzo.json)
conway_hash=$(/bin/cardano-cli latest genesis hash --genesis /shared/conway/genesis.conway.json)
/busybox sed "s/\"ByronGenesisHash\": \"[^\"]*\"/\"ByronGenesisHash\": \"$byron_hash\"/" /shared/node-1-config.json.base > /shared/node-1-config.json.base.byron
/busybox sed "s/\"ByronGenesisHash\": \"[^\"]*\"/\"ByronGenesisHash\": \"$byron_hash\"/" /shared/db-sync-config.json.base > /shared/db-sync-config.json.base.byron
/busybox sed "s/\"ShelleyGenesisHash\": \"[^\"]*\"/\"ShelleyGenesisHash\": \"$shelley_hash\"/" /shared/node-1-config.json.base.byron > /shared/node-1-config.base.shelley
/busybox sed "s/\"ShelleyGenesisHash\": \"[^\"]*\"/\"ShelleyGenesisHash\": \"$shelley_hash\"/" /shared/db-sync-config.json.base.byron > /shared/db-sync-config.base.shelley
/busybox sed "s/\"AlonzoGenesisHash\": \"[^\"]*\"/\"AlonzoGenesisHash\": \"$alonzo_hash\"/" /shared/node-1-config.base.shelley > /shared/node-1-config.json.base.conway
/busybox sed "s/\"AlonzoGenesisHash\": \"[^\"]*\"/\"AlonzoGenesisHash\": \"$alonzo_hash\"/" /shared/db-sync-config.base.shelley > /shared/db-sync-config.json.base.conway
/busybox sed "s/\"ConwayGenesisHash\": \"[^\"]*\"/\"ConwayGenesisHash\": \"$conway_hash\"/" /shared/node-1-config.json.base.conway > /shared/node-1-config.json
/busybox sed "s/\"ConwayGenesisHash\": \"[^\"]*\"/\"ConwayGenesisHash\": \"$conway_hash\"/" /shared/db-sync-config.json.base.conway > /shared/db-sync-config.json
echo "Updated ByronGenesisHash value in config files to: $byron_hash"
echo "Updated ShelleyGenesisHash value in config files to: $shelley_hash"
echo "Updated ConwayGenesisHash value in config files to: $conway_hash"
byron_startTimeMillis=$(($byron_startTime * 1000))
echo $byron_startTimeMillis > /shared/MC__FIRST_EPOCH_TIMESTAMP_MILLIS
echo $byron_startTimeMillis > /runtime-values/MC__FIRST_EPOCH_TIMESTAMP_MILLIS
echo "Created /shared/MC__FIRST_EPOCH_TIMESTAMP_MILLIS with value: $byron_startTimeMillis"
echo "Current time is now: $(date +"%H:%M:%S.%3N"). Starting node..."
cardano-node run \
--topology /shared/node-1-topology.json \
--database-path /data/db \
--socket-path /data/node.socket \
--host-addr 0.0.0.0 \
--port 32000 \
--config /shared/node-1-config.json \
--shelley-kes-key /keys/kes.skey \
--shelley-vrf-key /keys/vrf.skey \
--shelley-operational-certificate /keys/node.cert &
echo "Waiting for node.socket..."
while true; do
if [ -e "/data/node.socket" ]; then
break
else
sleep 1
fi
done
echo "Preparing native token owned by 'funded_address.skey'"
# Policy requires that mints are signed by the funded_address.skey (key hash is e8c300330fe315531ca89d4a2e7d0c80211bc70b473b1ed4979dff2b)
reward_token_policy_id=$(cardano-cli latest transaction policyid --script-file ./shared/reward_token_policy.script)
# hex of "Reward token"
reward_token_asset_name="52657761726420746f6b656e"
echo "Generating new address and funding it with 2x1000 Ada and 10 Ada + 1000000 reward token ($reward_token_policy_id.$reward_token_asset_name)"
new_address=$(cardano-cli latest address build \
--payment-verification-key-file /keys/funded_address.vkey \
--testnet-magic 42)
echo "New address created: $new_address"
dave_address="addr_test1vphpcf32drhhznv6rqmrmgpuwq06kug0lkg22ux777rtlqst2er0r"
eve_address="addr_test1vzzt5pwz3pum9xdgxalxyy52m3aqur0n43pcl727l37ggscl8h7v8"
# An address that will keep an UTXO with script of a test V-function, related to the SPO rewards. See v-function.script file.
vfunction_address="addr_test1vzuasm5nqzh7n909f7wang7apjprpg29l2f9sk6shlt84rqep6nyc"
# total-accrued-function-script-hash (cardano-cli latest transaction policyid --script-file v-function.script)
# ef1eb7b85327a8460799025a5affd0a8d8015731e9aacd5d1106a82b
# updated vfunction address (cardano-cli address build --payment-script-file v-function-updated.script --testnet-magic 42):
vfunction_updated_address="addr_test1wpxhte72udea5ag3umnaukjmyjp8ywsgn2z6alkmhv42nxqcv2vwc"
# total-accrued-function-script-hash (cardano-cli latest transaction policyid --script-file v-function-updated.script)
# 4d75e7cae373da7511e6e7de5a5b2482723a089a85aefedbbb2aa998
# Define the UTXO details and amounts
tx_in1="781cb948a37c7c38b43872af9b1e22135a94826eafd3740260a6db0a303885d8#0"
tx_in_amount=29993040000000000
# Define output amounts
tx_out1=1000000000 # new_address utxo 1
tx_out2=1000000000 # new_address utxo 2
tx_out3=1000000000 # partner-chains-node-4 (dave)
tx_out4=1000000000 # partner-chains-node-5 (eve)
tx_out5_lovelace=10000000
tx_out5_reward_token="1000000 $reward_token_policy_id.$reward_token_asset_name"
tx_out6=10000000
tx_out7=10000000
# Total output without fee
total_output=$((tx_out1 + tx_out2 + tx_out3 + tx_out4 + tx_out5_lovelace + tx_out6 + tx_out7))
fee=1000000
# Calculate remaining balance to return to the genesis address
change=$((tx_in_amount - total_output - fee))
# Build the raw transaction
cardano-cli latest transaction build-raw \
--tx-in $tx_in1 \
--tx-out "$new_address+$tx_out1" \
--tx-out "$new_address+$tx_out2" \
--tx-out "$dave_address+$tx_out3" \
--tx-out "$eve_address+$tx_out4" \
--tx-out "$new_address+$change" \
--tx-out "$new_address+$tx_out5_lovelace+$tx_out5_reward_token" \
--tx-out "$vfunction_address+$tx_out6" \
--tx-out-reference-script-file /shared/v-function.script \
--tx-out "$vfunction_updated_address+$tx_out7" \
--tx-out-reference-script-file /shared/v-function-updated.script \
--minting-script-file /shared/reward_token_policy.script \
--mint "$tx_out5_reward_token" \
--fee $fee \
--out-file /data/tx.raw
# Sign the transaction
cardano-cli latest transaction sign \
--tx-body-file /data/tx.raw \
--signing-key-file /shared/shelley/genesis-utxo.skey \
--signing-key-file /keys/funded_address.skey \
--testnet-magic 42 \
--out-file /data/tx.signed
cat /data/tx.signed
echo "Submitting transaction..."
cardano-cli latest transaction submit \
--tx-file /data/tx.signed \
--testnet-magic 42
echo "Transaction submitted to fund registered candidates and governance authority. Waiting 20 seconds for transaction to process..."
sleep 20
echo "Balance:"
# Query UTXOs at new_address, dave_address, and eve_address
echo "Querying UTXO for new_address:"
cardano-cli latest query utxo \
--testnet-magic 42 \
--address $new_address
echo "Querying UTXO for Dave address:"
cardano-cli latest query utxo \
--testnet-magic 42 \
--address $dave_address
echo "Querying UTXO for Eve address:"
cardano-cli latest query utxo \
--testnet-magic 42 \
--address $eve_address
# Save dynamic values to shared config volume for other nodes to use
echo $new_address > /shared/FUNDED_ADDRESS
echo "Created /shared/FUNDED_ADDRESS with value: $new_address"
echo "Querying and saving the first UTXO details for Dave address to /shared/dave.utxo:"
cardano-cli latest query utxo --testnet-magic 42 --address "${dave_address}" | /busybox awk 'NR>2 { print $1 "#" $2; exit }' > /shared/dave.utxo
echo "UTXO details for Dave saved in /shared/dave.utxo."
cat /shared/dave.utxo
echo "Querying and saving the first UTXO details for Eve address to /shared/eve.utxo:"
cardano-cli latest query utxo --testnet-magic 42 --address "${eve_address}" | /busybox awk 'NR>2 { print $1 "#" $2; exit }' > /shared/eve.utxo
echo "UTXO details for Eve saved in /shared/eve.utxo."
cat /shared/eve.utxo
echo "Querying and saving the first UTXO details for new address to /shared/genesis.utxo:"
cardano-cli latest query utxo --testnet-magic 42 --address "${new_address}" | /busybox awk 'NR>2 { print $1 "#" $2; exit }' > /shared/genesis.utxo
cat /shared/genesis.utxo > /runtime-values/genesis.utxo
cat /shared/genesis.utxo
touch /shared/cardano.ready
wait