diff --git a/README.md b/README.md index bfbddd2..ba2b0b2 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Use the `complete_build.sh` script to build the contracts using the data from `c ## Headless Interaction -Use the `scripts` folder to interact with the dapp using the cardano-cli. +Use the `headless` folder to interact with the dapp using the cardano-cli. ## CIP30 Frontend Interaction diff --git a/complete_build.sh b/complete_build.sh index 7e9f997..cdd771f 100755 --- a/complete_build.sh +++ b/complete_build.sh @@ -14,7 +14,10 @@ rm -fr build/ || true echo -e "\033[1;34m Building Contracts \033[0m" # remove all traces for production -aiken build --trace-level silent --filter-traces user-defined +# aiken build --trace-level silent --filter-traces user-defined + +# partial traces +aiken build --trace-level compact --filter-traces user-defined # keep the traces for testing # aiken build --trace-level verbose --filter-traces all @@ -96,8 +99,6 @@ echo -e "\033[1;33m Thread Contract Hash: $(cat hashes/thread_contract.hash) \03 thread_vkh=$(cat hashes/thread_contract.hash) -############################################################################### -############## DATUM AND REDEEMER STUFF ####################################### ############################################################################### jq \ @@ -110,7 +111,7 @@ jq \ .fields[2].bytes=$cvkh | .fields[3].bytes=$tvkh ' \ -./scripts/data/reference/reference-datum.json | sponge ./scripts/data/reference/reference-datum.json +./headless/data/reference/reference-datum.json | sponge ./headless/data/reference/reference-datum.json # end of build echo -e "\033[1;32m\nBuilding Complete! \033[0m" \ No newline at end of file diff --git a/config.json b/config.json index 3dfb492..c9b50f9 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,9 @@ { "__comment1__": "Genesis UTxO From Starter Wallet", - "genesis_tx_id": "64a77e920056af16040e372df803980dc96f045dc10f6133c604a0e60d99ea57", + "genesis_tx_id": "d235ed02346839c6ae5f07191d6b5da2850c2adcef55a3fa435134add0135823", "genesis_tx_idx": 0, "__comment2__": "Random String For Data Reference", - "random_string": "08" + "random_string": "16", + "__comment3__": "Change address for reference and genesis", + "change_address": "addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp" } \ No newline at end of file diff --git a/headless/00_createScriptReferences.sh b/headless/00_createScriptReferences.sh index 4daed39..f26ab3d 100755 --- a/headless/00_createScriptReferences.sh +++ b/headless/00_createScriptReferences.sh @@ -10,6 +10,9 @@ ${cli} query protocol-parameters ${network} --out-file ./tmp/protocol.json # Addresses reference_address=$(cat ./wallets/reference-wallet/payment.addr) +# address to send the leftover ada too +change_address=$(jq -r '.change_address' ../config.json) + # perma lock the script references to the reference contract reference_script_path="../contracts/reference_contract.plutus" script_reference_address=$(${cli} address build --payment-script-file ${reference_script_path} ${network}) @@ -62,7 +65,7 @@ do --tx-out-reference-script-file ${contract} \ --fee 900000 - FEE=$(cardano-cli transaction calculate-min-fee \ + FEE=$(${cli} transaction calculate-min-fee \ --tx-body-file ./tmp/tx.draft \ ${network} \ --protocol-params-file ./tmp/protocol.json \ @@ -90,12 +93,47 @@ do --out-file ./tmp/utxo-${file_name}.signed \ ${network} - ref_tx_in=$(${cli} transaction txid --tx-body-file ./tmp/tx.draft)#0 + tx_id=$(${cli} transaction txid --tx-body-file ./tmp/tx.draft) + ref_tx_in=${tx_id}#0 echo - echo -e "\033[0;36mNext UTxO: $ref_tx_in \033[0m" + echo -e "\033[0;36m$file_name: $tx_id#1 \033[0m" done +${cli} transaction build-raw \ + --babbage-era \ + --protocol-params-file ./tmp/protocol.json \ + --out-file ./tmp/tx.draft \ + --tx-in ${ref_tx_in} \ + --tx-out="${change_address} + ${changeAmount}" \ + --fee 900000 + +FEE=$(${cli} transaction calculate-min-fee \ + --tx-body-file ./tmp/tx.draft \ + ${network} \ + --protocol-params-file ./tmp/protocol.json \ + --tx-in-count 1 \ + --tx-out-count 2 \ + --witness-count 1) +echo -e "\033[0;35mFEE: ${FEE} \033[0m" +fee=$(echo $FEE | rev | cut -c 9- | rev) + +changeAmount=$((${changeAmount} - ${fee})) + +${cli} transaction build-raw \ + --babbage-era \ + --protocol-params-file ./tmp/protocol.json \ + --out-file ./tmp/tx.draft \ + --tx-in ${ref_tx_in} \ + --tx-out="${change_address} + ${changeAmount}" \ + --fee ${fee} + +${cli} transaction sign \ + --signing-key-file ./wallets/reference-wallet/payment.skey \ + --tx-body-file ./tmp/tx.draft \ + --out-file ./tmp/change-tx.signed \ + ${network} + echo -e "\033[1;37m --------------------------------------------------------------------------------\033[0m" # now submit them in that order for contract in $(ls "../contracts"/* | sort -V) @@ -108,4 +146,8 @@ do --tx-file ./tmp/utxo-${file_name}.signed done +${cli} transaction submit \ + ${network} \ + --tx-file ./tmp/change-tx.signed + echo -e "\033[0;32m\nDone!\033[0m" \ No newline at end of file diff --git a/headless/01_genesisMint.sh b/headless/01_genesisMint.sh index 51b1230..821d177 100755 --- a/headless/01_genesisMint.sh +++ b/headless/01_genesisMint.sh @@ -15,17 +15,16 @@ reference_script_address=$(${cli} address build --payment-script-file ${referenc genesis_script_path="../contracts/genesis_contract.plutus" genesis_policy_id=$(cat ../hashes/genesis_contract.hash) -# fraction estate wallet +# starter wallet starter_address=$(cat wallets/starter-wallet/payment.addr) starter_pkh=$(${cli} address key-hash --payment-verification-key-file wallets/starter-wallet/payment.vkey) -change_address="addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp" +change_address=$(jq -r '.change_address' ../config.json) # collat wallet 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" ${cli} query utxo \ ${network} \ @@ -53,7 +52,6 @@ genesis_tkn="${full_genesis_tkn:0:64}" mint_genesis_asset="1 ${genesis_policy_id}.${genesis_tkn}" echo -e "\033[1;36m\nGenesis Token: ${mint_genesis_asset} \033[0m" - # mint 1 genesis token and burn 100M old fet mint_asset="${mint_genesis_asset}" @@ -82,17 +80,10 @@ collat_utxo=$(jq -r 'keys[0]' tmp/collat_utxo.json) genesis_ref_utxo=$(${cli} transaction txid --tx-file tmp/utxo-genesis_contract.plutus.signed ) -# slot contraints -slot=$(${cli} query tip ${network} | jq .slot) -current_slot=$(($slot - 1)) -final_slot=$(($slot + 2500)) - echo -e "\033[0;36m Building Tx \033[0m" FEE=$(${cli} transaction build \ --babbage-era \ --out-file tmp/tx.draft \ - --invalid-before ${current_slot} \ - --invalid-hereafter ${final_slot} \ --change-address ${change_address} \ --tx-in-collateral="${collat_utxo}" \ --tx-in ${starter_tx_in} \ diff --git a/headless/cogno/01_createCogno.sh b/headless/cogno/01_createCogno.sh index 5899c1a..508d1f9 100755 --- a/headless/cogno/01_createCogno.sh +++ b/headless/cogno/01_createCogno.sh @@ -69,7 +69,6 @@ UTXO_VALUE=$(${cli} transaction calculate-min-required-utxo \ --tx-out="${cogno_script_address} + 5000000 + ${MINT_ASSET}" | tr -dc '0-9') cogno_address_out="${cogno_script_address} + ${UTXO_VALUE} + ${MINT_ASSET}" - echo "Cogno OUTPUT:" ${cogno_address_out} # # exit diff --git a/headless/data/cogno/cogno-datum.json b/headless/data/cogno/cogno-datum.json index 9fefdee..439312e 100644 --- a/headless/data/cogno/cogno-datum.json +++ b/headless/data/cogno/cogno-datum.json @@ -25,6 +25,20 @@ "bytes": "" } ] + }, + { + "constructor": 0, + "fields": [ + { + "list": [] + }, + { + "list": [] + }, + { + "list": [] + } + ] } ] } diff --git a/headless/data/cogno/token.name b/headless/data/cogno/token.name index ea49282..72b262a 100644 --- a/headless/data/cogno/token.name +++ b/headless/data/cogno/token.name @@ -1 +1 @@ -cafebabe00ac8e5e2f504e19d70a15539d99f863bb0bebc3f5c445fa9b42a566 +cafebabe00198bc57f19a5ef202e916693db2f0aa39379ca337e1fa06531fb72 diff --git a/headless/data/cogno/updated-cogno-datum.json b/headless/data/cogno/updated-cogno-datum.json index 9fefdee..439312e 100644 --- a/headless/data/cogno/updated-cogno-datum.json +++ b/headless/data/cogno/updated-cogno-datum.json @@ -25,6 +25,20 @@ "bytes": "" } ] + }, + { + "constructor": 0, + "fields": [ + { + "list": [] + }, + { + "list": [] + }, + { + "list": [] + } + ] } ] } diff --git a/headless/data/reference/reference-datum.json b/headless/data/reference/reference-datum.json index 3e66090..2fc9534 100644 --- a/headless/data/reference/reference-datum.json +++ b/headless/data/reference/reference-datum.json @@ -2,16 +2,16 @@ "constructor": 0, "fields": [ { - "bytes": "bb551e2b69f617a629c30ea72e136cea8a43ce3959a2c35eed93b943" + "bytes": "4387279867defd6ca72708ff601a1c1c218985cfad4a3a00bf39841d" }, { - "bytes": "e1fe41795990685656635438f6427b6e5870a1e692260a5336d62ee9" + "bytes": "c85f8a7a6dc3bc8c541aa2c3350e0c1c996a666c627f8910d56f1d46" }, { - "bytes": "8dfffee833c1f5f5a88382c5d19154517acfe5539296e1a2f4f8fac4" + "bytes": "1e7ced4cd5054b9a5ede4b1f5cf0452092874c81be30bd029878dd6a" }, { - "bytes": "72c824ef52141a930fea10963bfcb73f6d114c8cafc1d6721c717e5e" + "bytes": "cee32b83349938116d94e1a550ec6c85d703cbb949c78dbcab25731b" } ] } diff --git a/headless/data/thread/thread-datum.json b/headless/data/thread/thread-datum.json index c9772fe..b38edbb 100644 --- a/headless/data/thread/thread-datum.json +++ b/headless/data/thread/thread-datum.json @@ -21,7 +21,7 @@ ] }, { - "bytes": "cafebabe00ac8e5e2f504e19d70a15539d99f863bb0bebc3f5c445fa9b42a566" + "bytes": "cafebabe0035b6040bb1810776a1bea50e956e754fffd48f95bb53f01558c945" } ] } \ No newline at end of file diff --git a/headless/data/thread/token.name b/headless/data/thread/token.name index b3a4c43..d515e65 100644 --- a/headless/data/thread/token.name +++ b/headless/data/thread/token.name @@ -1 +1 @@ -1abe11ed007c7a9687a042efabf5acecce82030b010ce630e87c264981e183b2 +1abe11ed00bc76a2013c2b81ac62a6cf0ae1b1338cae024eb6375b5658f3e452 diff --git a/headless/data/thread/updated-thread-datum.json b/headless/data/thread/updated-thread-datum.json index c9772fe..b38edbb 100644 --- a/headless/data/thread/updated-thread-datum.json +++ b/headless/data/thread/updated-thread-datum.json @@ -21,7 +21,7 @@ ] }, { - "bytes": "cafebabe00ac8e5e2f504e19d70a15539d99f863bb0bebc3f5c445fa9b42a566" + "bytes": "cafebabe0035b6040bb1810776a1bea50e956e754fffd48f95bb53f01558c945" } ] } \ No newline at end of file diff --git a/headless/trade_token.sh b/headless/send_all.sh similarity index 90% rename from headless/trade_token.sh rename to headless/send_all.sh index 92d5b7d..b8acf3a 100755 --- a/headless/trade_token.sh +++ b/headless/send_all.sh @@ -10,12 +10,12 @@ rm ./tmp/tx.signed || true ${cli} query protocol-parameters ${network} --out-file ./tmp/protocol.json # Sender Address -sender_path="wallets/user-1-wallet/" +sender_path="wallets/reference-wallet/" sender_address=$(cat ${sender_path}payment.addr) # Receiver Address # receiver_address=$(cat ${sender_path}payment.addr) -receiver_address="addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp" +receiver_address=$(jq -r '.change_address' ../config.json) # # exit # diff --git a/lib/cogno_v2/types/cogno.ak b/lib/cogno_v2/types/cogno.ak index 872e2ad..8f38b78 100644 --- a/lib/cogno_v2/types/cogno.ak +++ b/lib/cogno_v2/types/cogno.ak @@ -1,3 +1,4 @@ +use aiken/transaction/value.{AssetName} use assist/types/wallet.{Wallet} pub type Profile { @@ -6,9 +7,19 @@ pub type Profile { details: ByteArray, } +pub type Moderation { + // show posts from these users + friendly_user_list: List, + // do not show posts from these users + restricted_user_list: List, + // do not show these threads + restricted_thread_list: List, +} + pub type CognoDatum { owner: Wallet, profile: Profile, + moderation: Moderation, } pub type CognoRedeemer { diff --git a/lib/cogno_v2/types/thread.ak b/lib/cogno_v2/types/thread.ak index bcbe7a3..14555d8 100644 --- a/lib/cogno_v2/types/thread.ak +++ b/lib/cogno_v2/types/thread.ak @@ -13,7 +13,7 @@ pub type ThreadDatum { category: ByteArray, // a list of comments, can be strings or images comments: List, - // the tkn of the owner + // the cafebabe tkn of the owner tkn: AssetName, } diff --git a/validators/cogno.ak b/validators/cogno.ak index 6d827b9..6e634fc 100644 --- a/validators/cogno.ak +++ b/validators/cogno.ak @@ -50,7 +50,9 @@ validator( |> value.from_minted_value() |> value.flatten() // - // + // Remove a cogno by burning the cafebabe token if it exists. This + // transaction is valid if and only if there exists a valid signature. + // If the cafebabe token doesn't exist then it is still removeable. // and { // owner must sign @@ -66,6 +68,7 @@ validator( )?, // must burn cafebabe token if it exists or { + // if cogno exists then burn it and { values.prove_nft( this_input.output.value, diff --git a/validators/cogno_minter.ak b/validators/cogno_minter.ak index 8278783..268d8ca 100644 --- a/validators/cogno_minter.ak +++ b/validators/cogno_minter.ak @@ -33,13 +33,14 @@ validator( extra_signatories, .. } = context.transaction - // get tx info + // get first tx info let index: Int = find.first_input_index(inputs) let tx_hash: TxHash = find.first_input_txid(inputs) // get reference data stuff let ref_addr: Address = credential.from_script(data_ref_hash) let ref_input: Input = find.input_by_addr(reference_inputs, ref_addr) expect ref_datum: ReferenceDatum = data.input_datum(ref_input) + // generate the cafebabe token name let token_name: AssetName = util.token_name(tx_hash, index, #"cafebabe") // what is being minted in this transaction let mint_list: List<(PolicyId, AssetName, Int)> = @@ -73,7 +74,7 @@ validator( value.from_asset(currency_symbol, token_name, 1), outputs, )?, - // can not spend anything from cogno address + // single output going to the cogno address count.outputs_by_addr(outputs, cogno_addr, 1)?, } } diff --git a/validators/thread.ak b/validators/thread.ak index 9ff5db4..f8f92cb 100644 --- a/validators/thread.ak +++ b/validators/thread.ak @@ -63,7 +63,7 @@ validator( // transaction then it can be removed from the contract. // and { - // owner must sign + // owner must sign by referenced cogno signing.verify_sig(extra_signatories, cogno_datum.owner.pkh)?, // single script input, no script output count.inputs_by_addr(inputs, this_addr, 1)?, diff --git a/validators/thread_minter.ak b/validators/thread_minter.ak index 1e64817..be92f0f 100644 --- a/validators/thread_minter.ak +++ b/validators/thread_minter.ak @@ -26,13 +26,14 @@ validator( MintToken -> { let Transaction { inputs, reference_inputs, outputs, mint, .. } = context.transaction - // get tx info + // get the first tx info let index: Int = find.first_input_index(inputs) let tx_hash: TxHash = find.first_input_txid(inputs) // get reference data stuff let ref_addr: Address = credential.from_script(data_ref_hash) let ref_input: Input = find.input_by_addr(reference_inputs, ref_addr) expect ref_datum: ReferenceDatum = data.input_datum(ref_input) + // generate the 1abe11ed token name let token_name: AssetName = util.token_name(tx_hash, index, #"1abe11ed") // what is being minted in this transaction let mint_list: List<(PolicyId, AssetName, Int)> =