Browse Source

wallet: Add function to retrieve transactions from the wallet

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2938/head
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
6efb1c00a6
  1. 24
      wallet/wallet.c
  2. 19
      wallet/wallet.h

24
wallet/wallet.c

@ -2806,3 +2806,27 @@ void wallet_clean_utxos(struct wallet *w, struct bitcoind *bitcoind)
} else } else
tal_free(utxos); tal_free(utxos);
} }
struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx)
{
sqlite3_stmt *stmt;
size_t count;
struct wallet_transaction *cur, *txs = tal_arr(ctx, struct wallet_transaction, 0);
stmt = db_select_prepare(w->db,
"id, id, rawtx, blockheight, txindex, type, channel_id "
"FROM transactions");
for (count = 0; db_select_step(w->db, stmt); count++) {
tal_resize(&txs, count + 1);
cur = &txs[count];
sqlite3_column_sha256_double(stmt, 1, &cur->id.shad);
cur->rawtx = tal_dup_arr(txs, u8, sqlite3_column_blob(stmt, 2),
sqlite3_column_bytes(stmt, 2), 0);
cur->blockheight = sqlite3_column_int(stmt, 3);
cur->txindex = sqlite3_column_int(stmt, 4);
cur->type = sqlite3_column_int(stmt, 5);
cur->channel_id = sqlite3_column_int(stmt, 6);
}
return txs;
}

19
wallet/wallet.h

@ -289,6 +289,15 @@ struct channeltx {
u32 depth; u32 depth;
}; };
struct wallet_transaction {
struct bitcoin_txid id;
u32 blockheight;
u32 txindex;
u8 *rawtx;
txtypes type;
u64 channel_id;
};
/** /**
* wallet_new - Constructor for a new sqlite3 based wallet * wallet_new - Constructor for a new sqlite3 based wallet
* *
@ -1131,4 +1140,14 @@ void add_unreleased_tx(struct wallet *w, struct unreleased_tx *utx);
/* These will touch the db, so need to be explicitly freed. */ /* These will touch the db, so need to be explicitly freed. */
void free_unreleased_txs(struct wallet *w); void free_unreleased_txs(struct wallet *w);
/**
* Get a list of transactions that we track in the wallet.
*
* @param ctx: allocation context for the returned list
* @param wallet: Wallet to load from.
* @return A tal_arr of wallet transactions
*/
struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx);
#endif /* LIGHTNING_WALLET_WALLET_H */ #endif /* LIGHTNING_WALLET_WALLET_H */

Loading…
Cancel
Save