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

Function got_utxo

wallet/wallet.c:3275–3352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3273}
3274
3275static void got_utxo(struct wallet *w,
3276 u64 keyindex,
3277 enum addrtype addrtype,
3278 const struct wally_tx *wtx,
3279 size_t outnum,
3280 bool is_coinbase,
3281 const u32 *blockheight,
3282 struct bitcoin_outpoint *outpoint)
3283{
3284 struct utxo *utxo = tal(tmpctx, struct utxo);
3285 const struct wally_tx_output *txout = &wtx->outputs[outnum];
3286 struct amount_asset asset = wally_tx_output_get_amount(txout);
3287
3288 utxo->keyindex = keyindex;
3289 /* This switch() pattern catches anyone adding new cases, plus
3290 * runtime errors */
3291 switch (addrtype) {
3292 case ADDR_P2SH_SEGWIT:
3293 utxo->utxotype = UTXO_P2SH_P2WPKH;
3294 goto type_ok;
3295 case ADDR_BECH32:
3296 utxo->utxotype = UTXO_P2WPKH;
3297 goto type_ok;
3298 case ADDR_P2TR:
3299 utxo->utxotype = UTXO_P2TR;
3300 goto type_ok;
3301 case ADDR_ALL:
3302 break;
3303 }
3304 abort();
3305
3306type_ok:
3307 utxo->amount = amount_asset_to_sat(&asset);
3308 utxo->status = OUTPUT_STATE_AVAILABLE;
3309 wally_txid(wtx, &utxo->outpoint.txid);
3310 utxo->outpoint.n = outnum;
3311 utxo->close_info = NULL;
3312 utxo->is_in_coinbase = is_coinbase;
3313
3314 utxo->blockheight = blockheight;
3315 utxo->spendheight = NULL;
3316 utxo->scriptPubkey = tal_dup_arr(utxo, u8, txout->script, txout->script_len, 0);
3317 log_debug(w->log, "Owning output %zu %s (%s) txid %s%s%s",
3318 outnum,
3319 fmt_amount_sat(tmpctx, utxo->amount),
3320 utxotype_to_str(utxo->utxotype),
3321 fmt_bitcoin_txid(tmpctx, &utxo->outpoint.txid),
3322 blockheight ? " CONFIRMED" : "",
3323 is_coinbase ? " COINBASE" : "");
3324
3325 /* We only record final ledger movements */
3326 if (blockheight) {
3327 struct chain_coin_mvt *mvt;
3328
3329 mvt = new_coin_wallet_deposit(tmpctx, &utxo->outpoint,
3330 *blockheight,
3331 utxo->amount,
3332 mk_mvt_tags(MVT_DEPOSIT));

Callers 2

mutual_close_p2pkh_catchFunction · 0.85

Calls 13

abortFunction · 0.85
wally_txidFunction · 0.85
utxotype_to_strFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
new_coin_wallet_depositFunction · 0.85
wallet_save_chain_mvtFunction · 0.85
wallet_add_utxoFunction · 0.85
wallet_confirm_txFunction · 0.85
wallet_annotate_txoutFunction · 0.85
outpointfilter_addFunction · 0.70
amount_asset_to_satFunction · 0.50

Tested by

no test coverage detected