sign tx with empty scriptSig inputs
This commit is contained in:
parent
5f413aca1c
commit
6b87256795
|
@ -706,6 +706,13 @@ class Transaction:
|
||||||
s, r = self.signature_count()
|
s, r = self.signature_count()
|
||||||
return r == s
|
return r == s
|
||||||
|
|
||||||
|
def inputs_without_script(self):
|
||||||
|
out = set()
|
||||||
|
for i, txin in enumerate(self.inputs):
|
||||||
|
if txin.get('scriptSig') == '':
|
||||||
|
out.add(i)
|
||||||
|
return out
|
||||||
|
|
||||||
def inputs_to_sign(self):
|
def inputs_to_sign(self):
|
||||||
out = set()
|
out = set()
|
||||||
for txin in self.inputs:
|
for txin in self.inputs:
|
||||||
|
|
|
@ -993,14 +993,20 @@ class Abstract_Wallet(object):
|
||||||
def sign_transaction(self, tx, password):
|
def sign_transaction(self, tx, password):
|
||||||
if self.is_watching_only():
|
if self.is_watching_only():
|
||||||
return
|
return
|
||||||
# check that the password is correct. This will raise if it's not.
|
# Raise if password is not correct.
|
||||||
self.check_password(password)
|
self.check_password(password)
|
||||||
|
# Add derivation for utxo in wallets
|
||||||
|
for i, addr in self.utxo_can_sign(tx):
|
||||||
|
txin = tx.inputs[i]
|
||||||
|
txin['address'] = addr
|
||||||
|
self.add_input_info(txin)
|
||||||
|
# Add private keys
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
x_pubkeys = tx.inputs_to_sign()
|
for x in self.xkeys_can_sign(tx):
|
||||||
for x in x_pubkeys:
|
|
||||||
sec = self.get_private_key_from_xpubkey(x, password)
|
sec = self.get_private_key_from_xpubkey(x, password)
|
||||||
if sec:
|
if sec:
|
||||||
keypairs[ x ] = sec
|
keypairs[x] = sec
|
||||||
|
# Sign
|
||||||
if keypairs:
|
if keypairs:
|
||||||
tx.sign(keypairs)
|
tx.sign(keypairs)
|
||||||
run_hook('sign_transaction', tx, password)
|
run_hook('sign_transaction', tx, password)
|
||||||
|
@ -1151,11 +1157,28 @@ class Abstract_Wallet(object):
|
||||||
return False
|
return False
|
||||||
if tx.is_complete():
|
if tx.is_complete():
|
||||||
return False
|
return False
|
||||||
for x in tx.inputs_to_sign():
|
if self.xkeys_can_sign(tx):
|
||||||
if self.can_sign_xpubkey(x):
|
return True
|
||||||
return True
|
if self.utxo_can_sign(tx):
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def utxo_can_sign(self, tx):
|
||||||
|
out = set()
|
||||||
|
coins = self.get_spendable_coins()
|
||||||
|
for i in tx.inputs_without_script():
|
||||||
|
txin = tx.inputs[i]
|
||||||
|
for item in coins:
|
||||||
|
if txin.get('prevout_hash') == item.get('prevout_hash') and txin.get('prevout_n') == item.get('prevout_n'):
|
||||||
|
out.add((i, item.get('address')))
|
||||||
|
return out
|
||||||
|
|
||||||
|
def xkeys_can_sign(self, tx):
|
||||||
|
out = set()
|
||||||
|
for x in tx.inputs_to_sign():
|
||||||
|
if self.can_sign_xpubkey(x):
|
||||||
|
out.add(x)
|
||||||
|
return out
|
||||||
|
|
||||||
def get_private_key_from_xpubkey(self, x_pubkey, password):
|
def get_private_key_from_xpubkey(self, x_pubkey, password):
|
||||||
if x_pubkey[0:2] in ['02','03','04']:
|
if x_pubkey[0:2] in ['02','03','04']:
|
||||||
|
|
Loading…
Reference in New Issue