def main(): # We need a wallet, but don't need a network. Set peer_goal to 0 spv = pyspv.pyspv('pyspv-simple-wallet', logging_level=pyspv.INFO, peer_goal=0, listen=None) tx, _ = pyspv.transaction.Transaction.unserialize( pyspv.hexstring_to_bytes(sys.argv[1], reverse=False), spv.coin) input_count = len(tx.inputs) total_added = 0 for spend_hash in sys.argv[2:]: spend_hash = pyspv.hexstring_to_bytes(spend_hash) spend = spv.wallet.spends[spend_hash]['spend'] for input_creator in spend.create_input_creators( spv, pyspv.transaction.Transaction.SIGHASH_ALL | pyspv.transaction.Transaction.SIGHASH_ANYONECANPAY): tx.inputs.append( pyspv.transaction.UnsignedTransactionInput(input_creator)) total_added += spend.amount for i, unsigned_input in enumerate(tx.inputs): if isinstance(unsigned_input, pyspv.transaction.UnsignedTransactionInput): tx.inputs[i] = unsigned_input.sign(tx, i) print(pyspv.bytes_to_hexstring(tx.serialize(), reverse=False)) print("total added as inputs: {}".format( spv.coin.format_money(total_added))) spv.shutdown() # Async shutdown spv.join() # Wait for shutdown to complete
def main(): # We need a wallet, but don't need a network. Set peer_goal to 0 spv = pyspv.pyspv('pyspv-simple-wallet', logging_level=pyspv.INFO, peer_goal=0, listen=None) tx, _ = pyspv.transaction.Transaction.unserialize(pyspv.hexstring_to_bytes(sys.argv[1], reverse=False), spv.coin) input_count = len(tx.inputs) total_added = 0 for spend_hash in sys.argv[2:]: spend_hash = pyspv.hexstring_to_bytes(spend_hash) spend = spv.wallet.spends[spend_hash]['spend'] for input_creator in spend.create_input_creators(spv, pyspv.transaction.Transaction.SIGHASH_ALL | pyspv.transaction.Transaction.SIGHASH_ANYONECANPAY): tx.inputs.append(pyspv.transaction.UnsignedTransactionInput(input_creator)) total_added += spend.amount for i, unsigned_input in enumerate(tx.inputs): if isinstance(unsigned_input, pyspv.transaction.UnsignedTransactionInput): tx.inputs[i] = unsigned_input.sign(tx, i) print(pyspv.bytes_to_hexstring(tx.serialize(), reverse=False)) print("total added as inputs: {}".format(spv.coin.format_money(total_added))) spv.shutdown() # Async shutdown spv.join() # Wait for shutdown to complete
def server_main(): global spv logging_level = pyspv.WARNING if '-v' in sys.argv: logging_level = pyspv.INFO if '-vv' in sys.argv or '-vvv' in sys.argv: logging_level = pyspv.DEBUG spv = pyspv.pyspv('pyspv-simple-wallet', logging_level=logging_level, peer_goal=4, testnet=True, listen=('0.0.0.0', 8336)) #relay_tx=False, rpc_server = SimpleXMLRPCServer((RPC_LISTEN_ADDRESS, RPC_LISTEN_PORT), allow_none=True) rpc_server.register_function(getnewaddress) rpc_server.register_function(getnewstealthaddress) rpc_server.register_function(getnewpubkey) rpc_server.register_function(getbalance) rpc_server.register_function(sendtoaddress) rpc_server.register_function(sendspendtoaddress) rpc_server.register_function(getinfo) rpc_server.register_function(listspends) rpc_server.register_function(dumppubkey) rpc_server.register_function(dumpprivkey) rpc_server.register_function(genmultisig) rpc_server.register_function(sendrawtransaction) try: rpc_server.serve_forever() except KeyboardInterrupt: pass spv.shutdown() # Async shutdown spv.join() # Wait for shutdown to complete
def main(): simple_wallet = __import__('simple-wallet') # We need a wallet, but don't need a network. Set peer_goal to 0 spv = pyspv.pyspv('pyspv-simple-wallet', logging_level=pyspv.INFO, peer_goal=0, listen=None) tx = pyspv.transaction.Transaction(spv.coin) total_output = 0 for i in range(1, len(sys.argv), 2): address = sys.argv[i] amount = sys.argv[i+1] output_producer = simple_wallet.get_output_producer(spv, address, spv.coin.parse_money(amount)) for output in output_producer.create_outputs(spv): tx.outputs.append(output) total_output += output.amount print(pyspv.bytes_to_hexstring(tx.serialize(), reverse=False)) print("total transaction output: {}".format(spv.coin.format_money(total_output))) spv.shutdown() # Async shutdown spv.join() # Wait for shutdown to complete