Crates.io | cngateway |
lib.rs | cngateway |
version | 0.1.15 |
source | src |
created_at | 2023-02-23 21:32:51.700364 |
updated_at | 2023-03-02 17:04:43.216961 |
description | cyphernode gatekeeper client |
homepage | |
repository | |
max_upload_size | |
id | 793064 |
size | 138,221 |
a client library for cyphernode gatekeeper
EXTREME BETA: We need help building this client. It is not safe for production use yet.
add certs/cert.pem
to the root directory for tests
if you are testing outside the cyphernodeappsnet (gatekeeper bound to localhost), only run
cargo test local
docker exec -it cngateway sh -c 'cargo test cyphernodeappsnet'
let gatekeeper_ip = "gatekeeper:2009".to_string(); // if you are connected to cyphernodeappsnet IF NOT expose gatekeeper outside network and use localhost
let kid = "003".to_string();
let key = "c06f9fc30c50ab7541cefaeb58708fe28babcf7d5ed1767a59685f63d0b63c54".to_string();
let cert_path = "/path/to/cacert.pem";
let client = CnGateway::new(
gatekeeper_ip,
kid,
key,
cert_path,
)
.await?;
// Use bitcoin core
let mempool = client.getmempoolinfo().await?;
let balance = client.getbalance().await?;
let address = client.getnewaddress(AddressType::Bech32,"dup".to_string()).await?; // uses the POST api format {address_type, label}
// Use lightning
let lninfo = client.ln_getinfo().await.unwrap();
let newaddr = client.ln_newaddr().await.unwrap();
let connstr = client.ln_getconnectionstring().await.unwrap();
let invoice = "lnbc920u1p3khp67pp5mcqxhupukc5te86wfkryerk8f69gg9ptzcep33ry94svm4wvwzqqdqqcqzzgxqyz5vqrzjqwnvuc0u4txn35cafc7w94gxvq5p3cu9dd95f7hlrh0fvs46wpvhdjx4k0kekn630gqqqqryqqqqthqqpyrzjqw8c7yfutqqy3kz8662fxutjvef7q2ujsxtt45csu0k688lkzu3ldjx4k0kekn630gqqqqryqqqqthqqpysp58nxs2nm5wphu234ggawaeul2tnpl6jqc9a0ymfhwpr64vq0k3l4s9qypqsqlkrver3pdxm0teyye0n6y5sje8u90t4j8vpxq3qjwjh9ue46cctj2nzw8fdudfec6nd0e8gx9v485ek7p624j5leeykg70wmv59y3pqqn9ulv2".to_string();
let bolt11_decoded = client.ln_decodebolt11(invoice).await.unwrap();
let peer =
"02eadbd9e7557375161df8b646776a547c5cbc2e95b3071ec81553f8ec2cea3b8c@18.191.253.246:9735"
.to_string();
let msatoshis = 3_690_000;
let callback_url = "http://yourcypherapp/callback/".to_string();
let fund_stat = client
.ln_connectfund(peer, msatoshis, callback_url)
.await
.err();
let list_funds = client.ln_listfunds().await.unwrap();
let list_pays = client.ln_listpays().await.unwrap();
The cyphernode api request and response json types are internally converted into a native rust types.
The client feeds request parameters (if any) as function inputs.
Example: ln_connectfund
let fund_stat = client.ln_connectfund(
peer,
msatoshis,
callback_url
).await?
The client recieves the response as a native rust type.
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LnConnectFund {
pub result: String,
pub txid: String,
#[serde(rename = "channelId")]
pub channel_id: String,
}
NOTE: Rust uses snake_case for variable and function names. Cyphernode uses camelCase. All datatypes returned will internally be snake_case.