Skip to content

Commit

Permalink
Merge pull request #4 from logical-mechanism/add-always-false-to-hold…
Browse files Browse the repository at this point in the history
…-reference-utxo

now the script refernce lives in an always false contract
  • Loading branch information
logicalmechanism authored Sep 4, 2024
2 parents fd85549 + 299108b commit d8b7983
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
9 changes: 7 additions & 2 deletions complete_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ aiken build --trace-level silent --filter-traces user-defined
# keep the traces for testing if required
# aiken build --trace-level verbose --filter-traces all

ran="00"
ran="01"
ran_cbor=$(python3 -c "import cbor2;hex_string='${ran}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())")

echo -e "\033[1;33m\nBuilding Contract \033[0m"
aiken blueprint apply -o plutus.json -v seedelf.contract.spend "${ran_cbor}"
aiken blueprint convert -v seedelf.contract.spend > contracts/seedelf_contract.plutus
cardano-cli conway transaction policyid --script-file contracts/seedelf_contract.plutus > hashes/seedelf.hash
echo -e "\033[1;33m Contract Hash: $(cat hashes/seedelf.hash) \033[0m"
echo -e "\033[1;33m Seedelf Contract Hash: $(cat hashes/seedelf.hash) \033[0m"

aiken blueprint apply -o plutus.json -v always_false.contract.spend "${ran_cbor}"
aiken blueprint convert -v always_false.contract.spend > contracts/always_false_contract.plutus
cardano-cli conway transaction policyid --script-file contracts/always_false_contract.plutus > hashes/always_false.hash
echo -e "\033[1;33m Always False Contract Hash: $(cat hashes/always_false.hash) \033[0m"

# end of build
echo -e "\033[1;32m\nBuilding Complete! \033[0m"
22 changes: 17 additions & 5 deletions scripts/00_createScriptReferences.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ ${cli} conway query protocol-parameters ${network} --out-file ./tmp/protocol.jso

# Addresses
reference_address=$(cat ./wallets/reference-wallet/payment.addr)
script_reference_address=$(cat ./wallets/reference-wallet/payment.addr)

# always false to hold script utxo
always_false_script_path="../contracts/always_false_contract.plutus"
script_reference_address=$(${cli} conway address build --payment-script-file ${always_false_script_path} ${network})

echo -e "\033[0;35m\nGathering UTxO Information \033[0m"
${cli} conway query utxo \
Expand All @@ -32,9 +35,13 @@ counter=0
echo -e "\033[0;33m\nStart Building Tx Chain \033[0m"
for contract in $(ls "../contracts"/* | sort -V)
do

file_name=$(basename "$contract")
if [ "$file_name" == "always_false_contract.plutus" ]; then
continue
fi
echo -e "\033[1;37m --------------------------------------------------------------------------------\033[0m"
echo -e "\033[1;35m\n${contract}\033[0m"
file_name=$(basename "$contract")
# Increment the counter
((counter++)) || true

Expand All @@ -54,13 +61,15 @@ do
--tx-out="${reference_address} + ${changeAmount}" \
--tx-out="${script_reference_utxo}" \
--tx-out-reference-script-file ${contract} \
--fee 900000
--fee 0

size=$(jq -r '.cborHex' ${contract} | awk '{print length($0)*4}')

FEE=$(${cli} conway transaction calculate-min-fee \
--tx-body-file ./tmp/tx.draft \
--protocol-params-file ./tmp/protocol.json \
--reference-script-size 0 \
--witness-count 10)
--reference-script-size ${size} \
--witness-count 1)
echo -e "\033[0;35mFEE: ${FEE} \033[0m"
fee=$(echo $FEE | rev | cut -c 9- | rev)

Expand Down Expand Up @@ -92,6 +101,9 @@ echo -e "\033[1;37m ------------------------------------------------------------
for contract in $(ls "../contracts"/* | sort -V)
do
file_name=$(basename "${contract}")
if [ "$file_name" == "always_false_contract.plutus" ]; then
continue
fi
echo -e "\nSubmitting ${file_name}"
# Perform operations on each file
${cli} conway transaction submit \
Expand Down
12 changes: 10 additions & 2 deletions scripts/all_balances.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@ set -e
# SET UP VARS HERE
source .env

# wallet contract
# seedelf contract
seedelf_script_path="../contracts/seedelf_contract.plutus"
seedelf_script_address=$(${cli} address build --payment-script-file ${seedelf_script_path} ${network})

# always false to hold script utxo
always_false_script_path="../contracts/always_false_contract.plutus"
script_reference_address=$(${cli} conway address build --payment-script-file ${always_false_script_path} ${network})

# get current parameters
mkdir -p ./tmp
${cli} conway query protocol-parameters ${network} --out-file ./tmp/protocol.json
${cli} conway query tip ${network} | jq

# wallet
echo -e "\033[1;35m Contract Address: \033[0m"
echo -e "\033[1;35m Seedelf Contract Address: \033[0m"
echo -e "\n \033[1;35m ${seedelf_script_address} \033[0m \n";
${cli} conway query utxo --address ${seedelf_script_address} ${network}
${cli} conway query utxo --address ${seedelf_script_address} ${network} --out-file ./tmp/current.utxo

# wallet
echo -e "\033[1;35m Script Reference UTXO: \033[0m"
${cli} conway query utxo --address ${script_reference_address} ${network}

# Loop through each -wallet folder
for wallet_folder in wallets/*-wallet; do
# Check if payment.addr file exists in the folder
Expand Down
17 changes: 17 additions & 0 deletions validators/always_false.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// Always false to hold the seedelf script utxo.
////

validator contract(_random: ByteArray) {
spend(
_maybe_datum: Option<Data>,
_redeemer: Data,
_output_ref: Data,
_transaction: Data,
) {
False
}

else(_) {
fail
}
}

0 comments on commit d8b7983

Please sign in to comment.