How to create an asset issuance transaction using libwally?

0

I'm trying to create and sign a transaction for issuing an asset on the Liquid network using libwally.

I create the contract, entropy and asset hash with:

def build_issuance_data(contract_data, input_hash, input_index):
    contract = json.dumps(contract_data, separators=(",",":"), sort_keys=True)
    contract_hash = wally.sha256(contract.encode('ascii'))
    entropy = wally.tx_elements_issuance_generate_entropy(input_hash, input_index, contract_hash)
    asset_hash = wally.tx_elements_issuance_calculate_asset(entropy)
    return contract_hash, entropy, asset_hash

Then I build the unsigned transaction with:

def build_transaction(vins, vouts, lbtc_asset, entropy, amount, issuance_input_index, address_type):
    tx = wally.tx_init(2, 0, len(vins), len(vouts))

    # outputs
    for vout in vouts:
        script_pubkey = script_pubkey_from_address(vout["address"], address_type)
        wally.tx_add_elements_raw_output(
            tx,
            script_pubkey,
            lbtc_asset,
            wally.tx_confidential_value_from_satoshi(vout["amount"]), # the function adds a prefix to specify it's an explicit amount
            None, # nonce             ‾|
            None, # surjection_proof   | -> bilinding stuff
            None, # range_proof       _|
            0
        )

    #inputs
    for i, vin in enumerate(vins):
        prev_tx_hash = h2b(vin["txid"])[::-1]
        prev_tx_index = vin["vout"]
        issuance_entropy = entropy if i == issuance_input_index else None
        issuance_amount = h2b(amount) if i == issuance_input_index else None

        wally.tx_add_elements_raw_input(
            tx,
            prev_tx_hash,
            prev_tx_index,
            SEQUENCE, # sequence
            None, # scriptsig, is calculated later
            None, # witness
            None, # nonce
            issuance_entropy, # entropy
            issuance_amount, # issuance_amount
            None, # inflation_keys
            None, # issuance_amount_rangeproof
            None, # issuance_rangeproof
            None, # pegin_witness
            0
        )
        print(wally.tx_get_input_entropy(tx, i)

    return wally.tx_to_bytes(tx, 0)

Making a test with 1 input and 2 outputs, if I decode the returned raw transaction into a JSON object using liquid-cli decoderawtransaction, I can see that the input does not contain information about the issuance but at the same time wally.tx_get_input_entropy correctly returns the entropy calculated before.

I have the suspect the problem is not the transaction itself, but rather the serialization. Which flag should I use when serializing/deserializing the transaction?

altafan

Posted 2019-09-13T11:05:54.113

Reputation: 21

Your problem is serializing the transaction to hex form?vincenzopalazzo 2019-09-14T08:07:25.883

No answers