Created
May 21, 2015 16:09
-
-
Save dexX7/519ec29bd7e5d50a0be5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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