signing: rely on address_n being always list

pull/25/head
Jan Pochyla 6 years ago
parent 9291de47d0
commit b88e4e5d5a

@ -122,8 +122,6 @@ def sanitize_tx_input(tx: TransactionType) -> TxInputType:
txi.script_type = InputScriptType.SPENDADDRESS
if txi.sequence is None:
txi.sequence = 0xffffffff
if getattr(txi, 'address_n', None) is None:
txi.address_n = []
return txi

@ -71,7 +71,7 @@ def multisig_pubkey_index(multisig: MultisigRedeemScriptType, pubkey: bytes) ->
def multisig_get_pubkey(hd: HDNodePathType) -> bytes:
p = hd.address_n or []
p = hd.address_n
n = hd.node
node = bip32.HDNode(
depth=n.depth,

@ -482,12 +482,10 @@ def get_address_for_change(o: TxOutputType, coin: CoinType, root: bip32.HDNode):
input_script_type = InputScriptType.SPENDP2SHWITNESS
else:
raise SigningError(FailureType.DataError, 'Invalid script type')
address_n = o.address_n or []
return get_address(input_script_type, coin, node_derive(root, address_n), o.multisig)
return get_address(input_script_type, coin, node_derive(root, o.address_n), o.multisig)
def output_is_change(o: TxOutputType, wallet_path: list, segwit_in: int) -> bool:
address_n = o.address_n or []
is_segwit = (o.script_type == OutputScriptType.PAYTOWITNESS or
o.script_type == OutputScriptType.PAYTOP2SHWITNESS)
if is_segwit and o.amount > segwit_in:
@ -496,9 +494,9 @@ def output_is_change(o: TxOutputType, wallet_path: list, segwit_in: int) -> bool
# creating ANYONECANSPEND outputs before full segwit activation.
return False
return (wallet_path is not None and
wallet_path == address_n[:-_BIP32_WALLET_DEPTH] and
address_n[-2] <= _BIP32_CHANGE_CHAIN and
address_n[-1] <= _BIP32_MAX_LAST_ELEMENT)
wallet_path == o.address_n[:-_BIP32_WALLET_DEPTH] and
o.address_n[-2] <= _BIP32_CHANGE_CHAIN and
o.address_n[-1] <= _BIP32_MAX_LAST_ELEMENT)
# Tx Inputs

@ -33,12 +33,12 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
amount=0x0000000006b22c20,
script_type=OutputScriptType.PAYTOADDRESS,
multisig=None,
address_n=None)
address_n=[])
out2 = TxOutputType(address='16TZ8J6Q5iZKBWizWzFAYnrsaox5Z5aBRV', # derived
amount=0x000000000d519390,
script_type=OutputScriptType.PAYTOADDRESS,
multisig=None,
address_n=None)
address_n=[])
def test_prevouts(self):

@ -25,12 +25,12 @@ class TestSegwitBip143(unittest.TestCase):
amount=0x000000000bebb4b8,
script_type=OutputScriptType.PAYTOADDRESS,
multisig=None,
address_n=None)
address_n=[])
out2 = TxOutputType(address='1Q5YjKVj5yQWHBBsyEBamkfph3cA6G9KK8',
amount=0x000000002faf0800,
script_type=OutputScriptType.PAYTOADDRESS,
multisig=None,
address_n=None)
address_n=[])
def test_bip143_prevouts(self):

@ -42,14 +42,14 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(
address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu',
script_type=OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000,
address_n=None,
address_n=[],
multisig=None,
)
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2)
@ -137,7 +137,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(

@ -42,14 +42,14 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(
address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX',
script_type=OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000,
address_n=None,
address_n=[],
multisig=None,
)
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2)
@ -137,7 +137,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(
@ -252,7 +252,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=8,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(

@ -40,7 +40,7 @@ class TestSignTxFeeThreshold(unittest.TestCase):
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
amount=390000,
multisig=None,
address_n=None)
address_n=[])
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
@ -54,7 +54,7 @@ class TestSignTxFeeThreshold(unittest.TestCase):
amount=390000 - 100000, # fee increased to 100000 => too high
multisig=None,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None)
address_n=[])
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1)
messages = [
@ -106,7 +106,7 @@ class TestSignTxFeeThreshold(unittest.TestCase):
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
amount=390000,
multisig=None,
address_n=None)
address_n=[])
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
@ -120,7 +120,7 @@ class TestSignTxFeeThreshold(unittest.TestCase):
amount=390000 - 90000, # fee increased to 90000, slightly less than the threshold
script_type=OutputScriptType.PAYTOADDRESS,
multisig=None,
address_n=None)
address_n=[])
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1)
messages = [

@ -40,7 +40,7 @@ class TestSignTx(unittest.TestCase):
sequence=None)
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
amount=390000,
address_n=None)
address_n=[])
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
@ -53,7 +53,7 @@ class TestSignTx(unittest.TestCase):
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None)
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1)

@ -30,7 +30,7 @@ class TestCalculateTxWeight(unittest.TestCase):
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None)
calculator = TxWeightCalculator(1, 1)
@ -63,14 +63,14 @@ class TestCalculateTxWeight(unittest.TestCase):
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(
address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX',
script_type=OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000,
address_n=None,
address_n=[],
multisig=None,
)
@ -105,14 +105,14 @@ class TestCalculateTxWeight(unittest.TestCase):
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS,
address_n=None,
address_n=[],
multisig=None,
)
out2 = TxOutputType(
address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu',
script_type=OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000,
address_n=None,
address_n=[],
multisig=None,
)

Loading…
Cancel
Save