Skip to content

Instantly share code, notes, and snippets.

@dexX7
Created May 21, 2015 16:09
Show Gist options
  • Select an option

  • Save dexX7/519ec29bd7e5d50a0be5 to your computer and use it in GitHub Desktop.

Select an option

Save dexX7/519ec29bd7e5d50a0be5 to your computer and use it in GitHub Desktop.
from random import shuffle
def is_accepted_output(output):
"""Determine, if the output qualifies as input for an Omni transaction.
Any input with a type other than "pay-to-pubkey-hash" and "pay-to-script-hash"
invalidates an Omni transaction."""
return output['type'] == 'pubkeyhash' or output['type'] == 'scripthash'
def select_outputs(unspent_outputs, target_amount, sender):
"""Select outputs to be used as input for an Omni transaction."""
selected_amount = 0
selected_outputs = []
unspent_outputs = shuffle(unspent_outputs)
for output in unspent_outputs:
if not is_accepted_output(output):
continue
if sender not in output['addresses']:
continue
selected_amount += output['amount']
selected_outputs.append(output)
if selected_amount >= target_amount:
break
# It should then be checked by the caller (...), if the available, selected
# amount is actually sufficient
return selected_amount, unspent_outputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment