From 91942c79e27104e8a046891fcdd1ddf8baa93071 Mon Sep 17 00:00:00 2001 From: Orbital Date: Thu, 7 Dec 2023 16:02:14 -0600 Subject: [PATCH] Add state subservice option --- Cargo.toml | 3 +- build.rs | 1 + src/lib.rs | 21 ++++++++++++- vendor/staterpc/state.proto | 60 +++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 vendor/staterpc/state.proto diff --git a/Cargo.toml b/Cargo.toml index 1c7b217..2a4be84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,8 @@ peersrpc = [] versionrpc = [] routerrpc = ["lightningrpc"] invoicesrpc = ["lightningrpc"] -all = ["lightningrpc", "walletrpc", "peersrpc", "versionrpc", "routerrpc", "invoicesrpc"] +staterpc = ["lightningrpc"] +all = ["lightningrpc", "walletrpc", "peersrpc", "versionrpc", "routerrpc", "invoicesrpc", "staterpc"] default = ["all"] [dependencies] diff --git a/build.rs b/build.rs index f1daee7..e051f14 100644 --- a/build.rs +++ b/build.rs @@ -22,6 +22,7 @@ fn main() -> std::io::Result<()> { "verrpc/verrpc.proto", "routerrpc/router.proto", "invoicesrpc/invoices.proto", + "staterpc/state.proto", ]; let proto_paths: Vec<_> = protos diff --git a/src/lib.rs b/src/lib.rs index 092bfc0..bfb55d4 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub type PeersClient = peersrpc::peers_client::PeersClient; #[cfg(feature = "versionrpc")] pub type VersionerClient = verrpc::versioner_client::VersionerClient; -// Convenience type alias for signer client. +/// Convenience type alias for signer client. #[cfg(feature = "signrpc")] pub type SignerClient = signrpc::signer_client::SignerClient; @@ -45,6 +45,10 @@ pub type RouterClient = routerrpc::router_client::RouterClient; #[cfg(feature = "invoicesrpc")] pub type InvoicesClient = invoicesrpc::invoices_client::InvoicesClient; +/// Convenience type alias for state service client. +#[cfg(feature = "staterpc")] +pub type StateClient = staterpc::state_client::StateClient; + /// The client returned by `connect` function /// /// This is a convenience type which you most likely want to use instead of raw client. @@ -64,6 +68,8 @@ pub struct Client { router: RouterClient, #[cfg(feature = "invoicesrpc")] invoices: InvoicesClient, + #[cfg(feature = "staterpc")] + state: StateClient, } impl Client { @@ -108,6 +114,12 @@ impl Client { pub fn invoices(&mut self) -> &mut InvoicesClient { &mut self.invoices } + + /// Returns the state service client. + #[cfg(feature = "staterpc")] + pub fn state(&mut self) -> &mut StateClient { + &mut self.state + } } /// [`tonic::Status`] is re-exported as `Error` for convenience. @@ -163,6 +175,11 @@ pub mod invoicesrpc { tonic::include_proto!("invoicesrpc"); } +#[cfg(feature = "staterpc")] +pub mod staterpc { + tonic::include_proto!("staterpc"); +} + /// Supplies requests with macaroon #[derive(Clone)] pub struct MacaroonInterceptor { @@ -252,6 +269,8 @@ where svc.clone(), uri.clone(), ), + #[cfg(feature = "staterpc")] + state: staterpc::state_client::StateClient::with_origin(svc.clone(), uri.clone()), }; Ok(client) } diff --git a/vendor/staterpc/state.proto b/vendor/staterpc/state.proto new file mode 100644 index 0000000..78c61e0 --- /dev/null +++ b/vendor/staterpc/state.proto @@ -0,0 +1,60 @@ +syntax = "proto3"; + +package staterpc; + +/* + * Comments in this file will be directly parsed into the API + * Documentation as descriptions of the associated method, message, or field. + * These descriptions should go right above the definition of the object, and + * can be in either block or // comment format. + * + * An RPC method can be matched to an lncli command by placing a line in the + * beginning of the description in exactly the following format: + * lncli: `methodname` + * + * Failure to specify the exact name of the command will cause documentation + * generation to fail. + * + * More information on how exactly the gRPC documentation is generated from + * this proto file can be found here: + * https://github.com/lightninglabs/lightning-api + */ + +// State service is a always running service that exposes the current state of +// the wallet and RPC server. +service State { + // SubscribeState subscribes to the state of the wallet. The current wallet + // state will always be delivered immediately. + rpc SubscribeState (SubscribeStateRequest) + returns (stream SubscribeStateResponse); + + // GetState returns the current wallet state without streaming further + // changes. + rpc GetState (GetStateRequest) returns (GetStateResponse); +} + +enum WalletState { + NON_EXISTING = 0; + LOCKED = 1; + UNLOCKED = 2; + RPC_ACTIVE = 3; + + // SERVER_ACTIVE means that the lnd server is ready to accept calls. + SERVER_ACTIVE = 4; + + WAITING_TO_START = 255; +} + +message SubscribeStateRequest { +} + +message SubscribeStateResponse { + WalletState state = 1; +} + +message GetStateRequest { +} + +message GetStateResponse { + WalletState state = 1; +}