@@ -64,14 +64,52 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
64
64
65
65
size_t utxo_spend_weight (const struct utxo * utxo , size_t min_witness_weight )
66
66
{
67
- size_t wit_weight = bitcoin_tx_simple_input_witness_weight ();
67
+ size_t witness_weight ;
68
+ bool p2sh ;
69
+
70
+ switch (utxo -> utxotype ) {
71
+ case UTXO_P2SH_P2WPKH :
72
+ witness_weight = bitcoin_tx_simple_input_witness_weight ();
73
+ p2sh = true;
74
+ goto have_weight ;
75
+ case UTXO_P2WPKH :
76
+ witness_weight = bitcoin_tx_simple_input_witness_weight ();
77
+ p2sh = false;
78
+ goto have_weight ;
79
+ case UTXO_P2WSH_FROM_CLOSE :
80
+ /* BOLT #3:
81
+ * #### `to_remote` Output
82
+ *
83
+ * If `option_anchors` applies to the commitment
84
+ * transaction, the `to_remote` output is encumbered by a one
85
+ * block csv lock.
86
+ * <remotepubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
87
+ *
88
+ * The output is spent by an input with `nSequence` field set
89
+ * to `1` and witness: <remote_sig>
90
+ * Otherwise, this output is a simple P2WPKH to `remotepubkey`.
91
+ */
92
+ if (utxo -> close_info -> option_anchors )
93
+ witness_weight = 1 + 33 + 3 + 1 + 64 ;
94
+ else
95
+ witness_weight = 1 + 64 ;
96
+ p2sh = false;
97
+ goto have_weight ;
98
+ case UTXO_P2TR :
99
+ witness_weight = 1 + 64 ;
100
+ p2sh = false;
101
+ goto have_weight ;
102
+ }
103
+ abort ();
104
+
105
+ have_weight :
68
106
/* If the min is less than what we'd use for a 'normal' tx,
69
107
* we return the value with the greater added/calculated */
70
- if (wit_weight < min_witness_weight )
71
- return bitcoin_tx_input_weight (utxo -> utxotype == UTXO_P2SH_P2WPKH ,
108
+ if (witness_weight < min_witness_weight )
109
+ return bitcoin_tx_input_weight (p2sh ,
72
110
min_witness_weight );
73
111
74
- return bitcoin_tx_input_weight (utxo -> utxotype == UTXO_P2SH_P2WPKH , wit_weight );
112
+ return bitcoin_tx_input_weight (p2sh , witness_weight );
75
113
}
76
114
77
115
u32 utxo_is_immature (const struct utxo * utxo , u32 blockheight )
0 commit comments