Skip to content

Commit d286fbd

Browse files
authored
add script to withdraw staking rewards (#68)
1 parent 05e1ffd commit d286fbd

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

scripts/stake/withdraw-rewards.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Define directory paths
4+
keys_dir="./keys"
5+
txs_dir="./txs/stake"
6+
tx_path_stub="$txs_dir/stake-withdraw"
7+
tx_cert_path="$tx_path_stub.cert"
8+
tx_unsigned_path="$tx_path_stub.unsigned"
9+
tx_signed_path="$tx_path_stub.signed"
10+
11+
# Get the script's directory
12+
script_dir=$(dirname "$0")
13+
14+
# Get the container name from the get-container script
15+
container_name="$("$script_dir/../helper/get-container.sh")"
16+
17+
if [ -z "$container_name" ]; then
18+
echo "Failed to determine a running container."
19+
exit 1
20+
fi
21+
22+
echo "Using running container: $container_name"
23+
24+
# Function to execute cardano-cli commands inside the container
25+
container_cli() {
26+
docker exec -ti $container_name cardano-cli "$@"
27+
}
28+
29+
stake_account_balance=$(container_cli conway query stake-address-info --address $(cat $keys_dir/stake.addr) | jq -r '.[0].rewardAccountBalance')
30+
31+
# Send ada to the multisig payment script
32+
echo "Withdrawing all balance of $stake_account_balance from stake account."
33+
34+
echo "Building transaction"
35+
36+
container_cli conway transaction build \
37+
--tx-in $(container_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \
38+
--change-address $(cat $keys_dir/payment.addr) \
39+
--withdrawal $(cat $keys_dir/stake.addr)+$stake_account_balance \
40+
--out-file "$tx_unsigned_path"
41+
42+
echo "Signing transaction"
43+
44+
container_cli conway transaction sign \
45+
--tx-body-file "$tx_unsigned_path" \
46+
--signing-key-file $keys_dir/payment.skey \
47+
--signing-key-file $keys_dir/stake.skey \
48+
--out-file "$tx_signed_path"
49+
50+
# Submit the transaction
51+
echo "Submitting transaction"
52+
53+
container_cli conway transaction submit --tx-file $tx_signed_path

0 commit comments

Comments
 (0)