Skip to content

Commit

Permalink
runes: insert rune with correct id field.
Browse files Browse the repository at this point in the history
"id" is a magic name, so it was being populated by sqlite3
automatically, starting at 0.  Fortunately, we only fetched by id in
one place: to indicate the `stored` flag when asked about an explicit
rune in `showrunes`.

Reported-by: @ShahanaFarooqui
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: JSON-RPC: `showrunes` on a specific rune would always say `stored`: false.
  • Loading branch information
rustyrussell committed Aug 30, 2023
1 parent b7f9124 commit 496a6a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion tests/test_runes.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ def test_commando_blacklist_migration(node_factory):
{'start': 9, 'end': 9}]}


@pytest.mark.xfail(strict=True)
def test_showrune_id(node_factory):
l1 = node_factory.get_node()

Expand Down
10 changes: 5 additions & 5 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -5712,20 +5712,20 @@ const char **wallet_get_runes(const tal_t *ctx, struct wallet *wallet)
return strs;
}

static void db_rune_insert(struct db *db, struct rune *rune)
static void db_rune_insert(struct db *db,
const struct rune *rune)
{
struct db_stmt *stmt;

assert(rune->unique_id != NULL);

stmt = db_prepare_v2(db,
SQL("INSERT INTO runes (rune) VALUES (?);"));
SQL("INSERT INTO runes (id, rune) VALUES (?, ?);"));
db_bind_u64(stmt, atol(rune->unique_id));
db_bind_text(stmt, rune_to_base64(tmpctx, rune));
db_exec_prepared_v2(stmt);
tal_free(stmt);
}

void wallet_rune_insert(struct wallet *wallet, struct rune *rune)
void wallet_rune_insert(struct wallet *wallet, const struct rune *rune)
{
db_rune_insert(wallet->db, rune);
}
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ const char **wallet_get_runes(const tal_t *ctx, struct wallet *wallet);
* @wallet: the wallet to save into
* @rune: the instance to store
*/
void wallet_rune_insert(struct wallet *wallet, struct rune *rune);
void wallet_rune_insert(struct wallet *wallet, const struct rune *rune);

/* Load the runes blacklist */
struct rune_blacklist {
Expand Down

0 comments on commit 496a6a8

Please sign in to comment.