Skip to content

Commit

Permalink
work in progress update for conway - testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmachtl committed Nov 10, 2023
1 parent 46040b7 commit 37f8b2a
Show file tree
Hide file tree
Showing 27 changed files with 1,438 additions and 534 deletions.
575 changes: 492 additions & 83 deletions cardano/testnet/00_common.sh

Large diffs are not rendered by default.

156 changes: 114 additions & 42 deletions cardano/testnet/01_claimRewards.sh

Large diffs are not rendered by default.

158 changes: 129 additions & 29 deletions cardano/testnet/01_queryAddress.sh

Large diffs are not rendered by default.

98 changes: 65 additions & 33 deletions cardano/testnet/01_sendAssets.sh
Expand Up @@ -124,7 +124,7 @@ if [ ${paramCnt} -ge 2 ]; then
typeOfAddr=$(get_addressType "${toAddr}");
if [[ ${typeOfAddr} != ${addrTypePayment} ]]; then echo -e "\n\e[35mERROR - Resolved address '${toAddr}' is not a valid payment address.\n\e[0m"; exit 1; fi;
showProcessAnimation "Verify Adahandle is on resolved address: " &
utxo=$(${cardanocli} query utxo --address ${toAddr} ${magicparam} ); stopProcessAnimation; checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi;
utxo=$(${cardanocli} ${cliEra} query utxo --address ${toAddr} ); stopProcessAnimation; checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi;
if [[ $(grep "${adahandlePolicyID}.${assetNameHex} " <<< ${utxo} | wc -l) -ne 1 ]]; then
echo -e "\n\e[35mERROR - Resolved address '${toAddr}' does not hold the \$adahandle '${adahandleName}' !\n\e[0m"; exit 1; fi;
echo -e "\e[0mFound \$adahandle '${adahandleName}' on Address:\e[32m ${toAddr}\e[0m\n"
Expand Down Expand Up @@ -395,8 +395,7 @@ echo

#get live values
currentTip=$(get_currentTip)
ttl=$(get_currentTTL)
currentEPOCH=$(get_currentEpoch)
ttl=$(( ${currentTip} + ${defTTL} ))

echo -e "\e[0mCurrent Slot-Height:\e[32m ${currentTip} \e[0m(setting TTL[invalid_hereafter] to ${ttl})"
echo
Expand All @@ -409,20 +408,41 @@ echo
# Checking UTXO Data of the source address and gathering data about total lovelaces and total assets
#

#Get UTX0 Data for the address. When in online mode of course from the node and the chain, in offlinemode from the transferFile
if ${onlineMode}; then
showProcessAnimation "Query-UTXO: " &
utxo=$(${cardanocli} query utxo --address ${sendFromAddr} ${magicparam} ); stopProcessAnimation; checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi;
if [[ ${skipUtxoWithAsset} != "" ]]; then utxo=$(echo "${utxo}" | egrep -v "${skipUtxoWithAsset}" ); fi #if its set to keep utxos that contains certain policies, filter them out
if [[ ${onlyUtxoWithAsset} != "" ]]; then utxo=$(echo "${utxo}" | egrep "${onlyUtxoWithAsset}" ); utxo=$(echo -e "Header\n-----\n${utxo}"); fi #only use given utxos. rebuild the two header lines
if [[ ${utxoLimitCnt} -gt 0 ]]; then utxo=$(echo "${utxo}" | head -n $(( ${utxoLimitCnt} + 2 )) ); fi #if there was a utxo cnt limit set, reduce it (+2 for the header)

#Get UTX0 Data for the address. When in online mode of course from the node and the chain, in lightmode via API requests, in offlinemode from the transferFile
case ${workMode} in
"online") if [[ "${utxo}" == "" ]]; then #only query it again if not already queried via an adahandle check before
#check that the node is fully synced, otherwise the query would mabye return a false state
if [[ $(get_currentSync) != "synced" ]]; then echo -e "\e[35mError - Node not fully synced or not running, please let your node sync to 100% first !\e[0m\n"; exit 1; fi
showProcessAnimation "Query-UTXO: " &
utxo=$(${cardanocli} ${cliEra} query utxo --address ${sendFromAddr} 2> /dev/stdout);
if [ $? -ne 0 ]; then stopProcessAnimation; echo -e "\e[35mERROR - ${utxo}\e[0m\n"; exit $?; else stopProcessAnimation; fi;
if [[ ${skipUtxoWithAsset} != "" ]]; then utxo=$(echo "${utxo}" | egrep -v "${skipUtxoWithAsset}" ); fi #if its set to keep utxos that contains certain policies, filter them out
if [[ ${onlyUtxoWithAsset} != "" ]]; then utxo=$(echo "${utxo}" | egrep "${onlyUtxoWithAsset}" ); utxo=$(echo -e "Header\n-----\n${utxo}"); fi #only use given utxos. rebuild the two header lines
if [[ ${utxoLimitCnt} -gt 0 ]]; then utxo=$(echo "${utxo}" | head -n $(( ${utxoLimitCnt} + 2 )) ); fi #if there was a utxo cnt limit set, reduce it (+2 for the header)
fi
showProcessAnimation "Convert-UTXO: " &
utxoJSON=$(generate_UTXO "${utxo}" "${sendFromAddr}"); stopProcessAnimation;
;;

"light") if [[ "${utxo}" == "" ]]; then #only query it again if not already queried via an adahandle check before
showProcessAnimation "Query-UTXO-LightMode: " &
utxo=$(queryLight_UTXO "${sendFromAddr}");
if [ $? -ne 0 ]; then stopProcessAnimation; echo -e "\e[35mERROR - ${utxo}\e[0m\n"; exit $?; else stopProcessAnimation; fi;
if [[ ${skipUtxoWithAsset} != "" ]]; then utxo=$(echo "${utxo}" | egrep -v "${skipUtxoWithAsset}" ); fi #if its set to keep utxos that contains certain policies, filter them out
if [[ ${onlyUtxoWithAsset} != "" ]]; then utxo=$(echo "${utxo}" | egrep "${onlyUtxoWithAsset}" ); utxo=$(echo -e "Header\n-----\n${utxo}"); fi #only use given utxos. rebuild the two header lines
if [[ ${utxoLimitCnt} -gt 0 ]]; then utxo=$(echo "${utxo}" | head -n $(( ${utxoLimitCnt} + 2 )) ); fi #if there was a utxo cnt limit set, reduce it (+2 for the header)
fi
showProcessAnimation "Convert-UTXO: " &
utxoJSON=$(generate_UTXO "${utxo}" "${sendFromAddr}"); stopProcessAnimation;
else
readOfflineFile; #Reads the offlinefile into the offlineJSON variable
utxoJSON=$(jq -r ".address.\"${sendFromAddr}\".utxoJSON" <<< ${offlineJSON})
;;


"offline") readOfflineFile; #Reads the offlinefile into the offlineJSON variable
utxoJSON=$(jq -r ".address.\"${sendFromAddr}\".utxoJSON" <<< ${offlineJSON} 2> /dev/null)
if [[ "${utxoJSON}" == null ]]; then echo -e "\e[35mPayment-Address not included in the offline transferFile, please include it first online!\e[0m\n"; exit 1; fi
fi
;;
esac

#Only use UTXOs specied in the extra parameter if present
if [[ ! "${filterForUTXO}" == "" ]]; then echo -e "\e[0mUTXO-Mode: \e[32mOnly using the UTXO with Hash ${filterForUTXO}\e[0m\n"; utxoJSON=$(filterFor_UTXO "${utxoJSON}" "${filterForUTXO}"); fi
Expand Down Expand Up @@ -635,11 +655,11 @@ fi
rxcnt=2

#Read ProtocolParameters
if ${onlineMode}; then
protocolParametersJSON=$(${cardanocli} query protocol-parameters ${magicparam} ); #onlinemode
else
protocolParametersJSON=$(jq ".protocol.parameters" <<< ${offlineJSON}); #offlinemode
fi
case ${workMode} in
"online") protocolParametersJSON=$(${cardanocli} ${cliEra} query protocol-parameters );; #onlinemode
"light") protocolParametersJSON=${lightModeParametersJSON};; #lightmode
"offline") protocolParametersJSON=$(jq ".protocol.parameters" <<< ${offlineJSON});; #offlinemode
esac
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi

#minOutUTXO=$(calc_minOutUTXO "${protocolParametersJSON}" "${sendToAddr}+0${assetsSendString}")
Expand All @@ -649,9 +669,9 @@ minReturnUTXO=$(calc_minOutUTXO "${protocolParametersJSON}" "${sendToAddr}+10000
#Generate Dummy-TxBody file for fee calculation
txBodyFile="${tempDir}/dummy.txbody"
rm ${txBodyFile} 2> /dev/null
${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+1000000${assetsSendString}" --tx-out "${sendToAddr}+1000000${assetsReturnString}" --invalid-hereafter ${ttl} --fee 0 ${metafileParameter} --out-file ${txBodyFile}
${cardanocli} ${cliEra} transaction build-raw ${txInString} --tx-out "${sendToAddr}+1000000${assetsSendString}" --tx-out "${sendToAddr}+1000000${assetsReturnString}" --invalid-hereafter ${ttl} --fee 0 ${metafileParameter} --out-file ${txBodyFile}
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
fee=$(${cardanocli} transaction calculate-min-fee --tx-body-file ${txBodyFile} --protocol-params-file <(echo ${protocolParametersJSON}) --tx-in-count ${txcnt} --tx-out-count ${rxcnt} ${magicparam} --witness-count 1 --byron-witness-count 0 | awk '{ print $1 }')
fee=$(${cardanocli} ${cliEra} transaction calculate-min-fee --tx-body-file ${txBodyFile} --protocol-params-file <(echo ${protocolParametersJSON}) --tx-in-count ${txcnt} --tx-out-count ${rxcnt} --witness-count 1 --byron-witness-count 0 | awk '{ print $1 }')
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi

echo -e "\e[0mMinimum Transaction Fee for ${txcnt}x TxIn & ${rxcnt}x TxOut: \e[32m $(convertToADA ${fee}) ADA / ${fee} lovelaces \e[90m"
Expand Down Expand Up @@ -679,7 +699,7 @@ echo

#Building unsigned transaction body
rm ${txBodyFile} 2> /dev/null
${cardanocli} transaction build-raw ${nodeEraParam} ${txInString} --tx-out "${sendToAddr}+${lovelacesToSend}${assetsSendString}" --tx-out "${sendFromAddr}+${lovelacesToReturn}${assetsReturnString}" --invalid-hereafter ${ttl} --fee ${fee} ${metafileParameter} --out-file ${txBodyFile}
${cardanocli} ${cliEra} transaction build-raw ${txInString} --tx-out "${sendToAddr}+${lovelacesToSend}${assetsSendString}" --tx-out "${sendFromAddr}+${lovelacesToReturn}${assetsReturnString}" --invalid-hereafter ${ttl} --fee ${fee} ${metafileParameter} --out-file ${txBodyFile}
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi

dispFile=$(cat ${txBodyFile}); if ${cropTxOutput} && [[ ${#dispFile} -gt 4000 ]]; then echo "${dispFile:0:4000} ... (cropped)"; else echo "${dispFile}"; fi
Expand Down Expand Up @@ -718,7 +738,7 @@ if [[ -f "${fromAddr}.hwsfile" ]]; then
if [[ "${tmp^^}" =~ (ERROR|DISCONNECT) ]]; then echo -e "\e[35m${tmp}\e[0m\n"; exit 1; else echo -ne "\e[0mWitnessed ... "; fi
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi

${cardanocli} transaction assemble --tx-body-file ${txBodyFile} --witness-file ${txWitnessFile} --out-file ${txFile}
${cardanocli} ${cliEra} transaction assemble --tx-body-file ${txBodyFile} --witness-file ${txWitnessFile} --out-file ${txFile}
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
echo -e "Assembled ... \e[32mDONE\e[0m\n";

Expand All @@ -730,7 +750,7 @@ else
echo -e "\e[0mSign the unsigned transaction body with the \e[32m${fromAddr}.skey\e[0m: \e[32m ${txFile}\e[0m"
echo

${cardanocli} transaction sign --tx-body-file ${txBodyFile} --signing-key-file <(echo "${skeyJSON}") ${magicparam} --out-file ${txFile}
${cardanocli} ${cliEra} transaction sign --tx-body-file ${txBodyFile} --signing-key-file <(echo "${skeyJSON}") --out-file ${txFile}
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi

#forget the signing keys
Expand All @@ -755,20 +775,32 @@ if [[ ${txSize} -le ${maxTxSize} ]]; then echo -e "\e[0mTransaction-Size: ${txSi
#if ask "\e[33mDoes this look good for you, continue ?" N; then
if [ "${ENV_SKIP_PROMPT}" == "YES" ] || ask "\n\e[33mDoes this look good for you, continue ?" N; then

echo
if ${onlineMode}; then #onlinesubmit
echo
case ${workMode} in
"online")
#onlinesubmit
echo -ne "\e[0mSubmitting the transaction via the node... "
${cardanocli} transaction submit --tx-file ${txFile} ${magicparam}
${cardanocli} ${cliEra} transaction submit --tx-file ${txFile}
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi
echo -e "\e[32mDONE\n"

#Show the TxID
txID=$(${cardanocli} transaction txid --tx-file ${txFile}); echo -e "\e[0m TxID is: \e[32m${txID}\e[0m"
txID=$(${cardanocli} ${cliEra} transaction txid --tx-file ${txFile}); echo -e "\e[0m TxID is: \e[32m${txID}\e[0m"
checkError "$?"; if [ $? -ne 0 ]; then exit $?; fi;
if [[ "${transactionExplorer}" != "" ]]; then echo -e "\e[0mTracking: \e[32m${transactionExplorer}/${txID}\n\e[0m"; fi
;;

"light")
#lightmode submit
showProcessAnimation "Submit-Transaction-LightMode: " &
txID=$(submitLight "${txFile}");
if [ $? -ne 0 ]; then stopProcessAnimation; echo -e "\e[35mERROR - ${txID}\e[0m\n"; exit $?; else stopProcessAnimation; fi;
echo -e "\e[0mSubmit-Transaction-LightMode: \e[32mDONE\n"
if [[ "${transactionExplorer}" != "" ]]; then echo -e "\e[0mTracking: \e[32m${transactionExplorer}/${txID}\n\e[0m"; fi
;;


else #offlinestore
"offline")
#offlinestore
txFileJSON=$(cat ${txFile} | jq .)
offlineJSON=$( jq ".transactions += [ { date: \"$(date -R)\",
type: \"Transaction\",
Expand All @@ -781,7 +813,6 @@ if [ "${ENV_SKIP_PROMPT}" == "YES" ] || ask "\n\e[33mDoes this look good for you
#Write the new offileFile content
offlineJSON=$( jq ".history += [ { date: \"$(date -R)\", action: \"generated and signed utxo-token-transaction from '${fromAddr}' to '${toAddr}'\" } ]" <<< ${offlineJSON})
offlineJSON=$( jq ".general += {offlineCLI: \"${versionCLI}\" }" <<< ${offlineJSON})
offlineJSON=$( jq ".general += {offlineNODE: \"${versionNODE}\" }" <<< ${offlineJSON})
echo "${offlineJSON}" > ${offlineFile}
#Readback the tx content and compare it to the current one
readback=$(cat ${offlineFile} | jq -r ".transactions[-1].txJSON")
Expand All @@ -791,10 +822,11 @@ if [ "${ENV_SKIP_PROMPT}" == "YES" ] || ask "\n\e[33mDoes this look good for you
else
echo -e "\e[35mERROR - Could not verify the written data in the '$(basename ${offlineFile})'. Retry again or generate a new '$(basename ${offlineFile})'.\e[0m\n";
fi
;;

fi
fi
esac

fi

echo -e "\e[0m\n"

Expand Down

0 comments on commit 37f8b2a

Please sign in to comment.