Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state subservice option #11

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.iter().map(|proto| dir.join(proto)).collect();
Expand Down
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub type PeersClient = peersrpc::peers_client::PeersClient<Service>;
#[cfg(feature = "versionrpc")]
pub type VersionerClient = verrpc::versioner_client::VersionerClient<Service>;

// Convenience type alias for signer client.
/// Convenience type alias for signer client.
#[cfg(feature = "signrpc")]
pub type SignerClient = signrpc::signer_client::SignerClient<Service>;

Expand All @@ -45,6 +45,10 @@ pub type RouterClient = routerrpc::router_client::RouterClient<Service>;
#[cfg(feature = "invoicesrpc")]
pub type InvoicesClient = invoicesrpc::invoices_client::InvoicesClient<Service>;

/// Convenience type alias for state service client.
#[cfg(feature = "staterpc")]
pub type StateClient = staterpc::state_client::StateClient<Service>;

/// The client returned by `connect` function
///
/// This is a convenience type which you most likely want to use instead of raw client.
Expand All @@ -64,6 +68,8 @@ pub struct Client {
router: RouterClient,
#[cfg(feature = "invoicesrpc")]
invoices: InvoicesClient,
#[cfg(feature = "staterpc")]
state: StateClient,
}

impl Client {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
60 changes: 60 additions & 0 deletions vendor/staterpc/state.proto
Original file line number Diff line number Diff line change
@@ -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;
}