fix is_address (forgot p2sh)
This commit is contained in:
parent
c0858f314f
commit
0c37009cdb
|
@ -358,7 +358,7 @@ def is_address(addr):
|
||||||
addrtype, h = bc_address_to_hash_160(addr)
|
addrtype, h = bc_address_to_hash_160(addr)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
if addrtype != 0:
|
if addrtype not in [0, 5]:
|
||||||
return False
|
return False
|
||||||
return addr == hash_160_to_bc_address(h, addrtype)
|
return addr == hash_160_to_bc_address(h, addrtype)
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ class Abstract_Wallet(object):
|
||||||
for tx_hash, raw in tx_list.items():
|
for tx_hash, raw in tx_list.items():
|
||||||
tx = Transaction(raw)
|
tx = Transaction(raw)
|
||||||
self.transactions[tx_hash] = tx
|
self.transactions[tx_hash] = tx
|
||||||
if self.txi.get(tx_hash) is None and self.txo.get(tx_hash) is None:
|
if self.txi.get(tx_hash) is None and self.txo.get(tx_hash) is None and (tx_hash not in self.pruned_txo.values()):
|
||||||
print_error("removing unreferenced tx", tx_hash)
|
print_error("removing unreferenced tx", tx_hash)
|
||||||
self.transactions.pop(tx_hash)
|
self.transactions.pop(tx_hash)
|
||||||
|
|
||||||
|
@ -748,6 +748,14 @@ class Abstract_Wallet(object):
|
||||||
if (tx_hash, height) not in hist:
|
if (tx_hash, height) not in hist:
|
||||||
self.remove_transaction(tx_hash, height)
|
self.remove_transaction(tx_hash, height)
|
||||||
|
|
||||||
|
# fix: maybe remove only at the end, tx that have only unspent outputs
|
||||||
|
# bug: if tx is used by many addresses, not clear what we should do..
|
||||||
|
# we should remove tx iff it is completely unreferenced
|
||||||
|
|
||||||
|
# note about balance bug: on fist sync, it downloaded a lot of new tx, and I had a wrong balance.
|
||||||
|
# after one reconnection it was fixed. (probably after changing server, going from pruned to long)
|
||||||
|
# this could be related to the 'download missing tx' behaviour, that kicks in on startup
|
||||||
|
|
||||||
self.history[addr] = hist
|
self.history[addr] = hist
|
||||||
self.storage.put('addr_history', self.history, True)
|
self.storage.put('addr_history', self.history, True)
|
||||||
|
|
||||||
|
|
|
@ -221,25 +221,26 @@ class Plugin(BasePlugin):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def sign_transaction(self, tx):
|
def sign_transaction(self, tx, prev_tx, xpub_path):
|
||||||
if tx.is_complete():
|
self.prev_tx = prev_tx
|
||||||
return
|
self.xpub_path = xpub_path
|
||||||
client = self.get_client()
|
client = self.get_client()
|
||||||
inputs = self.tx_inputs(tx)
|
inputs = self.tx_inputs(tx, True)
|
||||||
outputs = self.tx_outputs(tx)
|
outputs = self.tx_outputs(tx)
|
||||||
try:
|
#try:
|
||||||
signed_tx = client.sign_tx('Bitcoin', inputs, outputs)[1]
|
signed_tx = client.sign_tx('Bitcoin', inputs, outputs)[1]
|
||||||
except Exception, e:
|
#except Exception, e:
|
||||||
give_error(e)
|
# give_error(e)
|
||||||
finally:
|
#finally:
|
||||||
self.handler.stop()
|
self.handler.stop()
|
||||||
|
|
||||||
#values = [i['value'] for i in tx.inputs]
|
#values = [i['value'] for i in tx.inputs]
|
||||||
raw = signed_tx.encode('hex')
|
raw = signed_tx.encode('hex')
|
||||||
tx.update(raw)
|
tx.update(raw)
|
||||||
#for i, txinput in enumerate(tx.inputs):
|
#for i, txinput in enumerate(tx.inputs):
|
||||||
# txinput['value'] = values[i]
|
# txinput['value'] = values[i]
|
||||||
|
|
||||||
def tx_inputs(self, tx):
|
def tx_inputs(self, tx, for_sig=False):
|
||||||
inputs = []
|
inputs = []
|
||||||
for txinput in tx.inputs:
|
for txinput in tx.inputs:
|
||||||
txinputtype = types.TxInputType()
|
txinputtype = types.TxInputType()
|
||||||
|
@ -247,12 +248,12 @@ class Plugin(BasePlugin):
|
||||||
prev_hash = "\0"*32
|
prev_hash = "\0"*32
|
||||||
prev_index = 0xffffffff # signed int -1
|
prev_index = 0xffffffff # signed int -1
|
||||||
else:
|
else:
|
||||||
address = txinput['address']
|
|
||||||
try:
|
if for_sig:
|
||||||
address_path = self.wallet.address_id(address)
|
x_pubkey = txinput['x_pubkeys'][0]
|
||||||
address_n = self.get_client().expand_path(address_path)
|
xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
|
||||||
txinputtype.address_n.extend(address_n)
|
xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
|
||||||
except: pass
|
txinputtype.address_n.extend(xpub_n + s)
|
||||||
|
|
||||||
prev_hash = unhexlify(txinput['prevout_hash'])
|
prev_hash = unhexlify(txinput['prevout_hash'])
|
||||||
prev_index = txinput['prevout_n']
|
prev_index = txinput['prevout_n']
|
||||||
|
@ -310,7 +311,7 @@ class Plugin(BasePlugin):
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def get_tx(self, tx_hash):
|
def get_tx(self, tx_hash):
|
||||||
tx = self.wallet.transactions[tx_hash]
|
tx = self.prev_tx[tx_hash]
|
||||||
tx.deserialize()
|
tx.deserialize()
|
||||||
return self.electrum_tx_to_txtype(tx)
|
return self.electrum_tx_to_txtype(tx)
|
||||||
|
|
||||||
|
@ -429,9 +430,26 @@ class TrezorWallet(BIP32_HD_Wallet):
|
||||||
return str(b64_msg_sig)
|
return str(b64_msg_sig)
|
||||||
|
|
||||||
def sign_transaction(self, tx, password):
|
def sign_transaction(self, tx, password):
|
||||||
|
if tx.is_complete():
|
||||||
|
return
|
||||||
if not self.check_proper_device():
|
if not self.check_proper_device():
|
||||||
give_error('Wrong device or password')
|
give_error('Wrong device or password')
|
||||||
self.plugin.sign_transaction(tx)
|
# 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)
|
||||||
|
|
||||||
def check_proper_device(self):
|
def check_proper_device(self):
|
||||||
self.get_client().ping('t')
|
self.get_client().ping('t')
|
||||||
|
|
Loading…
Reference in New Issue