From 5c208c1b06e4ae2f20f306186ab9b1f8cd1fa456 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2022 19:52:09 +0930 Subject: [PATCH] pyln-client: convert every _msat field to Millisatoshi This prepares for when they start being u64, not strings with msat appended. This has a strange side effect on our schema: despite the name, decodepay's `fee_base_msat` is actually a u64, which we now convert to msat on decode. Signed-off-by: Rusty Russell --- contrib/pyln-client/pyln/client/lightning.py | 7 +++---- contrib/pyln-testing/pyln/testing/fixtures.py | 2 +- doc/lightning-decodepay.7.md | 4 ++-- doc/schemas/decodepay.schema.json | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index 539e9e49c..51e70ae7e 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -453,11 +453,10 @@ class LightningRpc(UnixDomainSocketRpc): if isinstance(obj, dict): for k, v in obj.items(): if k.endswith('msat'): - if isinstance(v, str) and v.endswith('msat'): - obj[k] = Millisatoshi(v) - # Special case for array of msat values - elif isinstance(v, list) and all(isinstance(e, str) and e.endswith('msat') for e in v): + if isinstance(v, list): obj[k] = [Millisatoshi(e) for e in v] + else: + obj[k] = Millisatoshi(v) else: obj[k] = LightningRpc.LightningJSONDecoder.replace_amounts(v) elif isinstance(obj, list): diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index 4cbb63ab0..d576a3aba 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -356,7 +356,7 @@ def _extra_validator(is_request: bool): return False def is_msat_response(checker, instance): - """String number ending in msat""" + """String number ending in msat (deprecated) or integer""" return type(instance) is Millisatoshi def is_txid(checker, instance): diff --git a/doc/lightning-decodepay.7.md b/doc/lightning-decodepay.7.md index 300d80451..699038985 100644 --- a/doc/lightning-decodepay.7.md +++ b/doc/lightning-decodepay.7.md @@ -38,7 +38,7 @@ On success, an object is returned, containing: - hops in the route: - **pubkey** (pubkey): the public key of the node - **short_channel_id** (short_channel_id): a channel to the next peer - - **fee_base_msat** (u32): the base fee for payments + - **fee_base_msat** (msat): the base fee for payments - **fee_proportional_millionths** (u32): the parts-per-million fee for payments - **cltv_expiry_delta** (u32): the CLTV delta across this hop - **extra** (array of objects, optional): Any extra fields we didn't know how to parse: @@ -70,4 +70,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:17cb6c66c75e907f3a2583d702aec2fc6e5a7b6026d05a3ed9957304799c9aef) +[comment]: # ( SHA256STAMP:a606b0d0594d48c619a8d34c7c0d0996982db10f1423841f269e89004a19fa98) diff --git a/doc/schemas/decodepay.schema.json b/doc/schemas/decodepay.schema.json index 0823f7afa..09fa334da 100644 --- a/doc/schemas/decodepay.schema.json +++ b/doc/schemas/decodepay.schema.json @@ -132,7 +132,7 @@ "description": "a channel to the next peer" }, "fee_base_msat": { - "type": "u32", + "type": "msat", "description": "the base fee for payments" }, "fee_proportional_millionths": {