def make_op_return_tx(data, private_key, blockchain_client=BlockchainInfoClient(), fee=OP_RETURN_FEE, change_address=None, format='bin'): """ Builds and signs an OP_RETURN transaction. """ # get out the private key object, sending address, and inputs private_key_obj, from_address, inputs = analyze_private_key( private_key, blockchain_client) # get the change address if not change_address: change_address = from_address # create the outputs outputs = make_op_return_outputs(data, inputs, change_address, fee=fee, format=format) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, private_key_obj.to_hex()) # return the signed tx return signed_tx
def make_send_to_address_tx(recipient_address, amount, private_key, blockchain_client=BlockchainInfoClient(), fee=STANDARD_FEE, change_address=None): """ Builds and signs a "send to address" transaction. """ # get out the private key object, sending address, and inputs private_key_obj, from_address, inputs = analyze_private_key( private_key, blockchain_client) # get the change address if not change_address: change_address = from_address # create the outputs outputs = make_pay_to_address_outputs(recipient_address, amount, inputs, change_address, fee=fee) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, private_key_obj.to_hex()) # return the signed tx return signed_tx
def serialize_sign_and_broadcast(inputs, outputs, private_key, blockchain_client=BlockchainInfoClient()): # extract the private key object private_key_obj = get_private_key_obj(private_key) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, private_key_obj.to_hex()) # dispatch the signed transction to the network response = broadcast_transaction(signed_tx, blockchain_client) # return the response return response
def serialize_sign_and_broadcast(inputs, outputs, private_key, blockchain_client=BlockchainInfoClient()): # extract the private key object private_key_obj = get_private_key_obj(private_key) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # generate a scriptSig for each input for i in xrange(0, len(inputs)): signed_tx = sign_transaction( unsigned_tx, i, private_key_obj.to_hex() ) unsigned_tx = signed_tx # dispatch the signed transction to the network response = broadcast_transaction(signed_tx, blockchain_client) # return the response return response
def serialize_sign_and_broadcast(inputs, outputs, private_key, blockchain_client=BlockchainInfoClient()): # extract the private key object private_key_obj = get_private_key_obj(private_key) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # generate a scriptSig for each input for i in xrange(0, len(inputs)): signed_tx = sign_transaction(unsigned_tx, i, private_key_obj.to_hex()) unsigned_tx = signed_tx # dispatch the signed transction to the network response = broadcast_transaction(signed_tx, blockchain_client) # return the response return response
def make_op_return_tx(data, private_key, blockchain_client=BlockchainInfoClient(), fee=OP_RETURN_FEE, change_address=None, format='bin'): """ Builds and signs an OP_RETURN transaction. """ # get out the private key object, sending address, and inputs private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) # get the change address if not change_address: change_address = from_address # create the outputs outputs = make_op_return_outputs(data, inputs, change_address, fee=fee, format=format) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, private_key_obj.to_hex()) # return the signed tx return signed_tx
def make_send_to_address_tx(recipient_address, amount, private_key, blockchain_client=BlockchainInfoClient(), fee=STANDARD_FEE, change_address=None): """ Builds and signs a "send to address" transaction. """ # get out the private key object, sending address, and inputs private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) # get the change address if not change_address: change_address = from_address # create the outputs outputs = make_pay_to_address_outputs(recipient_address, amount, inputs, change_address, fee=fee) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, private_key_obj.to_hex()) # return the signed tx return signed_tx
def send_to_address(to_address, amount, sender_private_key, auth, api='chain.com'): """ Builds a transaction, signs it, and dispatches it to the network. Auth object is a 2-item tuple. """ # determine the address associated with the supplied private key from_address = BitcoinPrivateKey(sender_private_key).public_key().address() # get the unspent outputs corresponding to the given address inputs = get_unspents(from_address) # create an unsigned transaction from the inputs, to address, & amount unsigned_hex_transaction = make_send_to_address_transaction(inputs, from_address, to_address, amount) # signs the unsigned transaction with the private key signed_hex_transaction = sign_transaction(unsigned_hex_transaction, 0, sender_private_key) # dispatch the signed transction to the network response = broadcast_transaction(signed_hex_transaction, api=api, auth=auth) # return the response return response
def embed_data_in_blockchain(data, sender_private_key, auth, api='chain.com', fee=STANDARD_FEE, change_address=None, format='bin'): """ Builds, signs, and dispatches an OP_RETURN transaction. """ if not isinstance(sender_private_key, BitcoinPrivateKey): sender_private_key = BitcoinPrivateKey(sender_private_key) # determine the address associated with the supplied private key from_address = sender_private_key.public_key().address() # get the unspent outputs corresponding to the given address inputs = get_unspents(from_address, api=api, auth=auth) # get the change address if not change_address: change_address = from_address # create the outputs outputs = make_op_return_outputs(data, inputs, change_address, format=format) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, sender_private_key.to_hex()) # dispatch the signed transction to the network response = broadcast_transaction(signed_tx, api=api, auth=auth) # return the response return response
def send_to_address(recipient_address, amount, sender_private_key, auth, api='chain.com', fee=STANDARD_FEE, change_address=None): """ Builds, signs, and dispatches a "send to address" transaction. """ if not isinstance(sender_private_key, BitcoinPrivateKey): sender_private_key = BitcoinPrivateKey(sender_private_key) # determine the address associated with the supplied private key from_address = sender_private_key.public_key().address() # get the unspent outputs corresponding to the given address inputs = get_unspents(from_address, api=api, auth=auth) # get the change address if not change_address: change_address = from_address # create the outputs outputs = make_pay_to_address_outputs(recipient_address, amount, inputs, change_address, fee) # serialize the transaction unsigned_tx = serialize_transaction(inputs, outputs) # sign the unsigned transaction with the private key signed_tx = sign_transaction(unsigned_tx, 0, sender_private_key.to_hex()) # dispatch the signed transction to the network response = broadcast_transaction(signed_tx, api=api, auth=auth) # return the response return response