Skip to content

Commit

Permalink
Warn about locktime set with all final TxIn sequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss committed Dec 8, 2024
1 parent 0efe6cc commit 5ccb15b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
8 changes: 6 additions & 2 deletions pycoin/cmds/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def dump_header(output, tx):
else:
when = datetime.datetime.utcfromtimestamp(tx.lock_time)
meaning = "valid on or after %s utc" % when.isoformat()
if tx.lock_time != 0:
if all(tx_in.sequence == 0xffffffff for tx_in in tx.txs_in):
meaning = "IGNORED as all inputs have sequence 0xffffffff"
output.append("Lock time: %d (%s)" % (tx.lock_time, meaning))
output.append("Input%s:" % ('s' if len(tx.txs_in) != 1 else ''))

Expand Down Expand Up @@ -62,8 +65,9 @@ def dump_inputs(output, tx, network, verbose_signature, traceback_f, disassembly
sig_result = " sig ok" if tx.is_solution_ok(idx, traceback_f=traceback_f) else " BAD SIG"
suffix = " %12.5f m%s %s" % (satoshi_to_mbtc(tx_out.coin_value), network.symbol, sig_result)
address = network.address.for_script(tx_out.puzzle_script())
t = "%4d: %34s from %s:%-4d%s" % (idx, address, b2h_rev(tx_in.previous_hash),
tx_in.previous_index, suffix)
seq_text = "" if tx_in.sequence == 0xffffffff else " %8x" % tx_in.sequence
t = "%4d: %34s from %s:%-4d%s%s" % (idx, address, b2h_rev(tx_in.previous_hash),
tx_in.previous_index, suffix, seq_text)
output.append(t.rstrip())
if disassembly_level > 0:
dump_disassembly(output, tx, idx, network.annotate)
Expand Down
9 changes: 6 additions & 3 deletions pycoin/cmds/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def create_parser():
parser.add_argument('-l', "--lock-time", type=parse_locktime, help='Lock time; either a block'
'index, or a date/time (example: "2014-01-01T15:00:00"')

parser.add_argument('-q', "--sequence", type=int, default=0xffffffff,
help='Sequence for new tx_in objects. Must be non-default for lock_time to be respected. (Try 1)')

parser.add_argument('-n', "--network", default=get_current_netcode(), choices=codes,
help=('Default network code (environment variable PYCOIN_DEFAULT_NETCODE '
'or "BTC"=Bitcoin mainnet if unset'))
Expand Down Expand Up @@ -451,7 +454,7 @@ def parse_context(args, parser):
return (network, txs, spendables, payables, keychain, tx_db, warning_spendables)


def merge_txs(network, txs, spendables, payables):
def merge_txs(network, txs, spendables, payables, sequence):

tx_class = network.tx
txs_in = []
Expand All @@ -470,7 +473,7 @@ def merge_txs(network, txs, spendables, payables):
txs_out.extend(tx.txs_out[smaller:])
unspents.extend(tx.unspents[smaller:])
for spendable in spendables:
txs_in.append(spendable.tx_in())
txs_in.append(spendable.tx_in(sequence=sequence))
unspents.append(spendable)
for script, coin_value in payables:
txs_out.append(tx_class.TxOut(coin_value, script))
Expand Down Expand Up @@ -522,7 +525,7 @@ def wif_iter(iters):


def generate_tx(network, txs, spendables, payables, args):
txs_in, txs_out, unspents = merge_txs(network, txs, spendables, payables)
txs_in, txs_out, unspents = merge_txs(network, txs, spendables, payables, args.sequence)
lock_time, version = calculate_lock_time_and_version(args, txs)
if len(unspents) == len(txs_in):
unspents = remove_indices(unspents, args.remove_tx_in)
Expand Down
2 changes: 1 addition & 1 deletion tests/cmds/test_cases/tx/dump_lock_time.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Version: 1 tx hash e8151a2af31c368a35053ddd4bdb285a8595c769a3ad83e0fa02314a602
TxIn count: 2; TxOut count: 2
Lock time: 17 (valid after block index 17)
Inputs:
0: (unknown) from 9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff:0
0: (unknown) from 9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff:0 ffffffee
1: (unknown) from 8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef:1
Outputs:
0: 1Cu32FVupVCgHkMMRJdYJugxwo2Aprgk7H receives 1123.40000 mBTC
Expand Down
2 changes: 1 addition & 1 deletion tests/cmds/test_cases/tx/locktime_block.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tx -l 500000 d61aa2a5f5bce59d2a57447134f7ce9ce9d29b5c471f4bf747c43bf82aa26c2a/1/76a91491b24bf9f5288532960ac687abb035127b1d28a588ac/12345678 KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn 1KissFDVu2wAYWPRm4UGh5ZCDU9sE9an8T 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH --db 010000000135b0092a869bca1bc43e1628b3cb9e56ff9099a271fe95755e6f9289cf885b98000000008c4930460221008342b7eee70400acfed8d68be5aa8a6aeb06d7a2b3aef1fab7e4c1e46391efc6022100c0f86ba04f9a43c0d7fc8ab4cf9f3292989d3067f9b04e013c4a96bee87d5e1c014104dbedbe0028b3cbf362cad654c3b3e0902f65004691fa1332e94a31202ff06f4f7e67bd57d278c6a40b1915feb3bfb6850ca3750456e4c9af9db3d57a22b65323ffffffff02102f3504000000001976a9149b92770a85b1252448ec69900e77f1371d6a620188ac4e61bc00000000001976a91491b24bf9f5288532960ac687abb035127b1d28a588ac00000000
Version: 1 tx hash 992638b6c17e390fb3b2f221700de1315bb00333aa1a8ceda114ae0ec5408b21 258 bytes
TxIn count: 1; TxOut count: 2
Lock time: 500000 (valid after block index 500000)
Lock time: 500000 (IGNORED as all inputs have sequence 0xffffffff)
Input:
0: 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm from d61aa2a5f5bce59d2a57447134f7ce9ce9d29b5c471f4bf747c43bf82aa26c2a:1 123.45678 mBTC sig ok
Outputs:
Expand Down
2 changes: 1 addition & 1 deletion tests/cmds/test_cases/tx/locktime_date.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tx -l 2017-12-31T15:16:17 d61aa2a5f5bce59d2a57447134f7ce9ce9d29b5c471f4bf747c43bf82aa26c2a/1/76a91491b24bf9f5288532960ac687abb035127b1d28a588ac/12345678 KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn 1KissFDVu2wAYWPRm4UGh5ZCDU9sE9an8T 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH --db 010000000135b0092a869bca1bc43e1628b3cb9e56ff9099a271fe95755e6f9289cf885b98000000008c4930460221008342b7eee70400acfed8d68be5aa8a6aeb06d7a2b3aef1fab7e4c1e46391efc6022100c0f86ba04f9a43c0d7fc8ab4cf9f3292989d3067f9b04e013c4a96bee87d5e1c014104dbedbe0028b3cbf362cad654c3b3e0902f65004691fa1332e94a31202ff06f4f7e67bd57d278c6a40b1915feb3bfb6850ca3750456e4c9af9db3d57a22b65323ffffffff02102f3504000000001976a9149b92770a85b1252448ec69900e77f1371d6a620188ac4e61bc00000000001976a91491b24bf9f5288532960ac687abb035127b1d28a588ac00000000
Version: 1 tx hash d498c71a031848043f9326bbbf2c879c88522fd25d1bd908758ef020a6888fc8 257 bytes
TxIn count: 1; TxOut count: 2
Lock time: 1514733377 (valid on or after 2017-12-31T15:16:17 utc)
Lock time: 1514733377 (IGNORED as all inputs have sequence 0xffffffff)
Input:
0: 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm from d61aa2a5f5bce59d2a57447134f7ce9ce9d29b5c471f4bf747c43bf82aa26c2a:1 123.45678 mBTC sig ok
Outputs:
Expand Down
2 changes: 1 addition & 1 deletion tests/cmds/test_cases/tx/pay_to_taproot_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Version: 1 tx hash 33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac987
TxIn count: 1; TxOut count: 2
Lock time: 709631 (valid after block index 709631)
Input:
0: bc1pxwww0ct9ue7e8tdnlmug5m2tamfn7q06sahstg39ys4c9f3340qqxrdu9k from 5849051cf3ce36257a1d844e28959f368a35adc9520fb9679175f6cdf8c1f1d1:1 0.88480 mBTC sig ok
0: bc1pxwww0ct9ue7e8tdnlmug5m2tamfn7q06sahstg39ys4c9f3340qqxrdu9k from 5849051cf3ce36257a1d844e28959f368a35adc9520fb9679175f6cdf8c1f1d1:1 0.88480 mBTC sig ok fffffffd
Outputs:
0: (nulldata 2f49206c696b65205363686e6f7272207369677320616e6420492063616e6e6f74206c69652e20406269746275673432) receives 0.00000 mBTC
1: bc1p5d7rjq7g6rdk2yhzks9smlaqtedr4dekq08ge8ztwac72sfr9rusxg3297 receives 0.67230 mBTC
Expand Down
4 changes: 2 additions & 2 deletions tests/cmds/test_cases/tx/remove_tx_in.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Version: 2 tx hash 5b8e32dc53c9b3267ca2e5966f174bd8731e1b1351b614a1e97a0ce66a8
TxIn count: 2; TxOut count: 2
Lock time: 480399 (valid after block index 480399)
Inputs:
0: 1LNYwcAqg7sF6nfEfRWG243kYTV5ja2QxY from a6f5d2d7336894e27e7411d8b3aadd2204cf9ef47ecc0e4115ad659d1ff84a6a:1 1.35947 mBTC BAD SIG
1: 1Dy8GKBND7vYCWWW8SPooCyE2jpfEYa5tx from fcad37863eff07eb2dc6d313f1a0189e3f877a41e39608e1166957a12ff9211f:0 9.47580 mBTC BAD SIG
0: 1LNYwcAqg7sF6nfEfRWG243kYTV5ja2QxY from a6f5d2d7336894e27e7411d8b3aadd2204cf9ef47ecc0e4115ad659d1ff84a6a:1 1.35947 mBTC BAD SIG fffffffe
1: 1Dy8GKBND7vYCWWW8SPooCyE2jpfEYa5tx from fcad37863eff07eb2dc6d313f1a0189e3f877a41e39608e1166957a12ff9211f:0 9.47580 mBTC BAD SIG fffffffe
Outputs:
0: 1DPDWe8aSEEx23zzHFzQuRPmFtL5Jo2Q16 receives 1.19567 mBTC
1: 17vVQ7KbpcKmFRe4MqaNiPtKm5b46WdsMu receives 9.49631 mBTC
Expand Down

0 comments on commit 5ccb15b

Please sign in to comment.