本文整理汇总了Python中electrum.account.BIP32_Account类的典型用法代码示例。如果您正苦于以下问题:Python BIP32_Account类的具体用法?Python BIP32_Account怎么用?Python BIP32_Account使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BIP32_Account类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tx_inputs
def tx_inputs(self, tx, for_sig=False):
inputs = []
for txin in tx.inputs:
txinputtype = self.types.TxInputType()
if txin.get('is_coinbase'):
prev_hash = "\0"*32
prev_index = 0xffffffff # signed int -1
else:
if for_sig:
x_pubkeys = txin['x_pubkeys']
if len(x_pubkeys) == 1:
x_pubkey = x_pubkeys[0]
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
txinputtype.address_n.extend(xpub_n + s)
else:
def f(x_pubkey):
if is_extended_pubkey(x_pubkey):
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
else:
xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
s = []
node = ckd_public.deserialize(xpub)
return self.types.HDNodePathType(node=node, address_n=s)
pubkeys = map(f, x_pubkeys)
multisig = self.types.MultisigRedeemScriptType(
pubkeys=pubkeys,
signatures=map(lambda x: x.decode('hex') if x else '', txin.get('signatures')),
m=txin.get('num_sig'),
)
txinputtype = self.types.TxInputType(
script_type=self.types.SPENDMULTISIG,
multisig=multisig
)
# find which key is mine
for x_pubkey in x_pubkeys:
if is_extended_pubkey(x_pubkey):
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
if xpub in self.xpub_path:
xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
txinputtype.address_n.extend(xpub_n + s)
break
prev_hash = unhexlify(txin['prevout_hash'])
prev_index = txin['prevout_n']
txinputtype.prev_hash = prev_hash
txinputtype.prev_index = prev_index
if 'scriptSig' in txin:
script_sig = txin['scriptSig'].decode('hex')
txinputtype.script_sig = script_sig
if 'sequence' in txin:
sequence = txin['sequence']
txinputtype.sequence = sequence
inputs.append(txinputtype)
return inputs
示例2: tx_inputs
def tx_inputs(self, tx, for_sig=False):
inputs = []
for txin in tx.inputs:
txinputtype = types.TxInputType()
if txin.get("is_coinbase"):
prev_hash = "\0" * 32
prev_index = 0xFFFFFFFF # signed int -1
else:
if for_sig:
x_pubkeys = txin["x_pubkeys"]
if len(x_pubkeys) == 1:
x_pubkey = x_pubkeys[0]
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
txinputtype.address_n.extend(xpub_n + s)
else:
def f(x_pubkey):
if is_extended_pubkey(x_pubkey):
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
else:
xpub = xpub_from_pubkey(x_pubkey.decode("hex"))
s = []
node = ckd_public.deserialize(xpub)
return types.HDNodePathType(node=node, address_n=s)
pubkeys = map(f, x_pubkeys)
multisig = types.MultisigRedeemScriptType(
pubkeys=pubkeys,
signatures=map(lambda x: x.decode("hex") if x else "", txin.get("signatures")),
m=txin.get("num_sig"),
)
txinputtype = types.TxInputType(script_type=types.SPENDMULTISIG, multisig=multisig)
# find which key is mine
for x_pubkey in x_pubkeys:
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
if xpub in self.xpub_path:
xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
txinputtype.address_n.extend(xpub_n + s)
break
else:
raise
prev_hash = unhexlify(txin["prevout_hash"])
prev_index = txin["prevout_n"]
txinputtype.prev_hash = prev_hash
txinputtype.prev_index = prev_index
if "scriptSig" in txin:
script_sig = txin["scriptSig"].decode("hex")
txinputtype.script_sig = script_sig
if "sequence" in txin:
sequence = txin["sequence"]
txinputtype.sequence = sequence
inputs.append(txinputtype)
return inputs
示例3: tx_inputs
def tx_inputs(self, tx, for_sig=False):
inputs = []
for txinput in tx.inputs:
txinputtype = types.TxInputType()
if ('is_coinbase' in txinput and txinput['is_coinbase']):
prev_hash = "\0"*32
prev_index = 0xffffffff # signed int -1
else:
if for_sig:
x_pubkey = txinput['x_pubkeys'][0]
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
txinputtype.address_n.extend(xpub_n + s)
prev_hash = unhexlify(txinput['prevout_hash'])
prev_index = txinput['prevout_n']
txinputtype.prev_hash = prev_hash
txinputtype.prev_index = prev_index
if 'scriptSig' in txinput:
script_sig = txinput['scriptSig'].decode('hex')
txinputtype.script_sig = script_sig
if 'sequence' in txinput:
sequence = txinput['sequence']
txinputtype.sequence = sequence
inputs.append(txinputtype)
#TODO P2SH
return inputs
示例4: f
def f(x_pubkey):
if is_extended_pubkey(x_pubkey):
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
else:
xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
s = []
node = ckd_public.deserialize(xpub)
return types.HDNodePathType(node=node, address_n=s)
示例5: need_server
def need_server(wallet, tx):
from electrum.account import BIP32_Account
# Detect if the server is needed
long_id, short_id = wallet.get_user_id()
xpub3 = wallet.master_public_keys['x3/']
for x in tx.inputs_to_sign():
if x[0:2] == 'ff':
xpub, sequence = BIP32_Account.parse_xpubkey(x)
if xpub == xpub3:
return True
return False
示例6: sign_transaction
def sign_transaction(self, tx, password):
if tx.is_complete():
return
if not self.check_proper_device():
give_error('Wrong device or password')
# previous transactions used as inputs
prev_tx = {}
# path of the xpubs that are involved
xpub_path = {}
for txin in tx.inputs:
tx_hash = txin['prevout_hash']
prev_tx[tx_hash] = self.transactions[tx_hash]
address = txin['address']
address_path = self.address_id(address)
account_id, (change, address_index) = self.get_address_index(address)
for x_pubkey in txin['x_pubkeys']:
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
xpub_path[xpub] = "44'/0'/%s'"%account_id
self.plugin.sign_transaction(tx, prev_tx, xpub_path)
示例7: can_sign_xpubkey
def can_sign_xpubkey(self, x_pubkey):
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
return xpub in self.master_public_keys.values()
示例8: f
def f(x_pubkey):
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
node = ckd_public.deserialize(xpub)
return types.HDNodePathType(node=node, address_n=s)