| 254 | } |
| 255 | |
| 256 | struct wally_psbt *psbt_using_utxos(const tal_t *ctx, |
| 257 | struct wallet *wallet, |
| 258 | struct utxo **utxos, |
| 259 | u32 nlocktime, |
| 260 | u32 nsequence, |
| 261 | struct wally_psbt *base) |
| 262 | { |
| 263 | struct pubkey key; |
| 264 | u8 *scriptSig, *scriptPubkey, *redeemscript; |
| 265 | struct wally_psbt *psbt; |
| 266 | |
| 267 | if (base) |
| 268 | psbt = base; |
| 269 | else |
| 270 | psbt = create_psbt(ctx, tal_count(utxos), 0, nlocktime); |
| 271 | |
| 272 | for (size_t i = 0; i < tal_count(utxos); i++) { |
| 273 | u32 this_nsequence; |
| 274 | struct bitcoin_tx *tx; |
| 275 | |
| 276 | if (utxos[i]->utxotype == UTXO_P2SH_P2WPKH) { |
| 277 | bip32_pubkey(wallet->ld, &key, utxos[i]->keyindex); |
| 278 | scriptSig = bitcoin_scriptsig_p2sh_p2wpkh(tmpctx, &key); |
| 279 | redeemscript = bitcoin_redeem_p2sh_p2wpkh(tmpctx, &key); |
| 280 | scriptPubkey = scriptpubkey_p2sh(tmpctx, redeemscript); |
| 281 | |
| 282 | /* Make sure we've got the right info! */ |
| 283 | if (utxos[i]->scriptPubkey) |
| 284 | assert(tal_arr_eq(utxos[i]->scriptPubkey, scriptPubkey)); |
| 285 | } else { |
| 286 | scriptSig = NULL; |
| 287 | redeemscript = NULL; |
| 288 | scriptPubkey = utxos[i]->scriptPubkey; |
| 289 | } |
| 290 | |
| 291 | /* BOLT #3: |
| 292 | * #### `to_remote` Output |
| 293 | * ... |
| 294 | * The output is spent by an input with `nSequence` field |
| 295 | * set to `1` and witness: |
| 296 | */ |
| 297 | if (utxos[i]->close_info |
| 298 | && utxos[i]->close_info->option_anchors) |
| 299 | this_nsequence = utxos[i]->close_info->csv; |
| 300 | else |
| 301 | this_nsequence = nsequence; |
| 302 | |
| 303 | psbt_append_input(psbt, &utxos[i]->outpoint, |
| 304 | this_nsequence, scriptSig, |
| 305 | NULL, redeemscript); |
| 306 | |
| 307 | psbt_input_set_wit_utxo(psbt, psbt->num_inputs-1, |
| 308 | scriptPubkey, utxos[i]->amount); |
| 309 | if (is_elements(chainparams)) { |
| 310 | /* FIXME: persist asset tags */ |
| 311 | amount_sat_to_asset(&utxos[i]->amount, |
| 312 | chainparams->fee_asset_tag); |
| 313 | /* FIXME: persist nonces */ |
no test coverage detected