7 个稳定版本
2.5.0 | 2024年7月5日 |
---|---|
2.4.0 | 2024年2月28日 |
2.3.1 | 2023年12月16日 |
2.3.0 | 2023年9月29日 |
2.0.0 | 2023年2月28日 |
#1332 in 异步
108 个月下载量
用于 lightning-probing
99KB
359 行
LND gRPC 客户端在 Rust 中。
使用异步 gRPC 库 tonic_openssl
实现的 LND RPC 客户端。
这是从 https://github.com/yzernik/tonic_openssl_lnd 分支出来的,但使用路径上的十六进制凭据,以便能够远程连接到 LND 而不直接从macaroon和证书文件中读取。
关于
警告:此包处于早期开发阶段,可能存在未知问题!在使用主网络资金之前请先对其进行审查!
此包使用 tonic_openssl
和 prost
实现 LND gRPC。除了在编写时保持最新(:D)之外,它还允许 async
使用。它包含供应商的 *.proto
文件,因此不需要 LND 源代码,但接受环境变量 LND_REPO_DIR
,该变量可覆盖供应商的 *.proto
文件。这可以用于测试未发布的 lnd
中的新功能。(实际上,使用此库的激励项目就是这种情况。:)))
使用说明
无需设置,只需将crate添加到您的Cargo.toml
文件中即可。如果您需要更改生成客户端的*.proto
文件,请在构建期间将环境变量LND_REPO_DIR
设置为您已克隆的lnd
目录。
以下是从LND获取信息([getinfo](https://api.lightning.community/#getinfo)
调用)的示例。您可以在crate根目录中找到相同的示例,以便方便使用。
连接函数接受十六进制格式的证书和macaroon。
use std::fs;
#[tokio::main]
async fn main() {
// Read the contents of the file into a vector of bytes
let cert_bytes = fs::read("/path/to/tls.cert").expect("FailedToReadTlsCertFile");
let mac_bytes = fs::read("path/to/macaroon").expect("FailedToReadMacaroonFile");
// Convert the bytes to a hex string
let cert = buffer_as_hex(cert_bytes);
let macaroon = buffer_as_hex(mac_bytes);
let socket = "localhost:10001".to_string();
let mut client = lnd_grpc_rust::connect(cert, macaroon, socket)
.await
.expect("failed to connect");
let info = client
.lightning()
// All calls require at least empty parameter
.get_info(lnd_grpc_rust::lnrpc::GetInfoRequest {})
.await
.expect("failed to get info");
// We only print it here, note that in real-life code you may want to call `.into_inner()` on
// the response to get the message.
println!("{:#?}", info);
}
fn buffer_as_hex(bytes: Vec<u8>) -> String {
let hex_str = bytes.iter().map(|b| format!("{:02x}", b)).collect::<String>();
return hex_str;
}
许可证
MIT
依赖项
~12–22MB
~316K SLoC