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 <rusty@rustcorp.com.au>
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)
This commit is contained in:
Rusty Russell 2022-06-20 19:52:10 +09:30
parent 5531de99de
commit 60bd70be85
4 changed files with 17 additions and 14 deletions

View file

@ -412,8 +412,11 @@ void json_add_amount_msat_only(struct json_stream *result,
{ {
if (!deprecated_apis) if (!deprecated_apis)
assert(strends(msatfieldname, "_msat")); assert(strends(msatfieldname, "_msat"));
json_add_string(result, msatfieldname, if (deprecated_apis)
type_to_string(tmpctx, struct amount_msat, &msat)); 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, void json_add_amount_sat_compat(struct json_stream *result,

View file

@ -969,7 +969,7 @@ def test_cli(node_factory):
' "invoices": [', ' "invoices": [',
' {', ' {',
r' "label": "l\"[]{}",', r' "label": "l\"[]{}",',
' "amount_msat": "123000msat",', ' "amount_msat": 123000,',
' "status": "unpaid",', ' "status": "unpaid",',
r' "description": "d\"[]{}",', r' "description": "d\"[]{}",',
' }', ' }',

View file

@ -3097,8 +3097,8 @@ def test_partial_payment(node_factory, bitcoind, executor):
for i in range(2): for i in range(2):
line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion') line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion')
assert "'type': 'tlv'" in line assert "'type': 'tlv'" in line
assert "'forward_msat': '499msat'" in line or "'forward_msat': '501msat'" in line assert "'forward_msat': 499" in line or "'forward_msat': 501" in line
assert "'total_msat': '1000msat'" in line assert "'total_msat': 1000" in line
assert "'payment_secret': '{}'".format(paysecret) in line assert "'payment_secret': '{}'".format(paysecret) in line
pay = only_one(l1.rpc.listpays()['pays']) pay = only_one(l1.rpc.listpays()['pays'])

View file

@ -626,11 +626,11 @@ def test_openchannel_hook(node_factory, bitcoind):
# Make sure plugin got all the vars we expect # Make sure plugin got all the vars we expect
expected = { expected = {
'channel_flags': '1', 'channel_flags': '1',
'dust_limit_msat': '546000msat', 'dust_limit_msat': 546000,
'htlc_minimum_msat': '0msat', 'htlc_minimum_msat': 0,
'id': l1.info['id'], 'id': l1.info['id'],
'max_accepted_htlcs': '483', 'max_accepted_htlcs': '483',
'max_htlc_value_in_flight_msat': '18446744073709551615msat', 'max_htlc_value_in_flight_msat': 18446744073709551615,
'to_self_delay': '5', 'to_self_delay': '5',
} }
@ -643,15 +643,15 @@ def test_openchannel_hook(node_factory, bitcoind):
'feerate_our_max': '150000', 'feerate_our_max': '150000',
'feerate_our_min': '1875', 'feerate_our_min': '1875',
'locktime': '.*', 'locktime': '.*',
'their_funding_msat': '100000000msat', 'their_funding_msat': 100000000,
'channel_max_msat': '16777215000msat', 'channel_max_msat': 16777215000,
}) })
else: else:
expected.update({ expected.update({
'channel_reserve_msat': '1000000msat', 'channel_reserve_msat': 1000000,
'feerate_per_kw': '7500', 'feerate_per_kw': '7500',
'funding_msat': '100000000msat', 'funding_msat': 100000000,
'push_msat': '0msat', 'push_msat': 0,
}) })
l2.daemon.wait_for_log('reject_odd_funding_amounts.py: {} VARS'.format(len(expected))) 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 onion['type'] == 'tlv'
assert re.match(r'^11020203e80401..0608................$', onion['payload']) assert re.match(r'^11020203e80401..0608................$', onion['payload'])
assert len(onion['shared_secret']) == 64 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) assert len(onion['next_onion']) == 2 * (1300 + 32 + 33 + 1)
f1.result() f1.result()