Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless guardrails #15

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- **cogno-project**: added text to the landing README in the parent directory
- **cogno-project**: added text to the headless README
- **headless**: added script reference tx, contracts, and hashes
- **headless**: added guardrails to parent level headless scripts
- **headless**: added wallet protections


### Fixed
Expand Down
12 changes: 12 additions & 0 deletions headless/00_createScriptReferences.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ change_address=$(jq -r '.change_address' ../config.json)
reference_script_path="../contracts/reference_contract.plutus"
script_reference_address=$(${cli} address build --payment-script-file ${reference_script_path} ${network})

# Prompt user for confirmation
read -p "$(echo -e "\033[1;37\033[1;36m\nPress\033[0m \033[1;32mEnter\033[0m \033[1;36mTo Create Script Reference UTxOs Or Any Other Key To Exit:\n\033[0m")" -n 1 -r
echo -ne '\033[1A\033[2K\r'

# Check if input is empty (user pressed Enter)
if [[ -z $REPLY ]]; then
echo "Creating script reference UTxOs..."
else
echo "Operation cancelled."
exit;
fi

echo -e "\033[0;35m\nGathering UTxO Information \033[0m"
${cli} query utxo \
${network} \
Expand Down
14 changes: 13 additions & 1 deletion headless/01_genesisMint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ change_address=$(jq -r '.change_address' ../config.json)
collat_address=$(cat wallets/collat-wallet/payment.addr)
collat_pkh=$(${cli} address key-hash --payment-verification-key-file wallets/collat-wallet/payment.vkey)

echo -e "\033[0;36m Gathering Starter UTxO Information \033[0m"
# Prompt user for confirmation
read -p "$(echo -e "\033[1;37\033[1;36m\nPress\033[0m \033[1;32mEnter\033[0m \033[1;36mTo Mint Genesis Token Or Any Other Key To Exit:\n\033[0m")" -n 1 -r
echo -ne '\033[1A\033[2K\r'

# Check if input is empty (user pressed Enter)
if [[ -z $REPLY ]]; then
echo "Minting Genesis Token..."
else
echo "Operation cancelled."
exit;
fi

echo -e "\033[0;36m Gathering Starter UTxO Information\033[0m"
${cli} query utxo \
${network} \
--address ${starter_address} \
Expand Down
8 changes: 5 additions & 3 deletions headless/create_wallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set -e
source .env

if [[ $# -eq 0 ]] ; then
echo 'Please Supply A Wallet Folder'
exit 1
echo 'Please Supply A Wallet Folder: wallet/name-wallet'
exit 1;
fi

folder=${1}
Expand All @@ -17,7 +17,9 @@ if [ ! -d ${folder} ]; then
${cli} address key-gen --verification-key-file ${folder}/payment.vkey --signing-key-file ${folder}/payment.skey
${cli} address build --payment-verification-key-file ${folder}/payment.vkey --out-file ${folder}/payment.addr ${network}
${cli} address key-hash --payment-verification-key-file ${folder}/payment.vkey --out-file ${folder}/payment.hash
echo "${folder} folder created"
exit;
else
echo "Folder already exists"
echo "${folder} folder already exists"
exit 1;
fi
19 changes: 15 additions & 4 deletions headless/send_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set -e
# SET UP VARS HERE
source .env

rm ./tmp/tx.signed || true

# get params
${cli} query protocol-parameters ${network} --out-file ./tmp/protocol.json

Expand All @@ -16,6 +14,19 @@ sender_address=$(cat ${sender_path}payment.addr)
# Receiver Address
# receiver_address=$(cat ${sender_path}payment.addr)
receiver_address=$(jq -r '.change_address' ../config.json)

# Prompt user for confirmation
echo -e "\033[1;37mSending All UTxOs From \033[1;34m${sender_path}\033[0m\033[1;37m to \033[1;35m${receiver_address}\033[0m"
read -p "$(echo -e "\033[1;37m\033[1;36m\nPress\033[0m \033[1;32mEnter\033[0m \033[1;36mTo Send All UTxOs Or Any Other Key To Exit:\n\033[0m")" -n 1 -r
echo -ne '\033[1A\033[2K\r'

# Check if input is empty (user pressed Enter)
if [[ -z $REPLY ]]; then
echo "Sending all UTxOs..."
else
echo "Operation cancelled."
exit;
fi
#
# exit
#
Expand All @@ -32,14 +43,14 @@ if [ "${TXNS}" -eq "0" ]; then
fi
alltxin=""
TXIN=$(jq -r --arg alltxin "" 'keys[] | . + $alltxin + " --tx-in"' tmp/sender_utxo.json)
seller_tx_in=${TXIN::-8}
sender_tx_in=${TXIN::-8}

echo -e "\033[0;36m Building Tx \033[0m"
FEE=$(${cli} transaction build \
--babbage-era \
--out-file ./tmp/tx.draft \
--change-address ${receiver_address} \
--tx-in ${seller_tx_in} \
--tx-in ${sender_tx_in} \
${network})

IFS=':' read -ra VALUE <<< "${FEE}"
Expand Down