mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
wallet: Add method to retrieve outpoints from the utxoset
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
1de124277b
commit
387ba76920
2 changed files with 48 additions and 0 deletions
|
@ -1891,3 +1891,38 @@ void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
|
|||
|
||||
outpointfilter_add(w->utxoset_outpoints, &txid, outnum);
|
||||
}
|
||||
|
||||
struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
struct outpoint *op;
|
||||
stmt = db_prepare(w->db, "SELECT"
|
||||
" txid,"
|
||||
" spendheight,"
|
||||
" scriptpubkey,"
|
||||
" satoshis "
|
||||
"FROM utxoset "
|
||||
"WHERE blockheight = ?"
|
||||
" AND txindex = ?"
|
||||
" AND outnum = ?");
|
||||
sqlite3_bind_int(stmt, 1, short_channel_id_blocknum(scid));
|
||||
sqlite3_bind_int(stmt, 2, short_channel_id_txnum(scid));
|
||||
sqlite3_bind_int(stmt, 3, short_channel_id_outnum(scid));
|
||||
|
||||
|
||||
if (sqlite3_step(stmt) != SQLITE_ROW)
|
||||
return NULL;
|
||||
|
||||
op = tal(ctx, struct outpoint);
|
||||
op->blockheight = short_channel_id_blocknum(scid);
|
||||
op->txindex = short_channel_id_txnum(scid);
|
||||
op->outnum = short_channel_id_outnum(scid);
|
||||
sqlite3_column_sha256_double(stmt, 0, &op->txid.shad);
|
||||
op->spendheight = sqlite3_column_int(stmt, 1);
|
||||
op->scriptpubkey = tal_arr(op, u8, sqlite3_column_bytes(stmt, 2));
|
||||
memcpy(op->scriptpubkey, sqlite3_column_blob(stmt, 2), sqlite3_column_bytes(stmt, 2));
|
||||
op->satoshis = sqlite3_column_int64(stmt, 3);
|
||||
|
||||
return op;
|
||||
}
|
||||
|
|
|
@ -108,6 +108,16 @@ struct wallet_payment {
|
|||
struct short_channel_id *route_channels;
|
||||
};
|
||||
|
||||
struct outpoint {
|
||||
struct bitcoin_txid txid;
|
||||
u32 blockheight;
|
||||
u32 txindex;
|
||||
u32 outnum;
|
||||
u64 satoshis;
|
||||
u8 *scriptpubkey;
|
||||
u32 spendheight;
|
||||
};
|
||||
|
||||
/**
|
||||
* wallet_new - Constructor for a new sqlite3 based wallet
|
||||
*
|
||||
|
@ -711,6 +721,9 @@ void wallet_blocks_rollback(struct wallet *w, u32 height);
|
|||
void wallet_outpoint_spend(struct wallet *w, const u32 blockheight,
|
||||
const struct bitcoin_txid *txid, const u32 outnum);
|
||||
|
||||
struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
||||
const struct short_channel_id *scid);
|
||||
|
||||
void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
|
||||
const u32 outnum, const u32 blockheight,
|
||||
const u32 txindex, const u8 *scriptpubkey,
|
||||
|
|
Loading…
Add table
Reference in a new issue