def broadcast(namespace_id, private_key, blockchain_client, testset=False, tx_only=False, blockchain_broadcaster=None): if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client nulldata = build(namespace_id, testset=testset) # get inputs and from address private_key_obj, from_address, inputs = analyze_private_key( private_key, blockchain_client) # OP_RETURN outputs outputs = make_op_return_outputs(nulldata, inputs, from_address, fee=DEFAULT_OP_RETURN_FEE, format='hex') if tx_only: unsigned_tx = serialize_transaction(inputs, outputs) return {'unsigned_tx': signed_tx} else: signed_tx = tx_serialize_and_sign(inputs, outputs, private_key_obj) response = broadcast_transaction(signed_tx, blockchain_broadcaster) response.update({'data': nulldata}) return response
def broadcast(name, data_hash, consensus_hash, private_key, blockchain_client, blockchain_broadcaster=None, pay_fee=True, tx_only=False, public_key=None, testset=False): """ Write a name update into the blockchain. Returns a JSON object with 'data' set to the nulldata and 'transaction_hash' set to the transaction hash on success. """ # sanity check if public_key is None and private_key is None: raise Exception("Missing both public and private key") if not tx_only and private_key is None: raise Exception("Need private key for broadcasting") if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client from_address = None inputs = None private_key_obj = None if private_key is not None: # ordering directly pubk = BitcoinPrivateKey( private_key ).public_key() public_key = pubk.to_hex() # get inputs and from address using private key private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) elif public_key is not None: # subsidizing pubk = BitcoinPublicKey( public_key ) from_address = pubk.address() # get inputs from utxo provider inputs = get_unspents( from_address, blockchain_client ) nulldata = build(name, consensus_hash, data_hash=data_hash, testset=testset) outputs = make_op_return_outputs( nulldata, inputs, from_address, fee=DEFAULT_OP_RETURN_FEE, format='hex' ) if tx_only: unsigned_tx = serialize_transaction( inputs, outputs ) return {'unsigned_tx': unsigned_tx} else: signed_tx = tx_serialize_and_sign( inputs, outputs, private_key_obj ) response = broadcast_transaction( signed_tx, blockchain_broadcaster, format='hex') response.update({'data': nulldata}) return response
def broadcast(name, private_key, blockchain_client, testset=False, blockchain_broadcaster=None, pay_fee=True, public_key=None, tx_only=False): # sanity check if public_key is None and private_key is None: raise Exception("Missing both public and private key") if not tx_only and private_key is None: raise Exception("Need private key for broadcasting") if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client from_address = None inputs = None private_key_obj = None if private_key is not None: # ordering directly pubk = BitcoinPrivateKey( private_key ).public_key() public_key = pubk.to_hex() # get inputs and from address using private key private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) elif public_key is not None: # subsidizing pubk = BitcoinPublicKey( public_key ) from_address = pubk.address() # get inputs from utxo provider inputs = get_unspents( from_address, blockchain_client ) nulldata = build(name, testset=testset) outputs = make_op_return_outputs( nulldata, inputs, from_address, fee=DEFAULT_OP_RETURN_FEE, format='hex' ) if tx_only: unsigned_tx = serialize_transaction( inputs, outputs ) return {'unsigned_tx': unsigned_tx} else: signed_tx = tx_serialize_and_sign( inputs, outputs, private_key_obj ) response = broadcast_transaction( signed_tx, blockchain_broadcaster, format='hex') response.update({'data': nulldata}) return response
def make_transaction( namespace_id, payment_addr, blockchain_client, tx_fee=0 ): """ Make the namespace ready transaction Raise ValueError if there are not enough inputs to make the transaction """ namespace_id = str(namespace_id) payment_addr = str(payment_addr) tx_fee = int(tx_fee) assert is_namespace_valid( namespace_id ) nulldata = build( namespace_id ) # get inputs and from public key inputs = get_unspents( payment_addr, blockchain_client ) # OP_RETURN outputs outputs = make_op_return_outputs( nulldata, inputs, payment_addr, fee=(DEFAULT_OP_RETURN_FEE + tx_fee), format='hex' ) return (inputs, outputs)
def broadcast( namespace_id, private_key, blockchain_client, testset=False, tx_only=False, blockchain_broadcaster=None ): if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client nulldata = build( namespace_id, testset=testset ) # get inputs and from address private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) # OP_RETURN outputs outputs = make_op_return_outputs( nulldata, inputs, from_address, fee=DEFAULT_OP_RETURN_FEE, format='hex' ) if tx_only: unsigned_tx = serialize_transaction( inputs, outputs ) return {'unsigned_tx': signed_tx} else: signed_tx = tx_serialize_and_sign( inputs, outputs, private_key_obj ) response = broadcast_transaction( signed_tx, blockchain_broadcaster ) response.update({'data': nulldata}) return response