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

Function psbt_using_utxos

wallet/reservation.c:246–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244}
245
246static 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,

Callers 1

finish_psbtFunction · 0.85

Calls 14

create_psbtFunction · 0.85
bip32_pubkeyFunction · 0.85
scriptpubkey_p2shFunction · 0.85
memeqFunction · 0.85
tal_bytelenFunction · 0.85
is_elementsFunction · 0.85
wallet_transaction_getFunction · 0.85
psbt_input_set_utxoFunction · 0.85
psbt_append_inputFunction · 0.50
psbt_input_set_wit_utxoFunction · 0.50

Tested by

no test coverage detected