-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script queries for the UTxO of an address. | ||
# | ||
# The address may be supplied as an address, a file containing the address, or a verification key file | ||
|
||
set -eo pipefail | ||
|
||
export CARDANO_CLI="${CARDANO_CLI:-cardano-cli}" | ||
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" | ||
export TESTNET_MAGIC="${TESTNET_MAGIC:-42}" | ||
export UTXO_VKEY="${UTXO_VKEY:-example/shelley/utxo-keys/utxo1.vkey}" | ||
|
||
source="$1" | ||
addr="unknown" | ||
|
||
if [[ "$source" == *.vkey ]]; then | ||
$CARDANO_CLI address build --testnet-magic "$TESTNET_MAGIC" --payment-verification-key-file "$source" | ||
elif [[ "$source" == *.addr ]]; then | ||
cat "$source" | ||
elif [[ "$source" == addr_* ]]; then | ||
echo -n "$source" | ||
else | ||
echo "unknown source: $source" 2> /dev/null | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script iterates through the txouts of an address and splits each of them into two smaller txouts | ||
# | ||
# The script takes one argument, which is the maximum number of txouts to split. | ||
|
||
set -eo pipefail | ||
|
||
export BASE="${BASE:-.}" | ||
export CARDANO_CLI="${CARDANO_CLI:-cardano-cli}" | ||
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" | ||
export TESTNET_MAGIC="${TESTNET_MAGIC:-42}" | ||
export UTXO_SKEY="${UTXO_SKEY:-example/shelley/utxo-keys/utxo1.skey}" | ||
export SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
|
||
amount="$1" | ||
source_skey="$2" | ||
source="$("$SCRIPT_DIR/address-of.sh" "${source_skey%.skey}.vkey")" | ||
target="$("$SCRIPT_DIR/address-of.sh" "$3")" | ||
|
||
utxo_file="$(mktemp)" | ||
|
||
tx_base="$(mktemp)" | ||
|
||
"$CARDANO_CLI" query utxo --address "$source" --cardano-mode --testnet-magic "$TESTNET_MAGIC" --out-file "$utxo_file" | ||
|
||
echo "Queried UTxO for address: utxoaddr=$utxoaddr" | ||
|
||
txins="$(jq -r ". | to_entries | sort_by(.value.value.lovelace) | reverse | map(.key)[0:$count][]" "$utxo_file")" | ||
|
||
"$CARDANO_CLI" transaction build \ | ||
--alonzo-era \ | ||
--cardano-mode \ | ||
--testnet-magic "$TESTNET_MAGIC" \ | ||
--change-address "$target" \ | ||
--tx-in "$txin" \ | ||
--tx-out "$target+$amount" \ | ||
--out-file "$tx_base.tx" | ||
|
||
"$CARDANO_CLI" transaction sign \ | ||
--tx-body-file "$tx_base.tx" \ | ||
--testnet-magic "$TESTNET_MAGIC" \ | ||
--signing-key-file "$source_skey" \ | ||
--out-file "$tx_base.tx.signed" | ||
|
||
if [ "$SUBMIT_API_PORT" != "" ]; then | ||
xxd -r -p <<< $(jq .cborHex "$tx_base.tx.signed") > "$tx_base.tx.signed.cbor" | ||
|
||
curl \ | ||
-s \ | ||
--header "Content-Type: application/cbor" \ | ||
-X POST "http://localhost:$SUBMIT_API_PORT/api/submit/tx" \ | ||
--data-binary "@$tx_base.tx.signed.cbor" | ||
else | ||
"$CARDANO_CLI" transaction submit --tx-file "$tx_base.tx.signed.cbor" --testnet-magic "$TESTNET_MAGIC" | ||
fi |