From 24e44ecbb616704ceeb42a630f7bd5b177062e9b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 16 Jan 2022 16:39:47 +0100 Subject: [PATCH] cln-grpc: Add glue to get all pieces to work together --- Cargo.toml | 1 + cln-grpc/proto/primitives.proto | 8 +------- cln-grpc/src/lib.rs | 5 +++++ cln-grpc/src/pb.rs | 15 +++++++++++++++ cln-rpc/src/primitives.rs | 4 ++++ 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 cln-grpc/src/lib.rs create mode 100644 cln-grpc/src/pb.rs diff --git a/Cargo.toml b/Cargo.toml index e670e44ec..288c89347 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] members = [ "cln-rpc", + "cln-grpc", ] diff --git a/cln-grpc/proto/primitives.proto b/cln-grpc/proto/primitives.proto index d08e10bf7..0b1064c55 100644 --- a/cln-grpc/proto/primitives.proto +++ b/cln-grpc/proto/primitives.proto @@ -2,13 +2,7 @@ syntax = "proto3"; package cln; message Amount { - oneof unit { - uint64 millisatoshi = 1; - uint64 satoshi = 2; - uint64 bitcoin = 3; - bool all = 4; - bool any = 5; - } + uint64 msat = 1; } enum ChannelSide { diff --git a/cln-grpc/src/lib.rs b/cln-grpc/src/lib.rs new file mode 100644 index 000000000..b25b91261 --- /dev/null +++ b/cln-grpc/src/lib.rs @@ -0,0 +1,5 @@ +mod convert; +pub mod pb; +mod server; + +pub use crate::server::Server; diff --git a/cln-grpc/src/pb.rs b/cln-grpc/src/pb.rs new file mode 100644 index 000000000..6d72730cf --- /dev/null +++ b/cln-grpc/src/pb.rs @@ -0,0 +1,15 @@ +tonic::include_proto!("cln"); + +use cln_rpc::primitives::Amount as JAmount; + +impl From for Amount { + fn from(a: JAmount) -> Self { + Amount { msat: a.msat() } + } +} + +impl From for JAmount { + fn from(a: Amount) -> Self { + JAmount::from_msat(a.msat) + } +} diff --git a/cln-rpc/src/primitives.rs b/cln-rpc/src/primitives.rs index 0a7196202..a3317d415 100644 --- a/cln-rpc/src/primitives.rs +++ b/cln-rpc/src/primitives.rs @@ -62,6 +62,10 @@ impl Amount { msat: 100_000_000_000 * btc, } } + + pub fn msat(&self) -> u64 { + self.msat + } } #[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq)]