Skip to content

Commit 9a31072

Browse files
committed
bash-fns: add a simple faucet for custom networks
1 parent 7798ed9 commit 9a31072

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

scripts/bash-fns.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
#
33
# Various bash helper fns which aren't used enough to move to just recipes.
44

5-
# This can be used to simplify ssh sessions, rsync, ex:
6-
# ssh -o "$(ssm-proxy-cmd "$REGION")" "$INSTANCE_ID"
7-
ssm-proxy-cmd() {
8-
echo "ProxyCommand=sh -c 'aws --region $1 ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p'"
9-
}
10-
11-
125
# A handy transaction submission function with mempool monitoring.
136
# CARDANO_NODE_{NETWORK_ID,SOCKET_PATH}, TESTNET_MAGIC should already be exported.
147
submit() (
@@ -206,3 +199,30 @@ return-utxo() (
206199

207200
submit "$BASENAME.signed"
208201
)
202+
203+
# A handy faucet submission function with mempool monitoring, usable on custom networks.
204+
# CARDANO_NODE_{NETWORK_ID,SOCKET_PATH}, TESTNET_MAGIC should already be exported.
205+
# SEND_ADDR, LOVELACE, RICH_ADDR and RICH vars need to be provided.
206+
faucet() (
207+
SEND_ADDR="$1"
208+
LOVELACE="$2"
209+
210+
UTXOS=$(cardano-cli query utxo --address "$RICH_ADDR")
211+
UTXO=$(jq -r 'to_entries | max_by(.value.value.lovelace) | { (.key): .value }' <<< "$UTXOS")
212+
UTXO_TX=$(jq -r 'keys[0]' <<< "$UTXO")
213+
214+
cardano-cli latest transaction build \
215+
--tx-in "$UTXO_TX" \
216+
--tx-out "$SEND_ADDR+$LOVELACE" \
217+
--change-address "$RICH_ADDR" \
218+
--testnet-magic "$TESTNET_MAGIC" \
219+
--out-file faucet.txbody
220+
221+
cardano-cli latest transaction sign \
222+
--tx-body-file faucet.txbody \
223+
--signing-key-file "$RICH.skey" \
224+
--testnet-magic "$TESTNET_MAGIC" \
225+
--out-file faucet.txsigned
226+
227+
submit faucet.txsigned
228+
)

0 commit comments

Comments
 (0)