From 60bd70be852911ecf174c3dfeb88ab11ae3bf8d4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2022 19:52:10 +0930 Subject: [PATCH] JSON: deprecate printing msat fields as strings. This changes many fields: in non-deprecated mode, they're now raw integers. This was always the intention, but the transition was never completed. Suggested-By: @ShahanaFarooqui Signed-off-by: Rusty Russell Changelog-Changed: JSON-RPC: "_msat" fields can be raw numbers, not "123msat" strings (please handle both!) Changelog-Deprecated: JSON-RPC: "_msat" fields as "123msat" strings (will be only numbers) --- common/json_helpers.c | 7 +++++-- tests/test_misc.py | 2 +- tests/test_pay.py | 4 ++-- tests/test_plugin.py | 18 +++++++++--------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/common/json_helpers.c b/common/json_helpers.c index aaf601435..569b2c107 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -412,8 +412,11 @@ void json_add_amount_msat_only(struct json_stream *result, { if (!deprecated_apis) assert(strends(msatfieldname, "_msat")); - json_add_string(result, msatfieldname, - type_to_string(tmpctx, struct amount_msat, &msat)); + if (deprecated_apis) + json_add_string(result, msatfieldname, + type_to_string(tmpctx, struct amount_msat, &msat)); + else + json_add_u64(result, msatfieldname, msat.millisatoshis); /* Raw: low-level helper */ } void json_add_amount_sat_compat(struct json_stream *result, diff --git a/tests/test_misc.py b/tests/test_misc.py index e2ac16fd7..7b67fba49 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -969,7 +969,7 @@ def test_cli(node_factory): ' "invoices": [', ' {', r' "label": "l\"[]{}",', - ' "amount_msat": "123000msat",', + ' "amount_msat": 123000,', ' "status": "unpaid",', r' "description": "d\"[]{}",', ' }', diff --git a/tests/test_pay.py b/tests/test_pay.py index 0e701527d..d3ec311dd 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3097,8 +3097,8 @@ def test_partial_payment(node_factory, bitcoind, executor): for i in range(2): line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion') assert "'type': 'tlv'" in line - assert "'forward_msat': '499msat'" in line or "'forward_msat': '501msat'" in line - assert "'total_msat': '1000msat'" in line + assert "'forward_msat': 499" in line or "'forward_msat': 501" in line + assert "'total_msat': 1000" in line assert "'payment_secret': '{}'".format(paysecret) in line pay = only_one(l1.rpc.listpays()['pays']) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 920d8809e..3942168eb 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -626,11 +626,11 @@ def test_openchannel_hook(node_factory, bitcoind): # Make sure plugin got all the vars we expect expected = { 'channel_flags': '1', - 'dust_limit_msat': '546000msat', - 'htlc_minimum_msat': '0msat', + 'dust_limit_msat': 546000, + 'htlc_minimum_msat': 0, 'id': l1.info['id'], 'max_accepted_htlcs': '483', - 'max_htlc_value_in_flight_msat': '18446744073709551615msat', + 'max_htlc_value_in_flight_msat': 18446744073709551615, 'to_self_delay': '5', } @@ -643,15 +643,15 @@ def test_openchannel_hook(node_factory, bitcoind): 'feerate_our_max': '150000', 'feerate_our_min': '1875', 'locktime': '.*', - 'their_funding_msat': '100000000msat', - 'channel_max_msat': '16777215000msat', + 'their_funding_msat': 100000000, + 'channel_max_msat': 16777215000, }) else: expected.update({ - 'channel_reserve_msat': '1000000msat', + 'channel_reserve_msat': 1000000, 'feerate_per_kw': '7500', - 'funding_msat': '100000000msat', - 'push_msat': '0msat', + 'funding_msat': 100000000, + 'push_msat': 0, }) l2.daemon.wait_for_log('reject_odd_funding_amounts.py: {} VARS'.format(len(expected))) @@ -1148,7 +1148,7 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor): assert onion['type'] == 'tlv' assert re.match(r'^11020203e80401..0608................$', onion['payload']) assert len(onion['shared_secret']) == 64 - assert onion['forward_msat'] == '1000msat' + assert onion['forward_msat'] == Millisatoshi(1000) assert len(onion['next_onion']) == 2 * (1300 + 32 + 33 + 1) f1.result()