mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Compare commits
4 commits
61773d1210
...
42cd0ff341
Author | SHA1 | Date | |
---|---|---|---|
|
42cd0ff341 | ||
|
c5e44a0435 | ||
|
32d55e28af | ||
|
f535b2fe63 |
2 changed files with 11 additions and 50 deletions
|
@ -16,6 +16,11 @@ import sqlite3
|
|||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../test/functional'))
|
||||
|
||||
from test_framework.compressor import decompress_amount # noqa: E402
|
||||
from test_framework.messages import deser_compact_size, deser_varint # noqa: E402
|
||||
|
||||
|
||||
UTXO_DUMP_MAGIC = b'utxo\xff'
|
||||
UTXO_DUMP_VERSION = 2
|
||||
|
@ -28,53 +33,9 @@ NET_MAGIC_BYTES = {
|
|||
}
|
||||
|
||||
|
||||
def read_varint(f):
|
||||
"""Equivalent of `ReadVarInt()` (see serialization module)."""
|
||||
n = 0
|
||||
while True:
|
||||
dat = f.read(1)[0]
|
||||
n = (n << 7) | (dat & 0x7f)
|
||||
if (dat & 0x80) > 0:
|
||||
n += 1
|
||||
else:
|
||||
return n
|
||||
|
||||
|
||||
def read_compactsize(f):
|
||||
"""Equivalent of `ReadCompactSize()` (see serialization module)."""
|
||||
n = f.read(1)[0]
|
||||
if n == 253:
|
||||
n = int.from_bytes(f.read(2), "little")
|
||||
elif n == 254:
|
||||
n = int.from_bytes(f.read(4), "little")
|
||||
elif n == 255:
|
||||
n = int.from_bytes(f.read(8), "little")
|
||||
return n
|
||||
|
||||
|
||||
def decompress_amount(x):
|
||||
"""Equivalent of `DecompressAmount()` (see compressor module)."""
|
||||
if x == 0:
|
||||
return 0
|
||||
x -= 1
|
||||
e = x % 10
|
||||
x //= 10
|
||||
n = 0
|
||||
if e < 9:
|
||||
d = (x % 9) + 1
|
||||
x //= 9
|
||||
n = x * 10 + d
|
||||
else:
|
||||
n = x + 1
|
||||
while e > 0:
|
||||
n *= 10
|
||||
e -= 1
|
||||
return n
|
||||
|
||||
|
||||
def decompress_script(f):
|
||||
"""Equivalent of `DecompressScript()` (see compressor module)."""
|
||||
size = read_varint(f) # sizes 0-5 encode compressed script types
|
||||
size = deser_varint(f) # sizes 0-5 encode compressed script types
|
||||
if size == 0: # P2PKH
|
||||
return bytes([0x76, 0xa9, 20]) + f.read(20) + bytes([0x88, 0xac])
|
||||
elif size == 1: # P2SH
|
||||
|
@ -154,13 +115,13 @@ def main():
|
|||
# read key (COutPoint)
|
||||
if coins_per_hash_left == 0: # read next prevout hash
|
||||
prevout_hash = f.read(32)[::-1].hex()
|
||||
coins_per_hash_left = read_compactsize(f)
|
||||
prevout_index = read_compactsize(f)
|
||||
coins_per_hash_left = deser_compact_size(f)
|
||||
prevout_index = deser_compact_size(f)
|
||||
# read value (Coin)
|
||||
code = read_varint(f)
|
||||
code = deser_varint(f)
|
||||
height = code >> 1
|
||||
is_coinbase = code & 1
|
||||
amount = decompress_amount(read_varint(f))
|
||||
amount = decompress_amount(deser_varint(f))
|
||||
scriptpubkey = decompress_script(f).hex()
|
||||
write_batch.append((prevout_hash, prevout_index, amount, is_coinbase, height, scriptpubkey))
|
||||
if height > max_height:
|
||||
|
|
|
@ -87,7 +87,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
|||
# 0.21.x and 22.x would both produce bad derivation paths when topping up an inactive hd chain
|
||||
# Make sure that this is being automatically cleaned up by migration
|
||||
node_master = self.nodes[1]
|
||||
node_v22 = self.nodes[self.num_nodes - 5]
|
||||
node_v22 = self.nodes[self.num_nodes - 3]
|
||||
wallet_name = "bad_deriv_path"
|
||||
node_v22.createwallet(wallet_name=wallet_name, descriptors=False)
|
||||
bad_deriv_wallet = node_v22.get_wallet_rpc(wallet_name)
|
||||
|
|
Loading…
Add table
Reference in a new issue