-
Notifications
You must be signed in to change notification settings - Fork 1
/
12.3_BP_calc_tx.sh
executable file
·104 lines (85 loc) · 2.57 KB
/
12.3_BP_calc_tx.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
#!/bin/bash
if [ -z "$ADA_USB_MNT" ]; then
echo "ADA_USB_MNT NOT set"
exit 1
fi
if [ ! -f "$ADA_USB_MNT/hot-env/stake.cert" ]; then
echo "no stake.cert!"
exit 1
fi
if [ ! -f "$ADA_USB_MNT/hot-env/deleg.cert" ]; then
echo "no deleg.cert!"
exit 1
fi
if [ ! -f "$ADA_USB_MNT/hot-env/pool.cert" ]; then
echo "no pool.cert!"
exit 1
fi
if [ ! -f "$ADA_USB_MNT/hot-env/payment.addr" ]; then
echo "no payment.addr!"
exit 1
fi
cp $ADA_USB_MNT/hot-env/payment.addr hot-env/
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slotNo')
echo Current Slot: $currentSlot
cardano-cli query utxo \
--address $(cat hot-env/payment.addr) \
--allegra-era \
--mainnet > fullUtxo.out
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
cat balance.out
tx_in=""
total_balance=0
while read -r utxo; do
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
idx=$(awk '{ print $2 }' <<< "${utxo}")
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
total_balance=$((${total_balance}+${utxo_balance}))
echo TxHash: ${in_addr}#${idx}
echo ADA: ${utxo_balance}
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
done < balance.out
txcnt=$(cat balance.out | wc -l)
rm balance.out
echo Total ADA balance: ${total_balance}
echo Number of UTXOs: ${txcnt}
# for testing
if [ -z "$tx_in" ]; then
echo "NOTE: 0 balance - using test account"
tx_in="--tx-in aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#0"
total_balance="5000000000"
fi
poolDeposit=$(cat pool-files/params.json | jq -r '.poolDeposit')
echo poolDeposit: $poolDeposit
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat hot-env/payment.addr)+0 \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee 0 \
--out-file tx.tmp \
--allegra-era \
--certificate $ADA_USB_MNT/hot-env/stake.cert
fee=$(cardano-cli transaction calculate-min-fee \
--tx-body-file tx.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 1 \
--mainnet \
--witness-count 3 \
--byron-witness-count 0 \
--protocol-params-file pool-files/params.json | awk '{ print $1 }')
echo fee: $fee
txOut=$((${total_balance}-${poolDeposit}-${fee}))
echo txOut: ${txOut}
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat hot-env/payment.addr)+${txOut} \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee ${fee} \
--certificate-file $ADA_USB_MNT/hot-env/pool.cert \
--certificate-file $ADA_USB_MNT/hot-env/deleg.cert \
--allegra-era \
--out-file $ADA_USB_MNT/offline-files/tx.raw
echo "--- tx.raw"
cat $ADA_USB_MNT/offline-files/tx.raw
rm fullUtxo.out
rm tx.tmp