From bba68e2136fdde0af520fdeb0e54e9a930d82d7e Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 1 Apr 2022 14:42:45 +1030 Subject: [PATCH] cln-grpc: Map AmountOrAll and AmountOrAny --- cln-grpc/proto/node.proto | Bin 24532 -> 24542 bytes cln-grpc/proto/primitives.proto | 14 +++++++++ cln-grpc/src/convert.rs | Bin 54518 -> 54526 bytes cln-grpc/src/pb.rs | 48 +++++++++++++++++++++++++++++- cln-rpc/src/lib.rs | 2 +- cln-rpc/src/model.rs | Bin 78813 -> 78823 bytes contrib/msggen/msggen/grpc.py | 6 ++++ contrib/msggen/msggen/model.py | 2 ++ contrib/msggen/msggen/rust.py | 2 ++ doc/schemas/invoice.request.json | 2 +- doc/schemas/withdraw.request.json | 2 +- tests/test_cln_rs.py | 10 +++++++ 12 files changed, 84 insertions(+), 4 deletions(-) diff --git a/cln-grpc/proto/node.proto b/cln-grpc/proto/node.proto index f3a6dd23a7f90ef3baed1d037eba95378114f129..cfd390c23984e5e9f62d78a8fe690d3980ff1975 100644 GIT binary patch delta 31 lcmcbzpYh&)#tlo%SpAC}^C~wlF}ouNV&>#*ZU_zG0s!Fq4EF#4 delta 29 ncmV+&0OJ4NzX8<00kEVtv#B=R9swYe@kkewyIvBrv{fn!)$0uV diff --git a/cln-grpc/proto/primitives.proto b/cln-grpc/proto/primitives.proto index 2f04e1410..c76730949 100644 --- a/cln-grpc/proto/primitives.proto +++ b/cln-grpc/proto/primitives.proto @@ -5,6 +5,20 @@ message Amount { uint64 msat = 1; } +message AmountOrAll { + oneof value { + Amount amount = 1; + bool all = 2; + } +} + +message AmountOrAny { + oneof value { + Amount amount = 1; + bool any = 2; + } +} + enum ChannelSide { IN = 0; OUT = 1; diff --git a/cln-grpc/src/convert.rs b/cln-grpc/src/convert.rs index 61b09b814f3f7dc572fb0e7d633a964f969313ac..cb7d8d54bc5f9d767f4a1431d0280340514f50ee 100644 GIT binary patch delta 38 wcmV+>0NMZcsRRD01F*5Q1bks`d9$&!m=OhhVQg$alkUnXlTFi4v% for Amount { @@ -55,3 +56,48 @@ impl From<&OutputDesc> for JOutputDesc { } } } + +impl From for AmountOrAll { + fn from(a: JAmountOrAll) -> Self { + match a { + JAmountOrAll::Amount(a) => AmountOrAll { + value: Some(amount_or_all::Value::Amount(a.into())), + }, + JAmountOrAll::All => AmountOrAll { + value: Some(amount_or_all::Value::All(true)), + }, + } + } +} + +impl From<&AmountOrAll> for JAmountOrAll { + fn from(a: &AmountOrAll) -> Self { + match &a.value { + Some(amount_or_all::Value::Amount(a)) => JAmountOrAll::Amount(a.into()), + Some(amount_or_all::Value::All(_)) => JAmountOrAll::All, + None => panic!("AmountOrAll is neither amount nor all: {:?}", a), + } + } +} + +impl From for AmountOrAny { + fn from(a: JAmountOrAny) -> Self { + match a { + JAmountOrAny::Amount(a) => AmountOrAny { + value: Some(amount_or_any::Value::Amount(a.into())), + }, + JAmountOrAny::Any => AmountOrAny { + value: Some(amount_or_any::Value::Any(true)), + }, + } + } +} +impl From<&AmountOrAny> for JAmountOrAny { + fn from(a: &AmountOrAny) -> Self { + match &a.value { + Some(amount_or_any::Value::Amount(a)) => JAmountOrAny::Amount(a.into()), + Some(amount_or_any::Value::Any(_)) => JAmountOrAny::Any, + None => panic!("AmountOrAll is neither amount nor any: {:?}", a), + } + } +} diff --git a/cln-rpc/src/lib.rs b/cln-rpc/src/lib.rs index 0197d4b39..c57bf2432 100644 --- a/cln-rpc/src/lib.rs +++ b/cln-rpc/src/lib.rs @@ -75,7 +75,7 @@ impl ClnRpc { // serde_json knows which variant of [`Request`] should be // used. response["method"] = req2["method"].clone(); - + log::warn!("XXX {:?}", response); serde_json::from_value(response).context("converting response into enum") } } diff --git a/cln-rpc/src/model.rs b/cln-rpc/src/model.rs index 9d767e310ce6f205a50e901c3e27de53b746d10f..be76d10ceba05b6e64f00ee44d051cea54143f82 100644 GIT binary patch delta 56 zcmccnoaOm*mJPSHS^bL~^C~9`E|s2sfRE8(a?Dlp&AB?-A|UacoXHm@Bqz&wa!mH~ L*}OT&vG5ZBr9T$t delta 53 zcmV-50LuU8=LFs71hCsHlMYE3ldio(myiwtH?wjqD-@Fugc*}iOuLghSR0cjO=Xu% LB>@Su|3T>SY{M2r diff --git a/contrib/msggen/msggen/grpc.py b/contrib/msggen/msggen/grpc.py index e29e8312a..61084e7cf 100644 --- a/contrib/msggen/msggen/grpc.py +++ b/contrib/msggen/msggen/grpc.py @@ -10,6 +10,8 @@ typemap = { 'boolean': 'bool', 'hex': 'bytes', 'msat': 'Amount', + 'msat|all': 'AmountOrAll', + 'msat|any': 'AmountOrAny', 'number': 'sint64', 'pubkey': 'bytes', 'short_channel_id': 'string', @@ -395,6 +397,10 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): 'pubkey?': f'c.{name}.clone().map(|v| hex::encode(v))', 'msat': f'c.{name}.as_ref().unwrap().into()', 'msat?': f'c.{name}.as_ref().map(|a| a.into())', + 'msat|all': f'c.{name}.as_ref().unwrap().into()', + 'msat|all?': f'c.{name}.as_ref().map(|a| a.into())', + 'msat|any': f'c.{name}.as_ref().unwrap().into()', + 'msat|any?': f'c.{name}.as_ref().map(|a| a.into())', 'feerate': f'c.{name}.as_ref().unwrap().into()', 'feerate?': f'c.{name}.as_ref().map(|a| a.into())', }.get( diff --git a/contrib/msggen/msggen/model.py b/contrib/msggen/msggen/model.py index db5812917..49215203a 100644 --- a/contrib/msggen/msggen/model.py +++ b/contrib/msggen/msggen/model.py @@ -224,6 +224,8 @@ class PrimitiveField(Field): "pubkey", "signature", "msat", + "msat|any", + "msat|all", "hex", "short_channel_id", "txid", diff --git a/contrib/msggen/msggen/rust.py b/contrib/msggen/msggen/rust.py index ea5aaf3cc..0de946b7f 100644 --- a/contrib/msggen/msggen/rust.py +++ b/contrib/msggen/msggen/rust.py @@ -32,6 +32,8 @@ typemap = { 'boolean': 'bool', 'hex': 'String', 'msat': 'Amount', + 'msat|all': 'AmountOrAll', + 'msat|any': 'AmountOrAny', 'number': 'i64', 'pubkey': 'String', 'short_channel_id': 'String', diff --git a/doc/schemas/invoice.request.json b/doc/schemas/invoice.request.json index 282311bd8..34d40c267 100644 --- a/doc/schemas/invoice.request.json +++ b/doc/schemas/invoice.request.json @@ -9,7 +9,7 @@ ], "properties": { "msatoshi": { - "type": "msat", + "type": "msat|any", "description": "" }, "description": { diff --git a/doc/schemas/withdraw.request.json b/doc/schemas/withdraw.request.json index d098171c8..0637f1f16 100644 --- a/doc/schemas/withdraw.request.json +++ b/doc/schemas/withdraw.request.json @@ -9,7 +9,7 @@ "type": "pubkey" }, "satoshi": { - "type": "msat" + "type": "msat|all" }, "feerate": { "type": "feerate" diff --git a/tests/test_cln_rs.py b/tests/test_cln_rs.py index 4fb62b810..140ffa392 100644 --- a/tests/test_cln_rs.py +++ b/tests/test_cln_rs.py @@ -5,6 +5,7 @@ from pyln.testing.utils import env, TEST_NETWORK, wait_for from ephemeral_port_reserve import reserve import grpc import node_pb2 as nodepb +from primitives_pb2 import AmountOrAny import pytest import subprocess @@ -101,6 +102,15 @@ def test_grpc_connect(node_factory): response = stub.ListFunds(nodepb.ListfundsRequest()) print(response) + inv = stub.Invoice(nodepb.InvoiceRequest( + msatoshi=AmountOrAny(any=True), + description="hello", + label="lbl1", + preimage=b"\x00" * 32, + cltv=24 + )) + print(inv) + def test_grpc_generate_certificate(node_factory): """Test whether we correctly generate the certificates.