Skip to content

Commit

Permalink
cleanup and remove app version enforcement for Ledger/Trezor. Up to u…
Browse files Browse the repository at this point in the history
…ser to make sure correct version is deployed.
  • Loading branch information
Scitz0 committed Jul 26, 2024
1 parent 5b74809 commit ef1c07b
Showing 1 changed file with 0 additions and 154 deletions.
154 changes: 0 additions & 154 deletions scripts/cnode-helper-scripts/cntools.library
Original file line number Diff line number Diff line change
Expand Up @@ -4527,19 +4527,6 @@ unlockHWDevice() {
println ERROR "${FG_RED}ERROR${NC}: unable to identify connected hardware device, is the device plugged in and unlocked?"
println ERROR "Make sure device is seen by OS using tools like lsusb etc and is working correctly"
waitToProceed && return 1
elif [[ ${device_app_vendor} = Ledger ]]; then
if ! versionCheck "5.0.1" "${device_app_version}"; then
println ERROR "${FG_RED}ERROR${NC}: Cardano app version installed on Ledger is ${FG_LGRAY}v${device_app_version}${NC}, minimum required app version is ${FG_GREEN}v5.0.1${NC} !!"
return 1
fi
elif [[ ${device_app_vendor} = Trezor ]]; then
if ! versionCheck "2.6.4" "${device_app_version}"; then
println ERROR "${FG_RED}ERROR${NC}: Trezor firmware installed on device is ${FG_LGRAY}v${device_app_version}${NC}, minimum required version is ${FG_GREEN}v2.6.4${NC} !!"
return 1
fi
else
println ERROR "${FG_RED}ERROR${NC}: Unknown vendor: ${FG_LGRAY}${device_app_vendor}${NC} !!"
return 1
fi
println DEBUG "\n${FG_BLUE}INFO${NC}: follow directions on hardware device to $1"
}
Expand Down Expand Up @@ -4664,147 +4651,6 @@ to_cbor() {
echo -n "${cbor^^}" #return the cbor in uppercase
}

# Command : submitPoll
# Description : sign and submit a CIP-0094 poll answer
submitPoll() {

getWalletType ${wallet_name}
wallet_type=$?

[[ $(cat "${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_ADDR_FILENAME}" 2>/dev/null) = "${addr}" ]] && wallet_source="payment" || wallet_source="base"
POOL_ID_HASH=$(cat ${POOL_FOLDER}/${pool_name}/${POOL_ID_FILENAME})

if [[ ${CNTOOLS_MODE} = "LIGHT" ]]; then
for key in "${!assets[@]}"; do
[[ ${key} != "${addr},"* ]] && unset 'assets[$key]'
done
utxo_cnt=${utxos_cnt[${addr}]}
tx_in=${tx_in_arr[${addr}]}
else
getBalance ${addr}
fi

if [[ ${wallet_type} -eq 5 ]]; then
op_mode=hybrid
unset required_total
validateMultiSigScript false "$(cat "${payment_script_file}")"
witness_cnt=$(( required_total + 1 ))
else
witness_cnt=2
fi

if ! getTTL "$([[ ${wallet_type} -eq 5 ]] && echo true)"; then return 1; fi

getAssetsTxOut

metafile_param="--metadata-cbor-file ${cborFile}"
if [[ -n ${metafile} && -f ${metafile} ]]; then
metafile_param+=" --json-metadata-no-schema --metadata-json-file ${metafile}"
fi

unset script_args
if [[ ${wallet_type} -eq 5 ]]; then
script_args=( --tx-in-script-file "${payment_script_file}" )
fi

tmpNewBalance=$(( lovelace ))
build_args=(
${tx_in}
"${script_args[@]}"
--tx-out "${addr}+${tmpNewBalance}${assets_tx_out}"
--invalid-hereafter ${ttl}
--fee ${DUMMYFEE}
${metafile_param}
--required-signer-hash "${POOL_ID_HASH}"
--out-file "${TMP_DIR}"/tx0.tmp
)

if ! buildTx; then return 1; fi

calcMinFee "${TMP_DIR}"/tx0.tmp ${utxo_cnt} 1 ${witness_cnt} || return 1

newBalance=$(( lovelace - min_fee ))
println LOG "Balance left to be returned in used UTxO is $(formatLovelace ${newBalance}) ADA ( $(formatLovelace ${lovelace}) - $(formatLovelace ${min_fee}) )"

if [[ ${lovelace} -lt ${min_fee} ]]; then
println ERROR "\n${FG_RED}ERROR${NC}: Not enough ADA in ${wallet_source} address for tx fee!"\
"Funds in address: ${FG_LBLUE}$(formatLovelace ${lovelace})${NC} ADA"\
"Minimum required: ${FG_LBLUE}$(formatLovelace ${min_fee})${NC} ADA"
return 1
fi

tx_out="${addr}+${newBalance}${assets_tx_out}"
getMinUTxO "${tx_out}" || return 1
if [[ ${newBalance} -lt ${min_utxo_out} ]]; then
println ERROR "\n${FG_RED}ERROR${NC}: minimum UTxO value not fulfilled, only ${FG_LBLUE}$(formatLovelace ${newBalance})${NC} ADA left in address after tx fee, at least ${FG_LBLUE}$(formatLovelace ${min_utxo_out})${NC} ADA required!"
return 1
fi

build_args=(
${tx_in}
"${script_args[@]}"
--tx-out "${tx_out}"
--invalid-hereafter ${ttl}
--fee ${min_fee}
${metafile_param}
--required-signer-hash "${POOL_ID_HASH}"
--out-file "${TMP_DIR}"/tx.raw
)

if ! buildTx; then return 1; fi

needHWCLI=false
pay_vk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_VK_FILENAME}"
[[ $(jq .description "${pay_vk_file}") = *Hardware* ]] && needHWCLI=true
if [[ ${needHWCLI} = true ]]; then
if ! HWCLIversionCheck; then return 1; fi
if ! transformRawTx "${TMP_DIR}"/tx.raw; then return 1; fi
fi

if [[ ${op_mode} = "hybrid" ]]; then
if ! buildOfflineJSON "Poll Cast"; then return 1; fi
if ! offlineJSON=$(jq ". += { \"wallet-name\": \"${wallet_name}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { txFee: \"${min_fee}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { \"poll-title\": \"${poll_title}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { \"poll-txId\": \"${poll_txId}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { \"poll-question\": \"${questionString}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { \"poll-answer\": \"${optionString[${answer}]}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { \"pool-name\": \"${pool_name}\" }" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { txBody: $(jq -c . "${TMP_DIR}"/tx.raw) }" <<< ${offlineJSON}); then return 1; fi
if [[ ${wallet_type} -eq 5 ]]; then
if ! offlineJSON=$(jq ".\"script-file\" += [{ name: \"Wallet '${wallet_name}' payment script\", script: $(jq -c . "${payment_script_file}") }]" <<< ${offlineJSON}); then return 1; fi
else
if ! offlineJSON=$(jq ".\"signing-file\" += [{ name: \"Wallet '${wallet_name}' payment signing key\", vkey: $(jq -c . "${payment_vk_file}") }]" <<< ${offlineJSON}); then return 1; fi
fi
if ! offlineJSON=$(jq ".\"signing-file\" += [{ name: \"Pool '${pool_name}' cold signing key\", vkey: $(jq -c . "${pool_coldkey_vk_file}") }]" <<< ${offlineJSON}); then return 1; fi
if ! offlineJSON=$(jq ". += { \"signed-txBody\": {} }" <<< ${offlineJSON}); then return 1; fi
offline_tx="${TMP_DIR}/offline_tx_$(jq -r .id <<< ${offlineJSON}).json"
jq -r . <<< "${offlineJSON}" > "${offline_tx}"
echo
if [[ ${wallet_type} -eq 5 ]]; then
println "CIP-0094 poll transaction successfully built and saved to: ${FG_LGRAY}${offline_tx}${NC}"
println DEBUG "Use CNTools [Transaction >> Sign] to witness the transaction with MultiSig wallet participants."
else
println "Offline transaction successfully built and saved to: ${FG_LGRAY}${offline_tx}${NC}"
println DEBUG "move file to offline computer and sign it using CNTools in offline mode '-o' [Transaction >> Sign] with:"
println DEBUG "Wallet ${FG_GREEN}${wallet_name} ${FG_LGRAY}$(basename ${payment_sk_file})${NC}"
println DEBUG "Pool ${FG_GREEN}${pool_name} ${FG_LGRAY}$(basename ${pool_coldkey_sk_file})${NC}"
fi
return 2 # return as failed to stop main processing and return to home menu
fi

echo "Transaction Fee: $(formatLovelace ${min_fee}) ADA"
println "\nDo you want to publish this answer for pool ${pool_name} on ${NETWORK_NAME}?"
select_opt "[n] No" "[y] Yes"
case $? in
1) if ! witnessTx "${TMP_DIR}/tx.raw" "${payment_sk_file}" "${pool_coldkey_sk_file}"; then return 1; fi
if ! assembleTx "${TMP_DIR}/tx.raw"; then return 1; fi
if ! submitTx "${tx_signed}"; then return 1; fi
println "Poll ${FG_GREEN}${poll_txId}${NC} ballot casted to the network"
waitToProceed && return
esac
}

# Command : getPriceInfo
# Description : fetch current ADA price from coingecko in selected currency
getPriceInfo() {
Expand Down

0 comments on commit ef1c07b

Please sign in to comment.