wallet/address: p2wsh get_address

pull/25/head
Tomas Susanka 6 years ago committed by Jan Pochyla
parent b7e4fe02a9
commit 4c2dec55ed

@ -1,24 +1,20 @@
from micropython import const from micropython import const
from trezor import wire, ui from trezor import ui
async def layout_get_address(ctx, msg): async def layout_get_address(ctx, msg):
from trezor.messages.Address import Address from trezor.messages.Address import Address
from trezor.messages.InputScriptType import SPENDWITNESS from trezor.messages.InputScriptType import SPENDWITNESS
from trezor.messages.FailureType import ProcessError
from ..common import coins from ..common import coins
from ..common import seed from ..common import seed
from ..wallet.sign_tx import addresses from ..wallet.sign_tx import addresses
if msg.multisig:
raise wire.FailureError(ProcessError, 'GetAddress.multisig is unsupported')
address_n = msg.address_n or () address_n = msg.address_n or ()
coin_name = msg.coin_name or 'Bitcoin' coin_name = msg.coin_name or 'Bitcoin'
coin = coins.by_name(coin_name) coin = coins.by_name(coin_name)
node = await seed.derive_node(ctx, address_n) node = await seed.derive_node(ctx, address_n)
address = addresses.get_address(msg.script_type, coin, node) address = addresses.get_address(msg.script_type, coin, node, msg.multisig)
if msg.show_display: if msg.show_display:
while True: while True:

@ -30,13 +30,18 @@ def get_address(script_type: InputScriptType, coin: CoinType, node, multisig=Non
'Segwit not enabled on this coin') 'Segwit not enabled on this coin')
return address_p2wpkh(node.public_key(), coin.bech32_prefix) return address_p2wpkh(node.public_key(), coin.bech32_prefix)
elif script_type == InputScriptType.SPENDP2SHWITNESS: # p2wpkh using p2sh elif script_type == InputScriptType.SPENDP2SHWITNESS: # p2wpkh or p2wsh using p2sh
if not coin.segwit or coin.address_type_p2sh is None: if not coin.segwit or coin.address_type_p2sh is None:
raise AddressError(FailureType.ProcessError, raise AddressError(FailureType.ProcessError,
'Segwit not enabled on this coin') 'Segwit not enabled on this coin')
# p2wsh multisig
if multisig is not None:
return address_multisig_p2wsh_in_p2sh(multisig_get_pubkeys(multisig), multisig.m, coin.address_type_p2sh)
# p2wpkh
return address_p2wpkh_in_p2sh(node.public_key(), coin.address_type_p2sh) return address_p2wpkh_in_p2sh(node.public_key(), coin.address_type_p2sh)
elif script_type == InputScriptType.SPENDMULTISIG: # multisig elif script_type == InputScriptType.SPENDMULTISIG: # p2sh multisig
if multisig is None: if multisig is None:
raise AddressError(FailureType.ProcessError, raise AddressError(FailureType.ProcessError,
'Multisig details required') 'Multisig details required')

Loading…
Cancel
Save