From e2ef44c043fff54eccc8a70b80a479c6c7b7292f Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 19 Jul 2022 17:04:39 +0930 Subject: [PATCH] bkpr: add 'msat' suffix to all msat denominated fields Makes our json schema parsing work as expected. --- plugins/bkpr/bookkeeper.c | 14 +++++++------- plugins/bkpr/chain_event.c | 4 ++-- plugins/bkpr/channel_event.c | 6 +++--- plugins/bkpr/channelsapy.c | 20 ++++++++++---------- plugins/bkpr/incomestmt.c | 4 ++-- plugins/bkpr/onchain_fee.c | 4 ++-- tests/test_bookkeeper.py | 32 ++++++++++++++++---------------- tests/test_pay.py | 4 ++-- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c index 8c2a79208..60535373f 100644 --- a/plugins/bkpr/bookkeeper.c +++ b/plugins/bkpr/bookkeeper.c @@ -280,10 +280,10 @@ static struct command_result *json_inspect(struct command *cmd, fee_sum = find_sum_for_txid(fee_sums, set->txid); if (fee_sum) - json_add_amount_msat_only(res, "fees_paid", + json_add_amount_msat_only(res, "fees_paid_msat", fee_sum->fees_paid); else - json_add_amount_msat_only(res, "fees_paid", + json_add_amount_msat_only(res, "fees_paid_msat", AMOUNT_MSAT(0)); json_array_start(res, "outputs"); @@ -311,9 +311,9 @@ static struct command_result *json_inspect(struct command *cmd, json_add_num(res, "outnum", ev->outpoint.n); json_add_string(res, "output_tag", ev->tag); - json_add_amount_msat_only(res, "output_value", + json_add_amount_msat_only(res, "output_value_msat", ev->output_value); - json_add_amount_msat_only(res, "credit", + json_add_amount_msat_only(res, "credit_msat", ev->credit); json_add_string(res, "currency", ev->currency); if (ev->origin_acct) @@ -328,7 +328,7 @@ static struct command_result *json_inspect(struct command *cmd, ev->acct_name); json_add_num(res, "outnum", ev->outpoint.n); - json_add_amount_msat_only(res, "output_value", + json_add_amount_msat_only(res, "output_value_msat", ev->output_value); json_add_string(res, "currency", ev->currency); @@ -336,7 +336,7 @@ static struct command_result *json_inspect(struct command *cmd, json_add_string(res, "spend_tag", ev->tag); json_add_txid(res, "spending_txid", ev->spending_txid); - json_add_amount_msat_only(res, "debit", ev->debit); + json_add_amount_msat_only(res, "debit_msat", ev->debit); if (ev->payment_id) json_add_sha256(res, "payment_id", ev->payment_id); @@ -499,7 +499,7 @@ static struct command_result *json_list_balances(struct command *cmd, json_array_start(res, "balances"); for (size_t j = 0; j < tal_count(balances); j++) { json_object_start(res, NULL); - json_add_amount_msat_only(res, "balance", + json_add_amount_msat_only(res, "balance_msat", balances[j]->balance); json_add_string(res, "coin_type", balances[j]->currency); diff --git a/plugins/bkpr/chain_event.c b/plugins/bkpr/chain_event.c index 9b055782e..633aedb1d 100644 --- a/plugins/bkpr/chain_event.c +++ b/plugins/bkpr/chain_event.c @@ -11,8 +11,8 @@ void json_add_chain_event(struct json_stream *out, struct chain_event *ev) json_add_string(out, "origin", ev->origin_acct); json_add_string(out, "type", "chain"); json_add_string(out, "tag", ev->tag); - json_add_amount_msat_only(out, "credit", ev->credit); - json_add_amount_msat_only(out, "debit", ev->debit); + json_add_amount_msat_only(out, "credit_msat", ev->credit); + json_add_amount_msat_only(out, "debit_msat", ev->debit); json_add_string(out, "currency", ev->currency); json_add_outpoint(out, "outpoint", &ev->outpoint); diff --git a/plugins/bkpr/channel_event.c b/plugins/bkpr/channel_event.c index 58ca871d0..ca71f9f67 100644 --- a/plugins/bkpr/channel_event.c +++ b/plugins/bkpr/channel_event.c @@ -37,10 +37,10 @@ void json_add_channel_event(struct json_stream *out, json_add_string(out, "account", ev->acct_name); json_add_string(out, "type", "channel"); json_add_string(out, "tag", ev->tag); - json_add_amount_msat_only(out, "credit", ev->credit); - json_add_amount_msat_only(out, "debit", ev->debit); + json_add_amount_msat_only(out, "credit_msat", ev->credit); + json_add_amount_msat_only(out, "debit_msat", ev->debit); if (!amount_msat_zero(ev->fees)) - json_add_amount_msat_only(out, "fees", ev->fees); + json_add_amount_msat_only(out, "fees_msat", ev->fees); json_add_string(out, "currency", ev->currency); if (ev->payment_id) json_add_sha256(out, "payment_id", ev->payment_id); diff --git a/plugins/bkpr/channelsapy.c b/plugins/bkpr/channelsapy.c index 429fbffcb..bbf17c121 100644 --- a/plugins/bkpr/channelsapy.c +++ b/plugins/bkpr/channelsapy.c @@ -301,21 +301,21 @@ void json_add_channel_apy(struct json_stream *res, json_add_string(res, "account", apy->acct_name); - json_add_amount_msat_only(res, "routed_out", apy->routed_out); - json_add_amount_msat_only(res, "routed_in", apy->routed_in); - json_add_amount_msat_only(res, "lease_fee_paid", apy->lease_out); - json_add_amount_msat_only(res, "lease_fee_earned", apy->lease_in); - json_add_amount_msat_only(res, "pushed_out", apy->push_out); - json_add_amount_msat_only(res, "pushed_in", apy->push_in); + json_add_amount_msat_only(res, "routed_out_msat", apy->routed_out); + json_add_amount_msat_only(res, "routed_in_msat", apy->routed_in); + json_add_amount_msat_only(res, "lease_fee_paid_msat", apy->lease_out); + json_add_amount_msat_only(res, "lease_fee_earned_msat", apy->lease_in); + json_add_amount_msat_only(res, "pushed_out_msat", apy->push_out); + json_add_amount_msat_only(res, "pushed_in_msat", apy->push_in); - json_add_amount_msat_only(res, "our_start_balance", apy->our_start_bal); - json_add_amount_msat_only(res, "channel_start_balance", + json_add_amount_msat_only(res, "our_start_balance_msat", apy->our_start_bal); + json_add_amount_msat_only(res, "channel_start_balance_msat", apy->total_start_bal); ok = amount_msat_add(&total_fees, apy->fees_in, apy->fees_out); assert(ok); - json_add_amount_msat_only(res, "fees_out", apy->fees_out); - json_add_amount_msat_only(res, "fees_in", apy->fees_in); + json_add_amount_msat_only(res, "fees_out_msat", apy->fees_out); + json_add_amount_msat_only(res, "fees_in_msat", apy->fees_in); /* utilization (out): routed_out/total_balance */ assert(!amount_msat_zero(apy->total_start_bal)); diff --git a/plugins/bkpr/incomestmt.c b/plugins/bkpr/incomestmt.c index fcc529c6d..0a2eab100 100644 --- a/plugins/bkpr/incomestmt.c +++ b/plugins/bkpr/incomestmt.c @@ -392,8 +392,8 @@ void json_add_income_event(struct json_stream *out, struct income_event *ev) json_object_start(out, NULL); json_add_string(out, "account", ev->acct_name); json_add_string(out, "tag", ev->tag); - json_add_amount_msat_only(out, "credit", ev->credit); - json_add_amount_msat_only(out, "debit", ev->debit); + json_add_amount_msat_only(out, "credit_msat", ev->credit); + json_add_amount_msat_only(out, "debit_msat", ev->debit); json_add_string(out, "currency", ev->currency); json_add_u64(out, "timestamp", ev->timestamp); diff --git a/plugins/bkpr/onchain_fee.c b/plugins/bkpr/onchain_fee.c index 57c1002fb..b4667c14b 100644 --- a/plugins/bkpr/onchain_fee.c +++ b/plugins/bkpr/onchain_fee.c @@ -10,8 +10,8 @@ void json_add_onchain_fee(struct json_stream *out, json_add_string(out, "account", fee->acct_name); json_add_string(out, "type", "onchain_fee"); json_add_string(out, "tag", "onchain_fee"); - json_add_amount_msat_only(out, "credit", fee->credit); - json_add_amount_msat_only(out, "debit", fee->debit); + json_add_amount_msat_only(out, "credit_msat", fee->credit); + json_add_amount_msat_only(out, "debit_msat", fee->debit); json_add_string(out, "currency", fee->currency); json_add_u64(out, "timestamp", fee->timestamp); json_add_txid(out, "txid", &fee->txid); diff --git a/tests/test_bookkeeper.py b/tests/test_bookkeeper.py index 026be33db..08ecd74a1 100644 --- a/tests/test_bookkeeper.py +++ b/tests/test_bookkeeper.py @@ -56,7 +56,7 @@ def test_bookkeeping_closing_trimmed_htlcs(node_factory, bitcoind, executor): fees = find_tags(evs, 'onchain_fee') close_fee = [e for e in fees if e['txid'] == close['txid']] assert len(close_fee) == 1 - assert Millisatoshi(close_fee[0]['credit']) + Millisatoshi(delayed_to['credit']) == Millisatoshi(close['debit']) + assert close_fee[0]['credit_msat'] + delayed_to['credit_msat'] == close['debit_msat'] # l2's fees should equal the trimmed htlc out evs = l2.rpc.listaccountevents()['events'] @@ -66,8 +66,8 @@ def test_bookkeeping_closing_trimmed_htlcs(node_factory, bitcoind, executor): close_fee = [e for e in fees if e['txid'] == close['txid']] assert len(close_fee) == 1 # sent htlc was too small, we lose it, rounded up to nearest sat - assert close_fee[0]['credit'] == '101000msat' - assert Millisatoshi(close_fee[0]['credit']) + Millisatoshi(deposit['credit']) == Millisatoshi(close['debit']) + assert close_fee[0]['credit_msat'] == Millisatoshi('101000msat') + assert close_fee[0]['credit_msat'] + deposit['credit_msat'] == close['debit_msat'] @unittest.skipIf(TEST_NETWORK != 'regtest', "fixme: broadcast fails, dusty") @@ -96,7 +96,7 @@ def test_bookkeeping_closing_subsat_htlcs(node_factory, bitcoind, chainparams): fees = find_tags(evs, 'onchain_fee') close_fee = [e for e in fees if e['txid'] == close['txid']] assert len(close_fee) == 1 - assert Millisatoshi(close_fee[0]['credit']) + Millisatoshi(delayed_to['credit']) == Millisatoshi(close['debit']) + assert close_fee[0]['credit_msat'] + delayed_to['credit_msat'] == close['debit_msat'] evs = l2.rpc.listaccountevents()['events'] close = find_first_tag(evs, 'channel_close') @@ -105,8 +105,8 @@ def test_bookkeeping_closing_subsat_htlcs(node_factory, bitcoind, chainparams): close_fee = [e for e in fees if e['txid'] == close['txid']] assert len(close_fee) == 1 # too small to fit, we lose them as miner fees - assert close_fee[0]['credit'] == '333msat' - assert Millisatoshi(close_fee[0]['credit']) + Millisatoshi(deposit['credit']) == Millisatoshi(close['debit']) + assert close_fee[0]['credit_msat'] == Millisatoshi('333msat') + assert close_fee[0]['credit_msat'] + deposit['credit_msat'] == close['debit_msat'] @unittest.skipIf(TEST_NETWORK != 'regtest', "External wallet support doesn't work with elements yet.") @@ -141,15 +141,15 @@ def test_bookkeeping_external_withdraws(node_factory, bitcoind): for inc in incomes: assert inc['account'] == 'wallet' assert inc['tag'] == 'deposit' - assert Millisatoshi(inc['credit']) == amount_msat + assert inc['credit_msat'] == amount_msat # The event should show up in the 'listaccountevents' however events = l1.rpc.listaccountevents()['events'] assert len(events) == 3 external = [e for e in events if e['account'] == 'external'][0] - assert Millisatoshi(external['credit']) == Millisatoshi(amount // 2 * 1000) + assert external['credit_msat'] == Millisatoshi(amount // 2 * 1000) btc_balance = only_one(only_one(l1.rpc.listbalances()['accounts'])['balances']) - assert Millisatoshi(btc_balance['balance']) == amount_msat * 2 + assert btc_balance['balance_msat'] == amount_msat * 2 # Restart the node, issues a balance snapshot # If we were counting these incorrectly, @@ -166,7 +166,7 @@ def test_bookkeeping_external_withdraws(node_factory, bitcoind): # the wallet balance should be unchanged btc_balance = only_one(only_one(l1.rpc.listbalances()['accounts'])['balances']) - assert Millisatoshi(btc_balance['balance']) == amount_msat * 2 + assert btc_balance['balance_msat'] == amount_msat * 2 # ok now we mine a block bitcoind.generate_block(1) @@ -177,16 +177,16 @@ def test_bookkeeping_external_withdraws(node_factory, bitcoind): incomes = l1.rpc.listincome()['income_events'] # 2 wallet deposits, 1 wallet withdrawal, 1 onchain_fee assert len(incomes) == 4 - withdraw_amt = Millisatoshi(find_tags(incomes, 'withdrawal')[0]['debit']) + withdraw_amt = find_tags(incomes, 'withdrawal')[0]['debit_msat'] assert withdraw_amt == Millisatoshi(amount // 2 * 1000) fee_events = find_tags(incomes, 'onchain_fee') assert len(fee_events) == 1 - fees = Millisatoshi(fee_events[0]['debit']) + fees = fee_events[0]['debit_msat'] # wallet balance is decremented now btc_balance = only_one(only_one(l1.rpc.listbalances()['accounts'])['balances']) - assert Millisatoshi(btc_balance['balance']) == amount_msat * 2 - withdraw_amt - fees + assert btc_balance['balance_msat'] == amount_msat * 2 - withdraw_amt - fees @unittest.skipIf(TEST_NETWORK != 'regtest', "External wallet support doesn't work with elements yet.") @@ -233,7 +233,7 @@ def test_bookkeeping_external_withdraw_missing(node_factory, bitcoind): # the wallet balance should be unchanged btc_balance = only_one(only_one(l1.rpc.listbalances()['accounts'])['balances']) - assert Millisatoshi(btc_balance['balance']) == amount_msat * 2 + assert btc_balance['balance_msat'] == amount_msat * 2 # ok now we mine a block bitcoind.generate_block(1) @@ -248,12 +248,12 @@ def test_bookkeeping_external_withdraw_missing(node_factory, bitcoind): fee_events = find_tags(incomes, 'onchain_fee') assert len(fee_events) == 1 - fees = Millisatoshi(fee_events[0]['debit']) + fees = fee_events[0]['debit_msat'] assert fees > Millisatoshi(amount // 2 * 1000) # wallet balance is decremented now bal = only_one(only_one(l1.rpc.listbalances()['accounts'])['balances']) - assert Millisatoshi(bal['balance']) == amount_msat * 2 - fees + assert bal['balance_msat'] == amount_msat * 2 - fees @unittest.skipIf(TEST_NETWORK != 'regtest', "External wallet support doesn't work with elements yet.") diff --git a/tests/test_pay.py b/tests/test_pay.py index dc4bd15fe..7a5556250 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -1314,9 +1314,9 @@ def test_forward_pad_fees_and_cltv(node_factory, bitcoind): # the balance on l3 should equal the invoice bal = only_one(only_one(l3.rpc.listbalances()['accounts'])['balances'])['balance'] assert incomes[0]['tag'] == 'invoice' - assert bal == incomes[0]['debit'] + assert Millisatoshi(bal) == incomes[0]['debit_msat'] inve = only_one([e for e in l1.rpc.listaccountevents()['events'] if e['tag'] == 'invoice']) - assert Millisatoshi(inve['debit']) == Millisatoshi(incomes[0]['debit']) + Millisatoshi(incomes[1]['debit']) + assert inve['debit_msat'] == incomes[0]['debit_msat'] + incomes[1]['debit_msat'] @pytest.mark.developer("needs DEVELOPER=1 for dev_ignore_htlcs")