Example #1
0
    def create_transaction(utxos):
        core = bitcoincore.Connection(clargs.args)

        nlocktime = blockcount = get_current_blockcount() or 0
        is_replaceable = True

        estimated_vsize = EMPTY_TX_SIZE
        inputs, used_utxos = [], []

        for u in utxos:
            if not u.is_expired(blockcount):
                blocks_left = u.output.csv_blocks + u.height - blockcount
                logging.info('Skipping utxo ({}:{}) not expired ({} blocks left)'.format(
                    b2h_rev(u.txid), u.vout, blocks_left))
                continue

            estimated_vsize += INPUT_SIZE

            inputs.append({'txid': b2h_rev(u.txid), 'vout': u.vout})
            used_utxos.append(u)

        if len(used_utxos) == 0:
            return '', []

        logging.info('num used utxos: {}'.format(len(used_utxos)))

        feerate = get_feerate()
        satoshi_fee = round(feerate * estimated_vsize)

        satoshi_send = sum(u.satoshi for u in used_utxos) - satoshi_fee
        if satoshi_send < DUST_SATOSHI:
            raise InsufficientFee

        address = core.getnewaddress()
        scriptpubkey = scriptpubkey_from_address(address)

        tx = wally.tx_init(wally.WALLY_TX_VERSION_2, nlocktime, len(inputs), 1)
        sequence = MAX_BIP125_RBF_SEQUENCE
        if not is_replaceable:
            # A transaction is considered to have opted in to allowing
            # replacement of itself if any of its inputs have an nSequence
            # number less than or equal to MAX_BIP125_RBF_SEQUENCE
            sequence += 1

        for _input in inputs:
            txid = h2b_rev(_input['txid'])
            wally.tx_add_raw_input(tx, txid, _input['vout'], sequence, None, None, 0)

        wally.tx_add_raw_output(tx, satoshi_send, scriptpubkey, 0)

        transaction = wally.tx_to_hex(tx, wally.WALLY_TX_FLAG_USE_WITNESS)

        return transaction, used_utxos
Example #2
0
def new(nlocktime=0, inputs=8, outputs=8, version=wally.WALLY_TX_VERSION_2):
    # Create with room for 8 inputs/outputs by default to reduce re-allocations
    return wally.tx_init(version, nlocktime, inputs, outputs)
Example #3
0
non_confidential_addresses = [
    wally.confidential_addr_to_addr(confidential_address, address_prefix)
    for confidential_address in confidential_output_addresses
]

script_pubkeys = [
    wally.address_to_scriptpubkey(non_confidential_address, network)
    for non_confidential_address in non_confidential_addresses
]
# end-decompose_address

# start-create_output_tx
version = 2
locktime = 0
output_tx = wally.tx_init(version, locktime, 0, 0)
# end-create_output_tx

# start-create_outputs
for value, blinding_pubkey, script_pubkey in zip(output_values,
                                                 blinding_pubkeys,
                                                 script_pubkeys):

    abf, abfs_out = abfs_out[:32], abfs_out[32:]
    vbf, vbfs_out = vbfs_out[:32], vbfs_out[32:]
    asset_id, output_asset_ids = output_asset_ids[:32], output_asset_ids[32:]

    generator = wally.asset_generator_from_bytes(asset_id, abf)

    value_commitment = wally.asset_value_commitment(value, vbf, generator)
Example #4
0
 def __init__(self,
              tx=None,
              version: int = wally.WALLY_TX_VERSION_2,
              nlocktime: int = 0):
     self.tx = tx if tx else wally.tx_init(version, nlocktime, 0, 0)