def mktx(satoshis, fee): outputs = None if satoshis is None: # send all satoshis = sum([u['value'] for u in utxos]) print 'WARN: sending all of {} ({}) to {}'.format(payment_addr, satoshis, recipient_addr) outputs = [ {'script': virtualchain.make_payment_script(payment_addr), 'value': virtualchain.calculate_change_amount(utxos, 0, fee)}, ] else: outputs = [ {"script": virtualchain.make_payment_script(payment_addr), "value": satoshis}, {"script": virtualchain.make_payment_script(recipient_addr), "value": virtualchain.calculate_change_amount(utxos, satoshis, fee)}, ] txobj = { 'ins': utxos, 'outs': outputs, 'locktime': 0, 'version': 1 } # log.debug("serialize tx: {}".format(json.dumps(txobj, indent=4, sort_keys=True))) txstr = virtualchain.btc_tx_serialize(txobj) signed_txstr = virtualchain.tx_sign_all_unsigned_inputs(privkey, utxos, txstr) return signed_txstr
def make_outputs( data, inputs, new_name_owner_address, change_address, tx_fee=0, pay_fee=True, dust_included = False): """ Builds the outputs for a name transfer operation. Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = None op_fee = None dust_value = DEFAULT_DUST_FEE if pay_fee: total_tx_fee = tx_fee if not dust_included: total_tx_fee += (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE op_fee = DEFAULT_DUST_FEE else: total_tx_fee = 0 op_fee = 0 return [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # new name owner output {"script": virtualchain.make_payment_script(new_name_owner_address), "value": dust_value}, # change output {"script": virtualchain.make_payment_script(change_address), "value": virtualchain.calculate_change_amount(inputs, op_fee, total_tx_fee)} ]
def make_outputs( data, inputs, recipient_address, sender_address, update_hash_b58, tx_fee): """ Builds the outputs for a name import: * [0] is the OP_RETURN * [1] is the new owner (recipient) * [2] is the update hash * [3] is the change sent to the original owner Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 3) * DEFAULT_DUST_FEE + tx_fee op_fee = 2 * DEFAULT_DUST_FEE dust_value = DEFAULT_DUST_FEE return [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # recipient output {"script": virtualchain.make_payment_script(recipient_address), "value": dust_value}, # update hash output {"script": virtualchain.make_payment_script(update_hash_b58), "value": dust_value}, # change output {"script": virtualchain.make_payment_script(sender_address), "value": virtualchain.calculate_change_amount(inputs, op_fee, dust_fee)} ]
def make_outputs( data, inputs, change_address, tx_fee, pay_fee=True ): """ Make outputs for a revoke. Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = None op_fee = None dust_value = None if pay_fee: dust_fee = (len(inputs) + 1) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee op_fee = DEFAULT_DUST_FEE dust_value = DEFAULT_DUST_FEE else: # will be subsidized dust_fee = 0 op_fee = 0 dust_value = 0 return [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # change output {"script": virtualchain.make_payment_script(change_address), "value": virtualchain.calculate_change_amount(inputs, op_fee, dust_fee)} ]
def mktx( amt, tx_fee, recipient_addr, privkey, message=None ): """ Make the transaction with the given fee """ change_addr = virtualchain.BitcoinPrivateKey(privkey).public_key().address() inputs = testlib.get_unspents(change_addr) change = virtualchain.calculate_change_amount(inputs, amt, tx_fee) outputs = [ {'script': virtualchain.make_payment_script(recipient_addr), 'value': amt}, ] if change > 0: # need change and tx fee outputs.append( {'script': virtualchain.make_payment_script(change_addr), "value": change} ) if message: outputs = [ {"script": virtualchain.make_data_script(binascii.hexlify(message)), "value": 0} ] + outputs serialized_tx = blockstack_client.tx.serialize_tx(inputs, outputs) signed_tx = blockstack_client.tx.sign_tx(serialized_tx, privkey) return signed_tx
def make_outputs(data, inputs, reveal_addr, change_addr, tx_fee): """ Make outputs for a register: [0] OP_RETURN with the name [1] pay-to-address with the *reveal_addr*, not the sender's address. [2] change address with the NAMESPACE_PREORDER sender's address Raise ValueError if there are not enough inputs to make the transaction """ total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE return [ # main output { "script": virtualchain.make_data_script(str(data)), "value": 0 }, # register address { "script": virtualchain.make_payment_script(reveal_addr), "value": DEFAULT_DUST_FEE }, # change address { "script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount( inputs, total_to_send, DEFAULT_DUST_FEE * (len(inputs) + 2) + DEFAULT_OP_RETURN_FEE + tx_fee) }, ]
def make_outputs( data, inputs, change_addr, fee, tx_fee, pay_fee=True ): """ Make outputs for a namespace preorder: [0] OP_RETURN with the name [1] change address with the NAME_PREORDER sender's address [2] pay-to-address with the *burn address* with the fee Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 2) * DEFAULT_DUST_FEE + tx_fee op_fee = max(fee, DEFAULT_DUST_FEE) bill = op_fee if not pay_fee: # subsidized dust_fee = 0 op_fee = 0 bill = 0 return [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # change address {"script": virtualchain.make_payment_script( change_addr ), "value": virtualchain.calculate_change_amount(inputs, bill, dust_fee)}, # burn address {"script": virtualchain.make_payment_script(BLOCKSTACK_BURN_ADDRESS), "value": op_fee} ]
def make_outputs( data, inputs, new_name_owner_address, change_address, tx_fee=0, pay_fee=True): """ Builds the outputs for a name transfer operation. Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = None op_fee = None dust_value = DEFAULT_DUST_FEE if pay_fee: dust_fee = (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee op_fee = DEFAULT_DUST_FEE else: dust_fee = 0 op_fee = 0 return [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # new name owner output {"script": virtualchain.make_payment_script(new_name_owner_address), "value": dust_value}, # change output {"script": virtualchain.make_payment_script(change_address), "value": virtualchain.calculate_change_amount(inputs, op_fee, dust_fee)} ]
def make_outputs(data, inputs, sender_addr, burn_addr, fee, tx_fee, pay_fee=True, dust_included=False): """ Make outputs for a name preorder: [0] OP_RETURN with the name [1] address with the NAME_PREORDER sender's address [2] pay-to-address with the *burn address* with the fee Raise ValueError if there are not enough inputs to make the transaction """ op_fee = max(fee, DEFAULT_DUST_FEE) total_tx_fee = tx_fee if not dust_included: total_tx_fee += (len(inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE dust_value = DEFAULT_DUST_FEE bill = 0 if pay_fee: bill = op_fee else: op_fee = 0 bill = 0 total_tx_fee = 0 return [ # main output { "script": virtualchain.make_data_script(str(data)), "value": 0 }, # change address (can be subsidy key) { "script": virtualchain.make_payment_script(str(sender_addr)), "value": virtualchain.calculate_change_amount(inputs, bill, total_tx_fee) }, # burn address { "script": virtualchain.make_payment_script(str(burn_addr)), "value": op_fee } ]
def make_outputs( nulldata, inputs, change_addr, tx_fee=0 ): """ Make namespace-ready outputs """ return [ { "script": virtualchain.make_data_script(str(nulldata)), "value": 0 }, # change output { "script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount(inputs, 0, tx_fee + DEFAULT_OP_RETURN_FEE) } ]
def mktx(satoshis, fee): outputs = None if satoshis is None: # send all satoshis = sum([u['value'] for u in utxos]) print 'WARN: sending all of {} ({}) to {}'.format( payment_addr, satoshis, recipient_addr) outputs = [ { 'script': virtualchain.make_payment_script(payment_addr), 'value': virtualchain.calculate_change_amount(utxos, 0, fee) }, ] else: outputs = [ { "script": virtualchain.make_payment_script(payment_addr), "value": satoshis }, { "script": virtualchain.make_payment_script(recipient_addr), "value": virtualchain.calculate_change_amount(utxos, satoshis, fee) }, ] txobj = {'ins': utxos, 'outs': outputs, 'locktime': 0, 'version': 1} # log.debug("serialize tx: {}".format(json.dumps(txobj, indent=4, sort_keys=True))) txstr = virtualchain.btc_tx_serialize(txobj) signed_txstr = virtualchain.tx_sign_all_unsigned_inputs( privkey, utxos, txstr) return signed_txstr
def tx_make_subsidization_output(payer_utxo_inputs, payer_address, op_fee, dust_fee): """ Given the set of utxo inputs for both the client and payer, as well as the client's desired tx outputs, generate the inputs and outputs that will cause the payer to pay the operation's fees and dust fees. The client should send its own address as an input, with the same amount of BTC as the output. Return the payer output to include in the transaction on success, which should pay for the operation's fee and dust. Raise ValueError it here aren't enough inputs to subsidize """ return { 'script': virtualchain.make_payment_script(payer_address), 'value': virtualchain.calculate_change_amount(payer_utxo_inputs, op_fee, int(round(dust_fee))) }
def make_outputs(nulldata, inputs, change_addr, tx_fee=0): """ Make namespace-ready outputs """ return [ { "script": virtualchain.make_data_script(str(nulldata)), "value": 0 }, # change output { "script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount( inputs, 0, tx_fee + DEFAULT_OP_RETURN_FEE) } ]
def make_outputs(data, inputs, change_addr, fee, tx_fee, pay_fee=True): """ Make outputs for a namespace preorder: [0] OP_RETURN with the name [1] change address with the NAME_PREORDER sender's address [2] pay-to-address with the *burn address* with the fee Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = DEFAULT_OP_RETURN_FEE + (len(inputs) + 2) * DEFAULT_DUST_FEE + tx_fee op_fee = max(fee, DEFAULT_DUST_FEE) bill = op_fee if not pay_fee: # subsidized dust_fee = 0 op_fee = 0 bill = 0 return [ # main output { "script": virtualchain.make_data_script(str(data)), "value": 0 }, # change address { "script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount(inputs, bill, dust_fee) }, # burn address { "script": virtualchain.make_payment_script(BLOCKSTACK_BURN_ADDRESS), "value": op_fee } ]
def make_outputs( data, inputs, reveal_addr, change_addr, tx_fee): """ Make outputs for a register: [0] OP_RETURN with the name [1] pay-to-address with the *reveal_addr*, not the sender's address. [2] change address with the NAMESPACE_PREORDER sender's address Raise ValueError if there are not enough inputs to make the transaction """ total_to_send = DEFAULT_OP_RETURN_FEE + DEFAULT_DUST_FEE return [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # register address {"script": virtualchain.make_payment_script(reveal_addr), "value": DEFAULT_DUST_FEE}, # change address {"script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount(inputs, total_to_send, DEFAULT_DUST_FEE * (len(inputs) + 2) + DEFAULT_OP_RETURN_FEE + tx_fee)}, ]
def make_outputs(data, change_inputs, register_addr, change_addr, tx_fee, renewal_fee=None, pay_fee=True): """ Make outputs for a register: [0] OP_RETURN with the name [1] pay-to-address with the *register_addr*, not the sender's address. [2] change address with the NAME_PREORDER sender's address [3] (OPTIONAL) renewal fee, sent to the burn address Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = None dust_value = DEFAULT_DUST_FEE op_fee = None bill = None if pay_fee: # sender pays if renewal_fee is not None: # renewing dust_fee = (len(change_inputs) + 3) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee op_fee = max(renewal_fee, DEFAULT_DUST_FEE) bill = op_fee else: # registering dust_fee = (len(change_inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee op_fee = 0 bill = DEFAULT_DUST_FEE * 2 else: # subsidized by another address if renewal_fee is not None: # renewing dust_fee = 0 op_fee = max(renewal_fee, DEFAULT_DUST_FEE) bill = 0 else: # registering dust_fee = 0 op_fee = 0 bill = 0 outputs = [ # main output { "script": virtualchain.make_data_script(str(data)), "value": 0 }, # register address { "script": virtualchain.make_payment_script(register_addr), "value": dust_value }, # change address (can be the subsidy address) { "script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount(change_inputs, bill, dust_fee) }, ] if renewal_fee is not None: outputs.append( # burn address (when renewing) { "script": virtualchain.make_payment_script(BLOCKSTACK_BURN_ADDRESS), "value": op_fee }) return outputs
def make_outputs(data, change_inputs, register_addr, change_addr, tx_fee, renewal_fee=None, burn_address=BLOCKSTACK_BURN_ADDRESS, pay_fee=True, dust_included=False): """ Make outputs for a register: [0] OP_RETURN with the name, and possibly a value hash [1] pay-to-address with the *register_addr*, not the sender's address. If renewing, this is the new owner address. [2] change address with the NAME_PREORDER or NAME_RENEWAL's subsidizer's sender's address [3] (OPTIONAL) renewal fee, sent to the burn address Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = None dust_value = DEFAULT_DUST_FEE op_fee = None bill = None if pay_fee: # sender pays total_tx_fee = tx_fee if renewal_fee is not None: # renewing dust_fee = (len(change_inputs) + 3) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE op_fee = max(renewal_fee, DEFAULT_DUST_FEE) bill = op_fee else: # registering dust_fee = (len(change_inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE op_fee = 0 bill = DEFAULT_DUST_FEE * 2 if not dust_included: total_tx_fee += dust_fee else: # subsidized by another address bill = 0 total_tx_fee = 0 if renewal_fee is not None: # renewing op_fee = max(renewal_fee, DEFAULT_DUST_FEE) else: # registering op_fee = 0 payload = str(data) outputs = [ # main output { "script": virtualchain.make_data_script(payload), "value": 0 }, # register/new-owner address { "script": virtualchain.make_payment_script(str(register_addr)), "value": dust_value }, # change address (can be the subsidy address) { "script": virtualchain.make_payment_script(str(change_addr)), "value": virtualchain.calculate_change_amount(change_inputs, bill, total_tx_fee) }, ] if renewal_fee is not None: outputs.append( # burn address (when renewing) { "script": virtualchain.make_payment_script(str(burn_address)), "value": op_fee }) return outputs
def make_outputs( data, change_inputs, register_addr, change_addr, tx_fee, renewal_fee=None, pay_fee=True): """ Make outputs for a register: [0] OP_RETURN with the name [1] pay-to-address with the *register_addr*, not the sender's address. [2] change address with the NAME_PREORDER sender's address [3] (OPTIONAL) renewal fee, sent to the burn address Raise ValueError if there are not enough inputs to make the transaction """ dust_fee = None dust_value = DEFAULT_DUST_FEE op_fee = None bill = None if pay_fee: # sender pays if renewal_fee is not None: # renewing dust_fee = (len(change_inputs) + 3) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee op_fee = max(renewal_fee, DEFAULT_DUST_FEE) bill = op_fee else: # registering dust_fee = (len(change_inputs) + 2) * DEFAULT_DUST_FEE + DEFAULT_OP_RETURN_FEE + tx_fee op_fee = 0 bill = DEFAULT_DUST_FEE * 2 else: # subsidized by another address if renewal_fee is not None: # renewing dust_fee = 0 op_fee = max(renewal_fee, DEFAULT_DUST_FEE) bill = 0 else: # registering dust_fee = 0 op_fee = 0 bill = 0 outputs = [ # main output {"script": virtualchain.make_data_script(str(data)), "value": 0}, # register address {"script": virtualchain.make_payment_script(register_addr), "value": dust_value}, # change address (can be the subsidy address) {"script": virtualchain.make_payment_script(change_addr), "value": virtualchain.calculate_change_amount(change_inputs, bill, dust_fee)}, ] if renewal_fee is not None: outputs.append( # burn address (when renewing) {"script": virtualchain.make_payment_script(BLOCKSTACK_BURN_ADDRESS), "value": op_fee} ) return outputs