1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-22 08:08:11 +00:00

long() and print() for Python 3

This commit is contained in:
cclauss 2017-08-24 18:44:48 +02:00 committed by GitHub
parent 35fef9a94f
commit df302e9fe5

View File

@ -2,8 +2,13 @@
from sys import argv from sys import argv
class OutputInfo: try:
long # Python 2
except NameError:
long = int # Python 3
class OutputInfo:
def __init__(self, tx_hash, tx_index, value): def __init__(self, tx_hash, tx_index, value):
self.tx_hash = tx_hash self.tx_hash = tx_hash
self.tx_index = tx_index self.tx_index = tx_index
@ -13,6 +18,7 @@ class OutputInfo:
return "<%s:%s with %s Satoshis>" % (self.tx_hash, self.tx_index, return "<%s:%s with %s Satoshis>" % (self.tx_hash, self.tx_index,
self.value) self.value)
# Select optimal outputs for a send from unspent outputs list. # Select optimal outputs for a send from unspent outputs list.
# Returns output list and remaining change to be sent to # Returns output list and remaining change to be sent to
# a change address. # a change address.
@ -44,6 +50,7 @@ def select_outputs_greedy(unspent, min_value):
# No results found. # No results found.
return None, 0 return None, 0
def main(): def main():
unspent = [ unspent = [
OutputInfo("ebadfaa92f1fd29e2fe296eda702c48bd11ffd52313e986e99ddad9084062167", 1, 8000000), OutputInfo("ebadfaa92f1fd29e2fe296eda702c48bd11ffd52313e986e99ddad9084062167", 1, 8000000),
@ -54,15 +61,11 @@ def main():
OutputInfo("12b6a7934c1df821945ee9ee3b3326d07ca7a65fd6416ea44ce8c3db0c078c64", 0, 10000000), OutputInfo("12b6a7934c1df821945ee9ee3b3326d07ca7a65fd6416ea44ce8c3db0c078c64", 0, 10000000),
OutputInfo("7f42eda67921ee92eae5f79bd37c68c9cb859b899ce70dba68c48338857b7818", 0, 16100000), OutputInfo("7f42eda67921ee92eae5f79bd37c68c9cb859b899ce70dba68c48338857b7818", 0, 16100000),
] ]
target = long(argv[1]) if len(argv) > 1 else 55000000
if len(argv) > 1: print("For transaction amount %d Satoshis (%f bitcoin) use: " %
target = long(argv[1]) (target, target / 10.0 ** 8))
else: print(select_outputs_greedy(unspent, target))
target = 55000000
print "For transaction amount %d Satoshis (%f bitcoin) use: " % (target, target/10.0**8)
print select_outputs_greedy(unspent, target)
if __name__ == "__main__": if __name__ == "__main__":
main() main()