MCPcopy Create free account
hub / github.com/ElementsProject/lightning / psbt_using_utxos

Function psbt_using_utxos

wallet/reservation.c:256–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256struct 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 */

Callers 4

finish_psbtFunction · 0.85
json_addpsbtinputFunction · 0.85
anchor_psbtFunction · 0.85

Calls 11

create_psbtFunction · 0.85
scriptpubkey_p2shFunction · 0.85
psbt_append_inputFunction · 0.85
psbt_input_set_wit_utxoFunction · 0.85
is_elementsFunction · 0.85
wallet_transaction_getFunction · 0.85
psbt_input_set_utxoFunction · 0.85
bip32_pubkeyFunction · 0.50
amount_sat_to_assetFunction · 0.50

Tested by

no test coverage detected