diff --git a/common/psbt_internal.c b/common/psbt_internal.c index 454e824fb..dc329c6ca 100644 --- a/common/psbt_internal.c +++ b/common/psbt_internal.c @@ -161,3 +161,32 @@ psbt_to_witnesses(const tal_t *ctx, return witnesses; } + +size_t psbt_input_weight(struct wally_psbt *psbt, + size_t in) +{ + size_t weight; + const struct wally_map_item *redeem_script; + + redeem_script = wally_map_get_integer(&psbt->inputs[in].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04); + + /* txid + txout + sequence */ + weight = (32 + 4 + 4) * 4; + if (redeem_script) { + weight += + (redeem_script->value_len + + (varint_t) varint_size(redeem_script->value_len)) * 4; + } else { + /* zero scriptSig length */ + weight += (varint_t) varint_size(0) * 4; + } + + return weight; +} + +size_t psbt_output_weight(struct wally_psbt *psbt, + size_t outnum) +{ + return (8 + psbt->outputs[outnum].script_len + + varint_size(psbt->outputs[outnum].script_len)) * 4; +} diff --git a/common/psbt_internal.h b/common/psbt_internal.h index 166c7a91f..b3a121b7c 100644 --- a/common/psbt_internal.h +++ b/common/psbt_internal.h @@ -33,4 +33,12 @@ psbt_to_witnesses(const tal_t *ctx, const struct wally_psbt *psbt, enum tx_role side_to_stack); +/* psbt_input_weight - Calculate the tx weight for input index `in` */ +size_t psbt_input_weight(struct wally_psbt *psbt, + size_t in); + +/* psbt_output_weight - Calculate the tx weight for output index `outnum` */ +size_t psbt_output_weight(struct wally_psbt *psbt, + size_t outnum); + #endif /* LIGHTNING_COMMON_PSBT_INTERNAL_H */ diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 1fa6a3a87..442576cb7 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -593,35 +593,6 @@ static bool is_openers(const struct wally_map *unknowns) return serial_id % 2 == TX_INITIATOR; } -static size_t psbt_input_weight(struct wally_psbt *psbt, - size_t in) -{ - size_t weight; - const struct wally_map_item *redeem_script; - - redeem_script = wally_map_get_integer(&psbt->inputs[in].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04); - - /* txid + txout + sequence */ - weight = (32 + 4 + 4) * 4; - if (redeem_script) { - weight += - (redeem_script->value_len + - (varint_t) varint_size(redeem_script->value_len)) * 4; - } else { - /* zero scriptSig length */ - weight += (varint_t) varint_size(0) * 4; - } - - return weight; -} - -static size_t psbt_output_weight(struct wally_psbt *psbt, - size_t outnum) -{ - return (8 + psbt->outputs[outnum].script_len + - varint_size(psbt->outputs[outnum].script_len)) * 4; -} - static bool find_txout(struct wally_psbt *psbt, const u8 *wscript, u32 *funding_txout) { for (size_t i = 0; i < psbt->num_outputs; i++) {