From 2118d06300bd3af93943b62004a6b0e53405ce79 Mon Sep 17 00:00:00 2001 From: Cryp Toon Date: Mon, 25 Mar 2024 21:03:14 +0100 Subject: [PATCH 1/2] Fix bc error with scientific numbers in txfee_calc --- 04_2__Interlude_Using_JQ.md | 2 +- src/04_2_i_txfee-calc.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/04_2__Interlude_Using_JQ.md b/04_2__Interlude_Using_JQ.md index b516fe2a4..698beefa6 100644 --- a/04_2__Interlude_Using_JQ.md +++ b/04_2__Interlude_Using_JQ.md @@ -372,7 +372,7 @@ $ usedtxid=($(bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vin | .[] | . $ usedvout=($(bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vin | .[] | .vout')) $ btcin=$(for ((i=0; i<${#usedtxid[*]}; i++)); do txid=${usedtxid[i]}; vout=${usedvout[i]}; bitcoin-cli listunspent | jq -r '.[] | select (.txid | contains("'${txid}'")) | select(.vout | contains('$vout')) | .amount'; done | awk '{s+=$1} END {print s}') $ btcout=$(bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vout [] | .value' | awk '{s+=$1} END {print s}') -$ echo "$btcin-$btcout"| /usr/bin/bc +$ echo $(printf '%.8f-%.8f' $btcin $btcout_f) | /usr/bin/bc .255 ``` And that's also a good example of why you double-check your fees: we'd intended to send a transaction fee of 5,000 satoshis, but sent 255,000 satoshis instead. Whoops! diff --git a/src/04_2_i_txfee-calc.sh b/src/04_2_i_txfee-calc.sh index 64a884a23..0e94a0599 100644 --- a/src/04_2_i_txfee-calc.sh +++ b/src/04_2_i_txfee-calc.sh @@ -11,4 +11,4 @@ usedvout=($(bitcoin-cli decoderawtransaction $1 | jq -r '.vin | .[] | .vout')) btcin=$(for ((i=0; i<${#usedtxid[*]}; i++)); do txid=${usedtxid[i]}; vout=${usedvout[i]}; bitcoin-cli listunspent | jq -r '.[] | select (.txid | contains("'${txid}'")) | select(.vout | contains('$vout')) | .amount'; done | awk '{s+=$1} END {print s}') btcout=$(bitcoin-cli decoderawtransaction $1 | jq -r '.vout [] | .value' | awk '{s+=$1} END {print s}') btcout_f=$(awk -v btcout="$btcout" 'BEGIN { printf("%f\n", btcout) }' Date: Fri, 19 Apr 2024 10:42:01 +0200 Subject: [PATCH 2/2] Fix incorrect nSequence value --- 11_3_Using_CSV_in_Scripts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/11_3_Using_CSV_in_Scripts.md b/11_3_Using_CSV_in_Scripts.md index 745f9b99a..0fa4b16d3 100644 --- a/11_3_Using_CSV_in_Scripts.md +++ b/11_3_Using_CSV_in_Scripts.md @@ -14,7 +14,7 @@ Easy! > :information_source: **NOTE — SEQUENCE:** This is the third use of the `nSequence` value in Bitcoin. Any `nSequence` value without the 32nd bit set (1<<31), so 0x00000001 to 0x7ffffffff, will be interpreted as a relative timelock if `nVersion ≥ 2` (which is the default starting in Bitcoin Core 0.14.0). You should be careful to ensure that relative timelocks don't conflict with the other two uses of `nSequence`, for signalling `nTimeLock` and RBF. `nTimeLock` usually sets a value of 0xffffffff-1, where a relative timelock is disallowed; and RBF usually sets a value of "1", where a relative timelock is irrelevent, because it defines a timelock of 1 block. -> In general, remember: with a `nVersion` value of 2, a `nSequence` value of 0x00000001 to 0x7fffffff allows relative timelock, RBF, and `nTimeLock`; a `nSequence` value of 0x7fffffff to 0xffffffff-2 allows RBF and `nTimeLock`; a `nSequence` value of 0xffffffff-1 allows only `nTimeLock`; a `nSequence` value of 0xffffffff allows none; and `nVersion` can be set to 1 to disallow relative timelocks for any value of `nSequence`. Whew! +> In general, remember: with a `nVersion` value of 2, a `nSequence` value of 0x00000001 to 0x7ffffff allows relative timelock, RBF, and `nTimeLock`; a `nSequence` value of 0x7fffffff to 0xffffffff-2 allows RBF and `nTimeLock`; a `nSequence` value of 0xffffffff-1 allows only `nTimeLock`; a `nSequence` value of 0xffffffff allows none; and `nVersion` can be set to 1 to disallow relative timelocks for any value of `nSequence`. Whew! ### Create a CSV Relative Block Time