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