From e286c38c6ff66680638384e0c22210ccd86fb49d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 19 Sep 2022 10:19:53 +0930 Subject: [PATCH] wallet: use db_col_scid / db_bind_scid where possible. Without helpers, we were using the u64 functions. Signed-off-by: Rusty Russell --- wallet/wallet.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/wallet/wallet.c b/wallet/wallet.c index 9a457d09f..6d6269678 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1303,14 +1303,14 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm if (!db_col_is_null(stmt, "alias_local")) { alias[LOCAL] = tal(tmpctx, struct short_channel_id); - alias[LOCAL]->u64 = db_col_u64(stmt, "alias_local"); + db_col_scid(stmt, "alias_local", alias[LOCAL]); } else { alias[LOCAL] = NULL; } if (!db_col_is_null(stmt, "alias_remote")) { alias[REMOTE] = tal(tmpctx, struct short_channel_id); - alias[REMOTE]->u64 = db_col_u64(stmt, "alias_remote"); + db_col_scid(stmt, "alias_remote", alias[REMOTE]); } else { alias[REMOTE] = NULL; } @@ -1970,12 +1970,12 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_amount_msat(stmt, 43, &chan->htlc_maximum_msat); if (chan->alias[LOCAL] != NULL) - db_bind_u64(stmt, 44, chan->alias[LOCAL]->u64); + db_bind_scid(stmt, 44, chan->alias[LOCAL]); else db_bind_null(stmt, 44); if (chan->alias[REMOTE] != NULL) - db_bind_u64(stmt, 45, chan->alias[REMOTE]->u64); + db_bind_scid(stmt, 45, chan->alias[REMOTE]); else db_bind_null(stmt, 45); @@ -4393,8 +4393,7 @@ static bool wallet_forwarded_payment_update(struct wallet *w, else db_bind_int(stmt, 5, forward_style_in_db(forward_style)); db_bind_u64(stmt, 6, in->key.id); - db_bind_u64(stmt, 7, - channel_scid_or_local_alias(in->key.channel)->u64); + db_bind_scid(stmt, 7, channel_scid_or_local_alias(in->key.channel)); db_exec_prepared_v2(stmt); changed = db_count_changes(stmt) != 0; tal_free(stmt); @@ -4454,10 +4453,10 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, * the sender used to specify the channel, but that's under * control of the remote end. */ assert(in->key.channel->scid != NULL || in->key.channel->alias[LOCAL]); - db_bind_u64(stmt, 2, channel_scid_or_local_alias(in->key.channel)->u64); + db_bind_scid(stmt, 2, channel_scid_or_local_alias(in->key.channel)); if (scid_out) - db_bind_u64(stmt, 3, scid_out->u64); + db_bind_scid(stmt, 3, scid_out); else db_bind_null(stmt, 3); db_bind_amount_msat(stmt, 4, &in->msat); @@ -4578,7 +4577,7 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, if (chan_in) { // specific in_channel db_bind_int(stmt, 2, 0); - db_bind_u64(stmt, 3, chan_in->u64); + db_bind_scid(stmt, 3, chan_in); } else { // any in_channel db_bind_int(stmt, 2, 1); @@ -4588,7 +4587,7 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, if (chan_out) { // specific out_channel db_bind_int(stmt, 4, 0); - db_bind_u64(stmt, 5, chan_out->u64); + db_bind_scid(stmt, 5, chan_out); } else { // any out_channel db_bind_int(stmt, 4, 1); @@ -4624,11 +4623,10 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, /* FIXME: This now requires complex join to determine! */ cur->payment_hash = NULL; - cur->channel_in.u64 = db_col_u64(stmt, "in_channel_scid"); + db_col_scid(stmt, "in_channel_scid", &cur->channel_in); if (!db_col_is_null(stmt, "out_channel_scid")) { - cur->channel_out.u64 - = db_col_u64(stmt, "out_channel_scid"); + db_col_scid(stmt, "out_channel_scid", &cur->channel_out); } else { assert(cur->status == FORWARD_LOCAL_FAILED); cur->channel_out.u64 = 0;