|
4 | 4 |
|
5 | 5 | size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight)
|
6 | 6 | {
|
7 |
| - size_t wit_weight = bitcoin_tx_simple_input_witness_weight(); |
| 7 | + size_t witness_weight; |
| 8 | + bool p2sh; |
| 9 | + |
| 10 | + switch (utxo->utxotype) { |
| 11 | + case UTXO_P2SH_P2WPKH: |
| 12 | + witness_weight = bitcoin_tx_simple_input_witness_weight(); |
| 13 | + p2sh = true; |
| 14 | + goto have_weight; |
| 15 | + case UTXO_P2WPKH: |
| 16 | + witness_weight = bitcoin_tx_simple_input_witness_weight(); |
| 17 | + p2sh = false; |
| 18 | + goto have_weight; |
| 19 | + case UTXO_P2WSH_FROM_CLOSE: |
| 20 | + /* BOLT #3: |
| 21 | + * #### `to_remote` Output |
| 22 | + * |
| 23 | + * If `option_anchors` applies to the commitment |
| 24 | + * transaction, the `to_remote` output is encumbered by a one |
| 25 | + * block csv lock. |
| 26 | + * <remotepubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY |
| 27 | + * |
| 28 | + * The output is spent by an input with `nSequence` field set |
| 29 | + * to `1` and witness: <remote_sig> |
| 30 | + * Otherwise, this output is a simple P2WPKH to `remotepubkey`. |
| 31 | + */ |
| 32 | + if (utxo->close_info->option_anchors) |
| 33 | + witness_weight = 1 + 33 + 3 + 1 + 64; |
| 34 | + else |
| 35 | + witness_weight = 1 + 64; |
| 36 | + p2sh = false; |
| 37 | + goto have_weight; |
| 38 | + case UTXO_P2TR: |
| 39 | + witness_weight = 1 + 64; |
| 40 | + p2sh = false; |
| 41 | + goto have_weight; |
| 42 | + } |
| 43 | + abort(); |
| 44 | + |
| 45 | +have_weight: |
8 | 46 | /* If the min is less than what we'd use for a 'normal' tx,
|
9 | 47 | * we return the value with the greater added/calculated */
|
10 |
| - if (wit_weight < min_witness_weight) |
11 |
| - return bitcoin_tx_input_weight(utxo->utxotype == UTXO_P2SH_P2WPKH, |
| 48 | + if (witness_weight < min_witness_weight) |
| 49 | + return bitcoin_tx_input_weight(p2sh, |
12 | 50 | min_witness_weight);
|
13 | 51 |
|
14 |
| - return bitcoin_tx_input_weight(utxo->utxotype == UTXO_P2SH_P2WPKH, wit_weight); |
| 52 | + return bitcoin_tx_input_weight(p2sh, witness_weight); |
15 | 53 | }
|
16 | 54 |
|
17 | 55 | u32 utxo_is_immature(const struct utxo *utxo, u32 blockheight)
|
|
0 commit comments