Skip to content

Commit 088e3f8

Browse files
committed
tx: also compute rangeproof size for issuances if requested
We don't use this yet, but taproot requires it.
1 parent a23c923 commit 088e3f8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/transaction.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,18 +1688,24 @@ static int get_txout_commitments_size(const struct wally_tx_output *output,
16881688
}
16891689

16901690
static int get_txin_issuance_size(const struct wally_tx_input *input,
1691-
size_t *written)
1691+
size_t *issuance_size, size_t *issuance_rp_size)
16921692
{
1693-
*written = 0;
1693+
*issuance_size = 0;
1694+
if (issuance_rp_size)
1695+
*issuance_rp_size = 0;
16941696
#ifdef BUILD_ELEMENTS
16951697
if (input->features & WALLY_TX_IS_ISSUANCE) {
16961698
size_t c_n;
16971699

1698-
if (!(*written = confidential_value_length_from_bytes(input->issuance_amount)))
1700+
if (!(*issuance_size = confidential_value_length_from_bytes(input->issuance_amount)))
16991701
return WALLY_EINVAL;
17001702
if (!(c_n = confidential_value_length_from_bytes(input->inflation_keys)))
17011703
return WALLY_EINVAL;
1702-
*written = *written + c_n + sizeof(input->blinding_nonce) + sizeof(input->entropy);
1704+
*issuance_size += c_n + sizeof(input->blinding_nonce) + sizeof(input->entropy);
1705+
if (issuance_rp_size) {
1706+
*issuance_rp_size = input->issuance_amount_rangeproof_len +
1707+
input->inflation_keys_rangeproof_len;
1708+
}
17031709
}
17041710
#else
17051711
(void)input;
@@ -1772,7 +1778,8 @@ static int tx_get_lengths(const struct wally_tx *tx,
17721778
}
17731779
*base_size += amount_size;
17741780

1775-
if (get_txin_issuance_size(tx->inputs + opts->index, &issuance_size) != WALLY_OK)
1781+
if (get_txin_issuance_size(tx->inputs + opts->index,
1782+
&issuance_size, NULL) != WALLY_OK)
17761783
return WALLY_EINVAL;
17771784
*base_size += issuance_size;
17781785
*witness_size = 0;
@@ -1807,7 +1814,7 @@ static int tx_get_lengths(const struct wally_tx *tx,
18071814
sizeof(input->index) +
18081815
sizeof(input->sequence);
18091816

1810-
if (get_txin_issuance_size(input, &issuance_size) != WALLY_OK)
1817+
if (get_txin_issuance_size(input, &issuance_size, NULL) != WALLY_OK)
18111818
return WALLY_EINVAL;
18121819
n += issuance_size;
18131820

@@ -2168,7 +2175,8 @@ static inline int tx_to_bip143_bytes(const struct wally_tx *tx,
21682175
for (i = 0; i < tx->num_inputs; ++i) {
21692176
if (tx->inputs[i].features & WALLY_TX_IS_ISSUANCE) {
21702177
size_t issuance_size;
2171-
if (get_txin_issuance_size(tx->inputs + i, &issuance_size) != WALLY_OK)
2178+
if (get_txin_issuance_size(tx->inputs + i,
2179+
&issuance_size, NULL) != WALLY_OK)
21722180
return WALLY_EINVAL;
21732181
issuances_size += issuance_size;
21742182
} else

0 commit comments

Comments
 (0)