Browse Source

remove magic 'deadbeef' identifier from taker.py

master
undeath 5 years ago
parent
commit
a340f06534
No known key found for this signature in database
GPG Key ID: F0DF5443BD2F3520
  1. 24
      jmclient/jmclient/taker.py

24
jmclient/jmclient/taker.py

@ -548,12 +548,6 @@ class Taker(object):
jlog.info('obtained tx\n' + btc.human_readable_transaction( jlog.info('obtained tx\n' + btc.human_readable_transaction(
self.latest_tx)) self.latest_tx))
for index, ins in enumerate(self.latest_tx.vin):
utxo = (ins.prevout.hash[::-1], ins.prevout.n)
if utxo not in self.input_utxos.keys():
continue
# placeholders required
ins.scriptSig = btc.CScript.fromhex("deadbeef")
self.taker_info_callback("INFO", "Built tx, sending to counterparties.") self.taker_info_callback("INFO", "Built tx, sending to counterparties.")
return (True, list(self.maker_utxo_data.keys()), return (True, list(self.maker_utxo_data.keys()),
bintohex(self.latest_tx.serialize())) bintohex(self.latest_tx.serialize()))
@ -595,10 +589,9 @@ class Taker(object):
utxo = {} utxo = {}
ctr = 0 ctr = 0
for index, ins in enumerate(self.latest_tx.vin): for index, ins in enumerate(self.latest_tx.vin):
utxo_for_checking = (ins.prevout.hash[::-1], ins.prevout.n) if self._is_our_input(ins) or ins.scriptSig != b"":
# 'deadbeef' markers mean our own input scripts are not queried
if ins.scriptSig != b"":
continue continue
utxo_for_checking = (ins.prevout.hash[::-1], ins.prevout.n)
utxo[ctr] = [index, utxo_for_checking] utxo[ctr] = [index, utxo_for_checking]
ctr += 1 ctr += 1
utxo_data = jm_single().bc_interface.query_utxo_set([x[ utxo_data = jm_single().bc_interface.query_utxo_set([x[
@ -689,8 +682,9 @@ class Taker(object):
# other guy sent a failed signature # other guy sent a failed signature
tx_signed = True tx_signed = True
for input, witness in zip(self.latest_tx.vin, self.latest_tx.wit.vtxinwit): for ins, witness in zip(self.latest_tx.vin, self.latest_tx.wit.vtxinwit):
if input.scriptSig == b"" \ if ins.scriptSig == b"" \
and not self._is_our_input(ins) \
and witness == btc.CTxInWitness(btc.CScriptWitness([])): and witness == btc.CTxInWitness(btc.CScriptWitness([])):
tx_signed = False tx_signed = False
if not tx_signed: if not tx_signed:
@ -814,9 +808,9 @@ class Taker(object):
# now sign it ourselves # now sign it ourselves
our_inputs = {} our_inputs = {}
for index, ins in enumerate(self.latest_tx.vin): for index, ins in enumerate(self.latest_tx.vin):
utxo = (ins.prevout.hash[::-1], ins.prevout.n) if not self._is_our_input(ins):
if utxo not in self.input_utxos.keys():
continue continue
utxo = (ins.prevout.hash[::-1], ins.prevout.n)
self.latest_tx.vin[index].scriptSig = btc.CScript(b'') self.latest_tx.vin[index].scriptSig = btc.CScript(b'')
script = self.input_utxos[utxo]['script'] script = self.input_utxos[utxo]['script']
amount = self.input_utxos[utxo]['value'] amount = self.input_utxos[utxo]['value']
@ -946,6 +940,10 @@ class Taker(object):
txdetails=(txd, txid)) txdetails=(txd, txid))
return True return True
def _is_our_input(self, tx_input):
utxo = (tx_input.prevout.hash[::-1], tx_input.prevout.n)
return utxo in self.input_utxos
def round_to_significant_figures(d, sf): def round_to_significant_figures(d, sf):
'''Rounding number d to sf significant figures in base 10''' '''Rounding number d to sf significant figures in base 10'''
for p in range(-10, 15): for p in range(-10, 15):

Loading…
Cancel
Save