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

Feat: add get_transactions method #62

Merged
merged 1 commit into from
Oct 19, 2024
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 build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const PROTOS: &[&str] = &[
"protos/invoices.proto",
"protos/lightning.proto",
"protos/router.proto",
"protos/chainkit.proto",
];

fn main() -> Result<(), std::io::Error> {
Expand All @@ -13,5 +14,5 @@ fn main() -> Result<(), std::io::Error> {
tonic_build::configure()
.build_server(false)
.out_dir(BUILD_DIR)
.compile(PROTOS, &[PROTOS_NS])
.compile_protos(PROTOS, &[PROTOS_NS])
}
58 changes: 58 additions & 0 deletions protos/chainkit.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "proto3";

package chainrpc;

option go_package = "github.com/lightningnetwork/lnd/lnrpc/chainrpc";

// ChainKit is a service that can be used to get information from the
// chain backend.
service ChainKit {
/* lncli: `chain getblock`
GetBlock returns a block given the corresponding block hash.
*/
rpc GetBlock(GetBlockRequest) returns (GetBlockResponse);

/* lncli: `chain getbestblock`
GetBestBlock returns the block hash and current height from the valid
most-work chain.
*/
rpc GetBestBlock(GetBestBlockRequest) returns (GetBestBlockResponse);

/* lncli: `chain getblockhash`
GetBlockHash returns the hash of the block in the best blockchain
at the given height.
*/
rpc GetBlockHash(GetBlockHashRequest) returns (GetBlockHashResponse);
}

message GetBlockRequest {
// The hash of the requested block.
bytes block_hash = 1;
}

// TODO(ffranr): The neutrino GetBlock response includes many
// additional helpful fields. Consider adding them here also.
message GetBlockResponse {
// The raw bytes of the requested block.
bytes raw_block = 1;
}

message GetBestBlockRequest {}

message GetBestBlockResponse {
// The hash of the best block.
bytes block_hash = 1;

// The height of the best block.
int32 block_height = 2;
}

message GetBlockHashRequest {
// Block height of the target best chain block.
int64 block_height = 1;
}

message GetBlockHashResponse {
// The hash of the best block at the specified height.
bytes block_hash = 1;
}
1 change: 1 addition & 0 deletions src/gen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod chainrpc;
pub mod invoicesrpc;
pub mod lnrpc;
pub mod routerrpc;
44 changes: 37 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
/// Module including all tonic-build generated code.
/// Each sub-module represents one proto service.
mod gen;
pub use gen::{invoicesrpc, lnrpc, routerrpc};
pub use gen::{chainrpc, invoicesrpc, lnrpc, routerrpc};
use gen::{
chainrpc::{chain_kit_client::ChainKitClient, GetBestBlockRequest, GetBestBlockResponse},
invoicesrpc::{
invoices_client::InvoicesClient, lookup_invoice_msg::InvoiceRef, AddHoldInvoiceRequest,
AddHoldInvoiceResp, CancelInvoiceMsg, CancelInvoiceResp, LookupInvoiceMsg, LookupModifier,
Expand All @@ -20,11 +21,12 @@ use gen::{
lightning_client::LightningClient, AddInvoiceResponse, ChannelAcceptRequest,
ChannelAcceptResponse, ChannelBalanceRequest, ChannelBalanceResponse, CloseChannelRequest,
CloseStatusUpdate, ClosedChannelsRequest, ClosedChannelsResponse, ForwardingHistoryRequest,
ForwardingHistoryResponse, GetInfoRequest, GetInfoResponse, Invoice, ListChannelsRequest,
ListChannelsResponse, ListInvoiceRequest, ListInvoiceResponse, ListPaymentsRequest,
ListPaymentsResponse, NewAddressRequest, NewAddressResponse, PayReq, PayReqString, Payment,
PendingChannelsRequest, PendingChannelsResponse, SendCoinsRequest, SendCoinsResponse,
SendRequest, SendResponse, WalletBalanceRequest, WalletBalanceResponse,
ForwardingHistoryResponse, GetInfoRequest, GetInfoResponse, GetTransactionsRequest,
Invoice, ListChannelsRequest, ListChannelsResponse, ListInvoiceRequest,
ListInvoiceResponse, ListPaymentsRequest, ListPaymentsResponse, NewAddressRequest,
NewAddressResponse, PayReq, PayReqString, Payment, PendingChannelsRequest,
PendingChannelsResponse, SendCoinsRequest, SendCoinsResponse, SendRequest, SendResponse,
TransactionDetails, WalletBalanceRequest, WalletBalanceResponse,
},
routerrpc::{router_client::RouterClient, SendPaymentRequest, TrackPaymentRequest},
};
Expand All @@ -44,6 +46,7 @@ pub struct Lnd {
lightning: LightningClient<InterceptedService<Channel, LndInterceptor>>,
invoices: InvoicesClient<InterceptedService<Channel, LndInterceptor>>,
router: RouterClient<InterceptedService<Channel, LndInterceptor>>,
chainkit: ChainKitClient<InterceptedService<Channel, LndInterceptor>>,
tracer: std::sync::Arc<opentelemetry::global::BoxedTracer>,
}

Expand Down Expand Up @@ -151,12 +154,14 @@ impl Lnd {
let tracer = std::sync::Arc::new(opentelemetry::global::tracer("lnd"));
let lightning = LightningClient::with_interceptor(channel.clone(), interceptor.clone());
let invoices = InvoicesClient::with_interceptor(channel.clone(), interceptor.clone());
let router = RouterClient::with_interceptor(channel, interceptor);
let router = RouterClient::with_interceptor(channel.clone(), interceptor.clone());
let chainkit = ChainKitClient::with_interceptor(channel, interceptor);

Lnd {
lightning,
invoices,
router,
chainkit,
tracer,
}
}
Expand Down Expand Up @@ -436,6 +441,31 @@ impl Lnd {
.await
.map(Response::into_inner)
}

pub async fn get_transactions(
&self,
req: GetTransactionsRequest,
) -> Result<TransactionDetails, Status> {
let span = span!(self.tracer => "lnrpc". "Lightning" / "GetTransactions");

self.lightning
.clone()
.get_transactions(req)
.with_context(opentelemetry::Context::current_with_span(span))
.await
.map(Response::into_inner)
}

pub async fn get_best_block(&self) -> Result<GetBestBlockResponse, Status> {
let span = span!(self.tracer => "lnrpc". "ChainKit" / "GetBestBlock");

self.chainkit
.clone()
.get_best_block(GetBestBlockRequest::default())
.with_context(opentelemetry::Context::current_with_span(span))
.await
.map(Response::into_inner)
}
}

impl Lnd {
Expand Down
Loading