mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
wallet: remove unused wallet_channel_load().
It's only used for tests, but it's better to use the wallet_channels_load_active like the real code. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4dea3c4747
commit
f5c319a37e
@ -255,6 +255,22 @@ static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2)
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct wallet_channel *wallet_channel_load(struct wallet *w, const u64 id)
|
||||
{
|
||||
struct list_head peers;
|
||||
struct peer *peer;
|
||||
|
||||
list_head_init(&peers);
|
||||
|
||||
/* We expect only one peer, but reuse same code */
|
||||
if (!wallet_channels_load_active(w, &peers))
|
||||
return NULL;
|
||||
peer = list_top(&peers, struct peer, list);
|
||||
CHECK(peer);
|
||||
CHECK(peer->channel->id == id);
|
||||
return peer->channel;
|
||||
}
|
||||
|
||||
static bool test_channel_crud(const tal_t *ctx)
|
||||
{
|
||||
struct wallet *w = create_test_wallet(ctx);
|
||||
@ -284,6 +300,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
p.id = pk;
|
||||
p.our_msatoshi = NULL;
|
||||
p.last_tx = NULL;
|
||||
p.state = CHANNELD_NORMAL;
|
||||
memset(&ci.their_config, 0, sizeof(struct channel_config));
|
||||
ci.remote_fundingkey = pk;
|
||||
ci.theirbase.revocation = pk;
|
||||
@ -300,7 +317,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Load from DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v1)");
|
||||
@ -315,7 +332,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v2)");
|
||||
@ -330,7 +347,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v3)");
|
||||
@ -339,7 +356,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
c1.peer->funding_txid = hash;
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v4)");
|
||||
@ -348,7 +365,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
p.channel_info = &ci;
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v5)");
|
||||
@ -357,7 +374,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
p.last_sent_commit = &last_commit;
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v6)");
|
||||
@ -367,7 +384,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
p.last_sig = sig;
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v7)");
|
||||
@ -377,7 +394,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
p.local_shutdown_idx = 1337;
|
||||
wallet_channel_save(w, &c1);
|
||||
CHECK_MSG(!wallet_err, tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, c1.id), tal_fmt(w, "Load from DB"));
|
||||
CHECK_MSG(!wallet_err,
|
||||
tal_fmt(w, "Insert into DB: %s", wallet_err));
|
||||
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v8)");
|
||||
|
@ -559,7 +559,7 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
|
||||
|
||||
/* List of fields to retrieve from the channels DB table, in the order
|
||||
* that wallet_stmt2channel understands and will parse correctly */
|
||||
const char *channel_fields =
|
||||
static const char *channel_fields =
|
||||
"id, peer_id, short_channel_id, channel_config_local, "
|
||||
"channel_config_remote, state, funder, channel_flags, "
|
||||
"minimum_depth, "
|
||||
@ -574,27 +574,6 @@ const char *channel_fields =
|
||||
"last_sent_commit_state, last_sent_commit_id, "
|
||||
"last_tx, last_sig";
|
||||
|
||||
bool wallet_channel_load(struct wallet *w, const u64 id,
|
||||
struct wallet_channel *chan)
|
||||
{
|
||||
bool ok;
|
||||
/* The explicit query that matches the columns and their order in
|
||||
* wallet_stmt2channel. */
|
||||
sqlite3_stmt *stmt = db_query(
|
||||
__func__, w->db, "SELECT %s FROM channels WHERE id=%" PRIu64 ";",
|
||||
channel_fields, id);
|
||||
|
||||
if (!stmt || sqlite3_step(stmt) != SQLITE_ROW) {
|
||||
sqlite3_finalize(stmt);
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = wallet_stmt2channel(w, stmt, chan);
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool wallet_channels_load_active(struct wallet *w, struct list_head *peers)
|
||||
{
|
||||
bool ok = true;
|
||||
|
@ -197,8 +197,6 @@ bool wallet_shachain_add_hash(struct wallet *wallet,
|
||||
bool wallet_shachain_load(struct wallet *wallet, u64 id,
|
||||
struct wallet_shachain *chain);
|
||||
|
||||
bool wallet_channel_load(struct wallet *w, const u64 id,
|
||||
struct wallet_channel *chan);
|
||||
|
||||
/**
|
||||
* wallet_channel_save -- Upsert the channel into the database
|
||||
|
Loading…
Reference in New Issue
Block a user