Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Oct 25, 2021
1 parent a0cf91a commit e548c67
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
26 changes: 26 additions & 0 deletions scripts/lite/address-of.sh
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
18 changes: 4 additions & 14 deletions scripts/lite/query-utxo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,15 @@ 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}"
export SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

source="$1"
addr="unknown"
source="$($SCRIPT_DIR/address-of.sh "$1")"

if [[ "$source" == *.vkey ]]; then
addr=$($CARDANO_CLI address build --testnet-magic "$TESTNET_MAGIC" --payment-verification-key-file "$source")
elif [[ "$source" == *.addr ]]; then
addr="$(cat "$source")"
elif [[ "$source" == addr_* ]]; then
addr="$source"
else
echo "unknown source: $source" 2> /dev/null
fi

echo "UTxOs for $addr"
echo "UTxOs for $source"

utxo_out=$(mktemp)

$CARDANO_CLI query utxo --address "$addr" --cardano-mode --testnet-magic "$TESTNET_MAGIC" --out-file "$utxo_out"
$CARDANO_CLI query utxo --address "$source" --cardano-mode --testnet-magic "$TESTNET_MAGIC" --out-file "$utxo_out"

cat "$utxo_out" | jq -r '
to_entries
Expand Down
56 changes: 56 additions & 0 deletions scripts/lite/transfer.sh
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

0 comments on commit e548c67

Please sign in to comment.