Skip to content

Commit

Permalink
Enforce all inputs to a shuffle must be confirmed UTXOs
Browse files Browse the repository at this point in the history
- Also refactored the check_inputs code to be a little faster to execute
  • Loading branch information
cculianu committed Feb 13, 2019
1 parent 9ffad2c commit f488e15
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions plugins/shuffle/coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,26 @@ def check_inputs_for_sufficient_funds(self, inputs, amount):
it does as follows:
1. check utxo list for every pubkey in the dict
2. check if utxo from inputs are in the utxo list on blockchain for this pubkeys
2.a return None if there is a utxo from list not on utxo set from blockchain
2. check if utxo from inputs are in the utxo list on blockchain for these pubkeys
2.a return None if there is a utxo from list not in utxo set from blockchain
2.b return None if utxo in list is not confirmed
3. return True if summary values of utxos are greater then amount and False otherwise
"""
def _utxo_name(x): return x['tx_hash'] + ":" + str(x['tx_pos'])
total = 0
try:
for public_key in inputs:
for public_key, pk_inputs in inputs.items():
address = address_from_public_key(public_key)
unspent_list = self.getaddressunspent(address)
utxos = {(utxo['tx_hash']+ ":" + str(utxo['tx_pos'])):utxo['value'] for utxo in unspent_list}
for utxo in inputs[public_key]:
if utxo in utxos:
total += utxos[utxo]
else:
utxos = {
_utxo_name(utxo) : utxo['value']
for utxo in unspent_list if utxo.get('height',-1) > 0 # all inputs must have at least 1 confirmation
}
for utxo in pk_inputs:
val = utxos.get(utxo)
if val is None:
return None
total += val
return total >= amount
except:
return None
Expand Down

0 comments on commit f488e15

Please sign in to comment.