mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
db: add optional column string helper, and make db_col amounts return sat/msat.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
adee07125a
commit
b6d347a6d3
6 changed files with 87 additions and 77 deletions
|
@ -319,6 +319,17 @@ char *db_col_strdup(const tal_t *ctx,
|
|||
return tal_strdup(ctx, (char *)stmt->db->config->column_text_fn(stmt, col));
|
||||
}
|
||||
|
||||
char *db_col_strdup_optional(const tal_t *ctx,
|
||||
struct db_stmt *stmt,
|
||||
const char *colname)
|
||||
{
|
||||
size_t col = db_query_colnum(stmt, colname);
|
||||
if (db_column_is_null(stmt, col))
|
||||
return NULL;
|
||||
|
||||
return tal_strdup(ctx, (char *)stmt->db->config->column_text_fn(stmt, col));
|
||||
}
|
||||
|
||||
void db_col_preimage(struct db_stmt *stmt, const char *colname,
|
||||
struct preimage *preimage)
|
||||
{
|
||||
|
@ -516,15 +527,14 @@ void db_col_amount_msat_or_default(struct db_stmt *stmt,
|
|||
msat->millisatoshis = db_col_u64(stmt, colname); /* Raw: low level function */
|
||||
}
|
||||
|
||||
void db_col_amount_msat(struct db_stmt *stmt, const char *colname,
|
||||
struct amount_msat *msat)
|
||||
struct amount_msat db_col_amount_msat(struct db_stmt *stmt, const char *colname)
|
||||
{
|
||||
msat->millisatoshis = db_col_u64(stmt, colname); /* Raw: low level function */
|
||||
return amount_msat(db_col_u64(stmt, colname));
|
||||
}
|
||||
|
||||
void db_col_amount_sat(struct db_stmt *stmt, const char *colname, struct amount_sat *sat)
|
||||
struct amount_sat db_col_amount_sat(struct db_stmt *stmt, const char *colname)
|
||||
{
|
||||
sat->satoshis = db_col_u64(stmt, colname); /* Raw: low level function */
|
||||
return amount_sat(db_col_u64(stmt, colname));
|
||||
}
|
||||
|
||||
struct json_escape *db_col_json_escape(const tal_t *ctx,
|
||||
|
|
|
@ -67,9 +67,13 @@ const void* db_col_blob(struct db_stmt *stmt, const char *colname);
|
|||
char *db_col_strdup(const tal_t *ctx,
|
||||
struct db_stmt *stmt,
|
||||
const char *colname);
|
||||
/* string or NULL */
|
||||
char *db_col_strdup_optional(const tal_t *ctx,
|
||||
struct db_stmt *stmt,
|
||||
const char *colname);
|
||||
void db_col_preimage(struct db_stmt *stmt, const char *colname, struct preimage *preimage);
|
||||
void db_col_amount_msat(struct db_stmt *stmt, const char *colname, struct amount_msat *msat);
|
||||
void db_col_amount_sat(struct db_stmt *stmt, const char *colname, struct amount_sat *sat);
|
||||
struct amount_msat db_col_amount_msat(struct db_stmt *stmt, const char *colname);
|
||||
struct amount_sat db_col_amount_sat(struct db_stmt *stmt, const char *colname);
|
||||
struct json_escape *db_col_json_escape(const tal_t *ctx, struct db_stmt *stmt, const char *colname);
|
||||
void db_col_sha256(struct db_stmt *stmt, const char *colname, struct sha256 *sha);
|
||||
void db_col_sha256d(struct db_stmt *stmt, const char *colname, struct sha256_double *shad);
|
||||
|
|
|
@ -32,9 +32,9 @@ static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *st
|
|||
|
||||
e->tag = db_col_strdup(e, stmt, "e.tag");
|
||||
|
||||
db_col_amount_msat(stmt, "e.credit", &e->credit);
|
||||
db_col_amount_msat(stmt, "e.debit", &e->debit);
|
||||
db_col_amount_msat(stmt, "e.output_value", &e->output_value);
|
||||
e->credit = db_col_amount_msat(stmt, "e.credit");
|
||||
e->debit = db_col_amount_msat(stmt, "e.debit");
|
||||
e->output_value = db_col_amount_msat(stmt, "e.output_value");
|
||||
|
||||
e->currency = db_col_strdup(e, stmt, "e.currency");
|
||||
e->timestamp = db_col_u64(stmt, "e.timestamp");
|
||||
|
@ -96,9 +96,9 @@ static struct channel_event *stmt2channel_event(const tal_t *ctx, struct db_stmt
|
|||
|
||||
e->tag = db_col_strdup(e, stmt, "e.tag");
|
||||
|
||||
db_col_amount_msat(stmt, "e.credit", &e->credit);
|
||||
db_col_amount_msat(stmt, "e.debit", &e->debit);
|
||||
db_col_amount_msat(stmt, "e.fees", &e->fees);
|
||||
e->credit = db_col_amount_msat(stmt, "e.credit");
|
||||
e->debit = db_col_amount_msat(stmt, "e.debit");
|
||||
e->fees = db_col_amount_msat(stmt, "e.fees");
|
||||
|
||||
e->currency = db_col_strdup(e, stmt, "e.currency");
|
||||
if (!db_col_is_null(stmt, "e.payment_id")) {
|
||||
|
@ -131,8 +131,8 @@ static struct rebalance *stmt2rebalance(const tal_t *ctx, struct db_stmt *stmt)
|
|||
r->out_ev_id = db_col_u64(stmt, "out_e.id");
|
||||
r->in_acct_name = db_col_strdup(r, stmt, "in_acct.name");
|
||||
r->out_acct_name = db_col_strdup(r, stmt, "out_acct.name");
|
||||
db_col_amount_msat(stmt, "in_e.credit", &r->rebal_msat);
|
||||
db_col_amount_msat(stmt, "out_e.fees", &r->fee_msat);
|
||||
r->rebal_msat = db_col_amount_msat(stmt, "in_e.credit");
|
||||
r->fee_msat = db_col_amount_msat(stmt, "out_e.fees");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -289,8 +289,8 @@ struct fee_sum **calculate_onchain_fee_sums(const tal_t *ctx, struct db *db)
|
|||
sum->acct_db_id = db_col_u64(stmt, "of.account_id");
|
||||
sum->acct_name = db_col_strdup(sum, stmt, "a.name");
|
||||
sum->currency = db_col_strdup(sum, stmt, "of.currency");
|
||||
db_col_amount_msat(stmt, "credit", &sum->fees_paid);
|
||||
db_col_amount_msat(stmt, "debit", &debit);
|
||||
sum->fees_paid = db_col_amount_msat(stmt, "credit");
|
||||
debit = db_col_amount_msat(stmt, "debit");
|
||||
|
||||
ok = amount_msat_sub(&sum->fees_paid, sum->fees_paid,
|
||||
debit);
|
||||
|
@ -359,8 +359,8 @@ struct fee_sum **find_account_onchain_fees(const tal_t *ctx,
|
|||
sum->txid = tal(sum, struct bitcoin_txid);
|
||||
db_col_txid(stmt, "txid", sum->txid);
|
||||
|
||||
db_col_amount_msat(stmt, "credit", &sum->fees_paid);
|
||||
db_col_amount_msat(stmt, "debit", &amt);
|
||||
sum->fees_paid = db_col_amount_msat(stmt, "credit");
|
||||
amt = db_col_amount_msat(stmt, "debit");
|
||||
ok = amount_msat_sub(&sum->fees_paid, sum->fees_paid, amt);
|
||||
assert(ok);
|
||||
tal_arr_expand(&sums, sum);
|
||||
|
@ -818,8 +818,8 @@ char *account_get_balance(const tal_t *ctx,
|
|||
bal = tal(*balances, struct acct_balance);
|
||||
|
||||
bal->currency = db_col_strdup(bal, stmt, "ce.currency");
|
||||
db_col_amount_msat(stmt, "credit", &bal->credit);
|
||||
db_col_amount_msat(stmt, "debit", &bal->debit);
|
||||
bal->credit = db_col_amount_msat(stmt, "credit");
|
||||
bal->debit = db_col_amount_msat(stmt, "debit");
|
||||
tal_arr_expand(balances, bal);
|
||||
|
||||
if (account_exists)
|
||||
|
@ -862,13 +862,13 @@ char *account_get_balance(const tal_t *ctx,
|
|||
tal_arr_expand(balances, bal);
|
||||
}
|
||||
|
||||
db_col_amount_msat(stmt, "credit", &amt);
|
||||
amt = db_col_amount_msat(stmt, "credit");
|
||||
if (!amount_msat_add(&bal->credit, bal->credit, amt)) {
|
||||
tal_free(stmt);
|
||||
return "overflow adding channel_event credits";
|
||||
}
|
||||
|
||||
db_col_amount_msat(stmt, "debit", &amt);
|
||||
amt = db_col_amount_msat(stmt, "debit");
|
||||
if (!amount_msat_add(&bal->debit, bal->debit, amt)) {
|
||||
tal_free(stmt);
|
||||
return "overflow adding channel_event debits";
|
||||
|
@ -992,8 +992,8 @@ static struct onchain_fee *stmt2onchain_fee(const tal_t *ctx,
|
|||
of->acct_db_id = db_col_u64(stmt, "of.account_id");
|
||||
of->acct_name = db_col_strdup(of, stmt, "a.name");
|
||||
db_col_txid(stmt, "of.txid", &of->txid);
|
||||
db_col_amount_msat(stmt, "of.credit", &of->credit);
|
||||
db_col_amount_msat(stmt, "of.debit", &of->debit);
|
||||
of->credit = db_col_amount_msat(stmt, "of.credit");
|
||||
of->debit = db_col_amount_msat(stmt, "of.debit");
|
||||
of->currency = db_col_strdup(of, stmt, "of.currency");
|
||||
of->timestamp = db_col_u64(stmt, "of.timestamp");
|
||||
of->update_count = db_col_int(stmt, "of.update_count");
|
||||
|
@ -1490,8 +1490,8 @@ static void insert_chain_fees_diff(struct db *db,
|
|||
update_count = 0;
|
||||
while (db_step(stmt)) {
|
||||
update_count = db_col_int(stmt, "update_count");
|
||||
db_col_amount_msat(stmt, "credit", &credit);
|
||||
db_col_amount_msat(stmt, "debit", &debit);
|
||||
credit = db_col_amount_msat(stmt, "credit");
|
||||
debit = db_col_amount_msat(stmt, "debit");
|
||||
|
||||
/* These should apply perfectly, as we sorted them by
|
||||
* insert order */
|
||||
|
|
|
@ -1357,7 +1357,7 @@ migrate_inflight_last_tx_to_psbt(struct lightningd *ld, struct db *db)
|
|||
continue;
|
||||
}
|
||||
db_col_node_id(stmt, "p.node_id", &peer_id);
|
||||
db_col_amount_sat(stmt, "inflight.funding_satoshi", &funding_sat);
|
||||
funding_sat = db_col_amount_sat(stmt, "inflight.funding_satoshi");
|
||||
db_col_pubkey(stmt, "c.fundingkey_remote", &remote_funding_pubkey);
|
||||
db_col_txid(stmt, "inflight.funding_tx_id", &funding_txid);
|
||||
|
||||
|
@ -1458,7 +1458,7 @@ void migrate_last_tx_to_psbt(struct lightningd *ld, struct db *db)
|
|||
}
|
||||
|
||||
db_col_node_id(stmt, "p.node_id", &peer_id);
|
||||
db_col_amount_sat(stmt, "c.funding_satoshi", &funding_sat);
|
||||
funding_sat = db_col_amount_sat(stmt, "c.funding_satoshi");
|
||||
db_col_pubkey(stmt, "c.fundingkey_remote", &remote_funding_pubkey);
|
||||
|
||||
get_channel_basepoints(ld, &peer_id, cdb_id,
|
||||
|
|
|
@ -88,12 +88,17 @@ static struct invoice_details *wallet_stmt2invoice_details(const tal_t *ctx,
|
|||
|
||||
dtl->label = db_col_json_escape(dtl, stmt, "label");
|
||||
|
||||
dtl->msat = db_col_optional(dtl, stmt, "msatoshi", amount_msat);
|
||||
if (db_col_is_null(stmt, "msatoshi"))
|
||||
dtl->msat = NULL;
|
||||
else {
|
||||
dtl->msat = tal(dtl, struct amount_msat);
|
||||
*dtl->msat = db_col_amount_msat(stmt, "msatoshi");
|
||||
}
|
||||
dtl->expiry_time = db_col_u64(stmt, "expiry_time");
|
||||
|
||||
if (dtl->state == PAID) {
|
||||
dtl->pay_index = db_col_u64(stmt, "pay_index");
|
||||
db_col_amount_msat(stmt, "msatoshi_received", &dtl->received);
|
||||
dtl->received = db_col_amount_msat(stmt, "msatoshi_received");
|
||||
dtl->paid_timestamp = db_col_u64(stmt, "paid_timestamp");
|
||||
} else {
|
||||
db_col_ignore(stmt, "pay_index");
|
||||
|
@ -102,13 +107,7 @@ static struct invoice_details *wallet_stmt2invoice_details(const tal_t *ctx,
|
|||
}
|
||||
|
||||
dtl->invstring = db_col_strdup(dtl, stmt, "bolt11");
|
||||
|
||||
if (!db_col_is_null(stmt, "description"))
|
||||
dtl->description = db_col_strdup(dtl, stmt,
|
||||
"description");
|
||||
else
|
||||
dtl->description = NULL;
|
||||
|
||||
dtl->description = db_col_strdup_optional(dtl, stmt, "description");
|
||||
dtl->features = db_col_arr(dtl, stmt, "features", u8);
|
||||
dtl->local_offer_id = db_col_optional(dtl, stmt, "local_offer_id", sha256);
|
||||
dtl->created_index = db_col_u64(stmt, "id");
|
||||
|
|
|
@ -211,7 +211,7 @@ static struct utxo *wallet_stmt2output(const tal_t *ctx, struct db_stmt *stmt)
|
|||
u32 *blockheight, *spendheight;
|
||||
db_col_txid(stmt, "prev_out_tx", &utxo->outpoint.txid);
|
||||
utxo->outpoint.n = db_col_int(stmt, "prev_out_index");
|
||||
db_col_amount_sat(stmt, "value", &utxo->amount);
|
||||
utxo->amount = db_col_amount_sat(stmt, "value");
|
||||
utxo->is_p2sh = db_col_int(stmt, "type") == p2sh_wpkh;
|
||||
utxo->status = db_col_int(stmt, "status");
|
||||
utxo->keyindex = db_col_int(stmt, "keyindex");
|
||||
|
@ -1235,8 +1235,8 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
|||
|
||||
db_col_txid(stmt, "funding_tx_id", &funding.txid);
|
||||
funding.n = db_col_int(stmt, "funding_tx_outnum"),
|
||||
db_col_amount_sat(stmt, "funding_satoshi", &funding_sat);
|
||||
db_col_amount_sat(stmt, "our_funding_satoshi", &our_funding_sat);
|
||||
funding_sat = db_col_amount_sat(stmt, "funding_satoshi");
|
||||
our_funding_sat = db_col_amount_sat(stmt, "our_funding_satoshi");
|
||||
if (!db_col_signature(stmt, "last_sig", &last_sig.s))
|
||||
return NULL;
|
||||
|
||||
|
@ -1248,8 +1248,8 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
|||
lease_chan_max_msat = db_col_u64(stmt, "lease_chan_max_msat");
|
||||
lease_chan_max_ppt = db_col_int(stmt, "lease_chan_max_ppt");
|
||||
lease_blockheight_start = db_col_int(stmt, "lease_blockheight_start");
|
||||
db_col_amount_msat(stmt, "lease_fee", &lease_fee);
|
||||
db_col_amount_sat(stmt, "lease_satoshi", &lease_amt);
|
||||
lease_fee = db_col_amount_msat(stmt, "lease_fee");
|
||||
lease_amt = db_col_amount_sat(stmt, "lease_satoshi");
|
||||
} else {
|
||||
lease_commit_sig = NULL;
|
||||
lease_chan_max_msat = 0;
|
||||
|
@ -1356,16 +1356,13 @@ static bool wallet_channel_config_load(struct wallet *w, const u64 id,
|
|||
return false;
|
||||
|
||||
cc->id = id;
|
||||
db_col_amount_sat(stmt, "dust_limit_satoshis", &cc->dust_limit);
|
||||
db_col_amount_msat(stmt, "max_htlc_value_in_flight_msat",
|
||||
&cc->max_htlc_value_in_flight);
|
||||
db_col_amount_sat(stmt, "channel_reserve_satoshis",
|
||||
&cc->channel_reserve);
|
||||
db_col_amount_msat(stmt, "htlc_minimum_msat", &cc->htlc_minimum);
|
||||
cc->dust_limit = db_col_amount_sat(stmt, "dust_limit_satoshis");
|
||||
cc->max_htlc_value_in_flight = db_col_amount_msat(stmt, "max_htlc_value_in_flight_msat");
|
||||
cc->channel_reserve = db_col_amount_sat(stmt, "channel_reserve_satoshis");
|
||||
cc->htlc_minimum = db_col_amount_msat(stmt, "htlc_minimum_msat");
|
||||
cc->to_self_delay = db_col_int(stmt, "to_self_delay");
|
||||
cc->max_accepted_htlcs = db_col_int(stmt, "max_accepted_htlcs");
|
||||
db_col_amount_msat(stmt, "max_dust_htlc_exposure_msat",
|
||||
&cc->max_dust_htlc_exposure_msat);
|
||||
cc->max_dust_htlc_exposure_msat = db_col_amount_msat(stmt, "max_dust_htlc_exposure_msat");
|
||||
tal_free(stmt);
|
||||
return ok;
|
||||
}
|
||||
|
@ -1528,14 +1525,14 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
|||
= db_col_int(stmt, "shutdown_wrong_outnum");
|
||||
}
|
||||
|
||||
db_col_amount_sat(stmt, "funding_satoshi", &funding_sat);
|
||||
db_col_amount_sat(stmt, "our_funding_satoshi", &our_funding_sat);
|
||||
db_col_amount_msat(stmt, "push_msatoshi", &push_msat);
|
||||
db_col_amount_msat(stmt, "msatoshi_local", &our_msat);
|
||||
db_col_amount_msat(stmt, "msatoshi_to_us_min", &msat_to_us_min);
|
||||
db_col_amount_msat(stmt, "msatoshi_to_us_max", &msat_to_us_max);
|
||||
db_col_amount_msat(stmt, "htlc_minimum_msat", &htlc_minimum_msat);
|
||||
db_col_amount_msat(stmt, "htlc_maximum_msat", &htlc_maximum_msat);
|
||||
funding_sat = db_col_amount_sat(stmt, "funding_satoshi");
|
||||
our_funding_sat = db_col_amount_sat(stmt, "our_funding_satoshi");
|
||||
push_msat = db_col_amount_msat(stmt, "push_msatoshi");
|
||||
our_msat = db_col_amount_msat(stmt, "msatoshi_local");
|
||||
msat_to_us_min = db_col_amount_msat(stmt, "msatoshi_to_us_min");
|
||||
msat_to_us_max = db_col_amount_msat(stmt, "msatoshi_to_us_max");
|
||||
htlc_minimum_msat = db_col_amount_msat(stmt, "htlc_minimum_msat");
|
||||
htlc_maximum_msat = db_col_amount_msat(stmt, "htlc_maximum_msat");
|
||||
ignore_fee_limits = db_col_int(stmt, "ignore_fee_limits");
|
||||
|
||||
if (!db_col_is_null(stmt, "lease_commit_sig")) {
|
||||
|
@ -1656,11 +1653,11 @@ static struct closed_channel *wallet_stmt2closed_channel(const tal_t *ctx,
|
|||
cc->next_htlc_id = db_col_u64(stmt, "next_htlc_id");
|
||||
db_col_sha256d(stmt, "funding_tx_id", &cc->funding.txid.shad);
|
||||
cc->funding.n = db_col_int(stmt, "funding_tx_outnum");
|
||||
db_col_amount_sat(stmt, "funding_satoshi", &cc->funding_sats);
|
||||
db_col_amount_msat(stmt, "push_msatoshi", &cc->push);
|
||||
db_col_amount_msat(stmt, "msatoshi_local", &cc->our_msat);
|
||||
db_col_amount_msat(stmt, "msatoshi_to_us_min", &cc->msat_to_us_min);
|
||||
db_col_amount_msat(stmt, "msatoshi_to_us_max", &cc->msat_to_us_max);
|
||||
cc->funding_sats = db_col_amount_sat(stmt, "funding_satoshi");
|
||||
cc->push = db_col_amount_msat(stmt, "push_msatoshi");
|
||||
cc->our_msat = db_col_amount_msat(stmt, "msatoshi_local");
|
||||
cc->msat_to_us_min = db_col_amount_msat(stmt, "msatoshi_to_us_min");
|
||||
cc->msat_to_us_max = db_col_amount_msat(stmt, "msatoshi_to_us_max");
|
||||
/* last_tx is null for stub channels used for recovering funds through
|
||||
* Static channel backups. */
|
||||
if (!db_col_is_null(stmt, "last_tx"))
|
||||
|
@ -2791,7 +2788,7 @@ static bool wallet_stmt2htlc_in(struct channel *channel,
|
|||
in->dbid = db_col_u64(stmt, "id");
|
||||
in->key.id = db_col_u64(stmt, "channel_htlc_id");
|
||||
in->key.channel = channel;
|
||||
db_col_amount_msat(stmt, "msatoshi", &in->msat);
|
||||
in->msat = db_col_amount_msat(stmt, "msatoshi");
|
||||
in->cltv_expiry = db_col_int(stmt, "cltv_expiry");
|
||||
in->hstate = db_col_int(stmt, "hstate");
|
||||
in->status = NULL;
|
||||
|
@ -2864,7 +2861,7 @@ static bool wallet_stmt2htlc_out(struct wallet *wallet,
|
|||
out->dbid = db_col_u64(stmt, "id");
|
||||
out->key.id = db_col_u64(stmt, "channel_htlc_id");
|
||||
out->key.channel = channel;
|
||||
db_col_amount_msat(stmt, "msatoshi", &out->msat);
|
||||
out->msat = db_col_amount_msat(stmt, "msatoshi");
|
||||
out->cltv_expiry = db_col_int(stmt, "cltv_expiry");
|
||||
out->hstate = db_col_int(stmt, "hstate");
|
||||
db_col_sha256(stmt, "payment_hash", &out->payment_hash);
|
||||
|
@ -2889,7 +2886,7 @@ static bool wallet_stmt2htlc_out(struct wallet *wallet,
|
|||
out->failmsg = db_col_arr(out, stmt, "localfailmsg", u8);
|
||||
|
||||
out->in = NULL;
|
||||
db_col_amount_msat(stmt, "fees_msat", &out->fees);
|
||||
out->fees = db_col_amount_msat(stmt, "fees_msat");
|
||||
|
||||
if (!db_col_is_null(stmt, "origin_htlc")) {
|
||||
u64 in_id = db_col_u64(stmt, "origin_htlc");
|
||||
|
@ -3310,7 +3307,7 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
|
|||
payment->status = db_col_int(stmt, "status");
|
||||
payment->destination = db_col_optional(payment, stmt, "destination",
|
||||
node_id);
|
||||
db_col_amount_msat(stmt, "msatoshi", &payment->msatoshi);
|
||||
payment->msatoshi = db_col_amount_msat(stmt, "msatoshi");
|
||||
db_col_sha256(stmt, "payment_hash", &payment->payment_hash);
|
||||
|
||||
payment->timestamp = db_col_int(stmt, "timestamp");
|
||||
|
@ -3339,7 +3336,7 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
|
|||
payment->route_channels = NULL;
|
||||
}
|
||||
|
||||
db_col_amount_msat(stmt, "msatoshi_sent", &payment->msatoshi_sent);
|
||||
payment->msatoshi_sent = db_col_amount_msat(stmt, "msatoshi_sent");
|
||||
|
||||
if (!db_col_is_null(stmt, "description"))
|
||||
payment->label = db_col_strdup(payment, stmt, "description");
|
||||
|
@ -3363,7 +3360,7 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
|
|||
payment->failonion = NULL;
|
||||
|
||||
if (!db_col_is_null(stmt, "total_msat"))
|
||||
db_col_amount_msat(stmt, "total_msat", &payment->total_msat);
|
||||
payment->total_msat = db_col_amount_msat(stmt, "total_msat");
|
||||
else
|
||||
payment->total_msat = AMOUNT_MSAT(0);
|
||||
|
||||
|
@ -4066,7 +4063,7 @@ struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
|||
else
|
||||
op->spendheight = db_col_int(stmt, "spendheight");
|
||||
op->scriptpubkey = db_col_arr(op, stmt, "scriptpubkey", u8);
|
||||
db_col_amount_sat(stmt, "satoshis", &op->sat);
|
||||
op->sat = db_col_amount_sat(stmt, "satoshis");
|
||||
tal_free(stmt);
|
||||
|
||||
return op;
|
||||
|
@ -4553,7 +4550,7 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w)
|
|||
res = db_step(stmt);
|
||||
assert(res);
|
||||
|
||||
db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)", &total);
|
||||
total = db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)");
|
||||
tal_free(stmt);
|
||||
|
||||
deleted = amount_msat(db_get_intvar(w->db, "deleted_forward_fees", 0));
|
||||
|
@ -4653,10 +4650,10 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
|
|||
tal_resize(&results, count+1);
|
||||
struct forwarding *cur = &results[count];
|
||||
cur->status = db_col_int(stmt, "state");
|
||||
db_col_amount_msat(stmt, "in_msatoshi", &cur->msat_in);
|
||||
cur->msat_in = db_col_amount_msat(stmt, "in_msatoshi");
|
||||
|
||||
if (!db_col_is_null(stmt, "out_msatoshi")) {
|
||||
db_col_amount_msat(stmt, "out_msatoshi", &cur->msat_out);
|
||||
cur->msat_out = db_col_amount_msat(stmt, "out_msatoshi");
|
||||
if (!amount_msat_sub(&cur->fee, cur->msat_in, cur->msat_out)) {
|
||||
log_broken(w->log, "Forwarded in %s less than out %s!",
|
||||
type_to_string(tmpctx, struct amount_msat,
|
||||
|
@ -4762,7 +4759,7 @@ bool wallet_forward_delete(struct wallet *w,
|
|||
if (db_step(stmt)) {
|
||||
struct amount_msat deleted;
|
||||
|
||||
db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)", &deleted);
|
||||
deleted = db_col_amount_msat(stmt, "CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)");
|
||||
deleted.millisatoshis += /* Raw: db access */
|
||||
db_get_intvar(w->db, "deleted_forward_fees", 0);
|
||||
db_set_intvar(w->db, "deleted_forward_fees",
|
||||
|
@ -4881,7 +4878,7 @@ struct penalty_base *wallet_penalty_base_load_for_channel(const tal_t *ctx,
|
|||
pb.commitment_num = db_col_u64(stmt, "commitnum");
|
||||
db_col_txid(stmt, "txid", &pb.txid);
|
||||
pb.outnum = db_col_int(stmt, "outnum");
|
||||
db_col_amount_sat(stmt, "amount", &pb.amount);
|
||||
pb.amount = db_col_amount_sat(stmt, "amount");
|
||||
tal_arr_expand(&res, pb);
|
||||
}
|
||||
tal_free(stmt);
|
||||
|
@ -5558,7 +5555,7 @@ struct wallet_htlc_iter *wallet_htlcs_next(struct wallet *w,
|
|||
*owner = REMOTE;
|
||||
else
|
||||
*owner = LOCAL;
|
||||
db_col_amount_msat(iter->stmt, "h.msatoshi", msat);
|
||||
*msat = db_col_amount_msat(iter->stmt, "h.msatoshi");
|
||||
db_col_sha256(iter->stmt, "h.payment_hash", payment_hash);
|
||||
*cltv_expiry = db_col_int(iter->stmt, "h.cltv_expiry");
|
||||
*hstate = db_col_int(iter->stmt, "h.hstate");
|
||||
|
|
Loading…
Add table
Reference in a new issue