diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 1e4bf6eac..5b32ac367 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -204,6 +204,8 @@ const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, return res; } +/* FIXME(cdecker) Make the caller pass in a reference to amount_asset, and + * return false if unintelligible/encrypted. (WARN UNUSED). */ struct amount_asset bitcoin_tx_output_get_amount(const struct bitcoin_tx *tx, int outnum) { @@ -216,13 +218,18 @@ struct amount_asset bitcoin_tx_output_get_amount(const struct bitcoin_tx *tx, output = &tx->wtx->outputs[outnum]; if (chainparams->is_elements) { - /* We currently only support v1 asset tags */ - assert(output->asset_len == sizeof(amount.asset) && - output->asset[0] == 0x01); + assert(output->asset_len == sizeof(amount.asset)); memcpy(&amount.asset, output->asset, sizeof(amount.asset)); - memcpy(&raw, output->value + 1, sizeof(raw)); - amount.value = be64_to_cpu(raw); + /* We currently only support explicit value asset tags, others + * are confidential, so don't even try to assign a value to + * it. */ + if (output->asset[0] == 0x01) { + memcpy(&raw, output->value + 1, sizeof(raw)); + amount.value = be64_to_cpu(raw); + } else { + amount.value = 0; + } } else { /* Do not assign amount.asset, we should never touch it in * non-elements scenarios. */