Skip to content

Commit 0aa6b9a

Browse files
authored
Merge pull request #1170 from jpcapurro-atixlabs/add-pool-creaton-script
added script for creating a new stakepool
2 parents c675e45 + 24278e6 commit 0aa6b9a

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

scripts/bootstrap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,6 @@ else
331331
process_file "$SCRIPTPATH/faucet-send-money.shtempl" faucet-send-money.sh
332332
process_file "$SCRIPTPATH/faucet-send-certificate.shtempl" faucet-send-certificate.sh
333333
process_file "$SCRIPTPATH/create-account-and-delegate.shtempl" create-account-and-delegate.sh
334+
process_file "$SCRIPTPATH/create-stakepool.shtempl" create-stakepool.sh
334335
exit 0
335336
fi

scripts/create-stakepool.shtempl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
set -e
3+
set -u
4+
5+
### TEMPLATE
6+
CLI="####CLI####"
7+
REST_URL="####REST_URL####"
8+
BLOCK0_HASH="####BLOCK0_HASH####"
9+
ADDRTYPE="####ADDRTYPE####"
10+
FEE_CONSTANT="####FEE_CONSTANT####"
11+
FEE_CERTIFICATE="####FEE_CERTIFICATE####"
12+
FEE_COEFFICIENT="####FEE_COEFFICIENT####"
13+
# tx is broadcasted by the faucet account
14+
BROADCASTER_SK="####FAUCET_SK####"
15+
16+
if [ ${#} -gt 1 ]; then
17+
echo "usage: ./faucet-send-certificate.sh [pool_leader_sk]"
18+
echo "if a pool owner isnt provided, itll default to the faucet account"
19+
exit 1
20+
fi
21+
22+
if [ ${#} -eq 1 ]; then
23+
LEADER_SK=${1}
24+
else
25+
LEADER_SK=${BROADCASTER_SK}
26+
fi
27+
28+
BROADCASTER_PK=$(echo ${BROADCASTER_SK} | $CLI key to-public)
29+
BROADCASTER_ADDR=$(echo "${BROADCASTER_PK}" | xargs $CLI address account "${ADDRTYPE}")
30+
BROADCASTER_SK_FILE="broadcaster.sk"
31+
echo ${BROADCASTER_SK} > ${BROADCASTER_SK_FILE}
32+
33+
BROADCASTER_COUNTER=$($CLI rest v0 account get "${BROADCASTER_ADDR}" --host ${REST_URL}|grep counter |cut -f 2 -d ' ')
34+
35+
# leader
36+
LEADER_SK=$($CLI key generate --type=Ed25519)
37+
LEADER_PK=$(echo "${LEADER_SK}" | $CLI key to-public)
38+
39+
# stake pool
40+
POOL_VRF_SK=$($CLI key generate --type=Curve25519_2HashDH)
41+
POOL_KES_SK=$($CLI key generate --type=SumEd25519_12)
42+
43+
POOL_VRF_PK=$(echo "${POOL_VRF_SK}" | $CLI key to-public)
44+
POOL_KES_PK=$(echo "${POOL_KES_SK}" | $CLI key to-public)
45+
46+
LEADER_SK_FILE="stake_key.sk"
47+
echo "${LEADER_SK}" > ${LEADER_SK_FILE}
48+
49+
$CLI certificate new stake-pool-registration \
50+
--management-threshold 1 \
51+
--start-validity 0 \
52+
--owner "${LEADER_PK}" \
53+
--kes-key "${POOL_KES_PK}" \
54+
--vrf-key "${POOL_VRF_PK}" \
55+
--serial 1010101010 > stake_pool.cert
56+
57+
CERTIFICATE_FILE="stake_pool.cert"
58+
59+
TRANSACTION_FILE=tx.staging
60+
WITNESS_FILE=transaction.witness
61+
62+
# the fee to post the new certificate, the coefficient is just
63+
# multiplied by one because we only have one input
64+
POST_CERTIFICATE_FEE=$((FEE_CONSTANT + FEE_CERTIFICATE + FEE_COEFFICIENT))
65+
66+
$CLI transaction new --staging=${TRANSACTION_FILE}
67+
$CLI transaction add-account --staging=${TRANSACTION_FILE} "${BROADCASTER_ADDR}" "${POST_CERTIFICATE_FEE}"
68+
$CLI transaction add-certificate --staging=${TRANSACTION_FILE} "$(cat "${CERTIFICATE_FILE}")"
69+
$CLI transaction finalize --staging=${TRANSACTION_FILE}
70+
71+
TRANSACTION_ID=$($CLI transaction data-for-witness --staging=${TRANSACTION_FILE})
72+
73+
# create the witness
74+
$CLI transaction make-witness "${TRANSACTION_ID}" \
75+
--genesis-block-hash "${BLOCK0_HASH}" \
76+
--type "account" --account-spending-counter "${BROADCASTER_COUNTER}" \
77+
"${WITNESS_FILE}" "${BROADCASTER_SK_FILE}"
78+
$CLI transaction add-witness --staging=${TRANSACTION_FILE} "${WITNESS_FILE}"
79+
80+
$CLI transaction seal --staging=${TRANSACTION_FILE}
81+
82+
$CLI transaction auth --key=${LEADER_SK_FILE} --staging=${TRANSACTION_FILE}
83+
84+
$CLI transaction to-message --staging ${TRANSACTION_FILE} | $CLI rest v0 message post -h "${REST_URL}"

0 commit comments

Comments
 (0)