Skip to content
Open
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
30 changes: 15 additions & 15 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cln-grpc/proto/primitives.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ message Amount {
uint64 msat = 1;
}

message AmountSat {
uint64 sat = 1;
}

message AmountOrAll {
oneof value {
Amount amount = 1;
bool all = 2;
}
}

message AmountSatOrAll {
oneof value {
AmountSat amount_sat = 1;
bool all = 2;
}
}

message AmountOrAny {
oneof value {
Amount amount = 1;
Expand Down
44 changes: 41 additions & 3 deletions cln-grpc/src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ mod convert {

use cln_rpc::primitives::{
Amount as JAmount, AmountOrAll as JAmountOrAll, AmountOrAny as JAmountOrAny,
Feerate as JFeerate, JsonObjectOrArray as JJsonObjectOrArray, JsonScalar as JJsonScalar,
Outpoint as JOutpoint, OutputDesc as JOutputDesc, ProofField as JProofField,
AmountSat as JAmountSat, AmountSatOrAll as JAmountSatOrAll, Feerate as JFeerate,
JsonObjectOrArray as JJsonObjectOrArray, JsonScalar as JJsonScalar, Outpoint as JOutpoint,
OutputDesc as JOutputDesc, ProofField as JProofField,
};

impl From<JAmount> for Amount {
Expand All @@ -26,6 +27,18 @@ mod convert {
}
}

impl From<JAmountSat> for AmountSat {
fn from(a: JAmountSat) -> Self {
AmountSat { sat: a.sat() }
}
}

impl From<AmountSat> for JAmountSat {
fn from(a: AmountSat) -> Self {
JAmountSat::from_sat(a.sat)
}
}

impl From<JOutpoint> for Outpoint {
fn from(a: JOutpoint) -> Self {
Outpoint {
Expand Down Expand Up @@ -112,6 +125,31 @@ mod convert {
}
}

impl From<JAmountSatOrAll> for AmountSatOrAll {
fn from(a: JAmountSatOrAll) -> Self {
match a {
JAmountSatOrAll::AmountSat(a) => AmountSatOrAll {
value: Some(amount_sat_or_all::Value::AmountSat(a.into())),
},
JAmountSatOrAll::All => AmountSatOrAll {
value: Some(amount_sat_or_all::Value::All(true)),
},
}
}
}

impl From<AmountSatOrAll> for JAmountSatOrAll {
fn from(a: AmountSatOrAll) -> Self {
match a.value {
Some(amount_sat_or_all::Value::AmountSat(a)) => {
JAmountSatOrAll::AmountSat(a.into())
}
Some(amount_sat_or_all::Value::All(_)) => JAmountSatOrAll::All,
None => panic!("AmountSatOrAll is neither amount nor all: {:?}", a),
}
}
}

impl From<JAmountOrAny> for AmountOrAny {
fn from(a: JAmountOrAny) -> Self {
match a {
Expand All @@ -129,7 +167,7 @@ mod convert {
match a.value {
Some(amount_or_any::Value::Amount(a)) => JAmountOrAny::Amount(a.into()),
Some(amount_or_any::Value::Any(_)) => JAmountOrAny::Any,
None => panic!("AmountOrAll is neither amount nor any: {:?}", a),
None => panic!("AmountOrAny is neither amount nor any: {:?}", a),
}
}
}
Expand Down
80 changes: 60 additions & 20 deletions cln-grpc/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn test_getinfo() {
"version": "v0.10.2-509-ged26651-modded",
"blockheight": 103,
"network": "regtest",
"fees_collected_msat": "0msat", "lightning-dir": "/tmp/ltests-20irp76f/test_pay_variants_1/lightning-1/regtest",
"fees_collected_msat": 0, "lightning-dir": "/tmp/ltests-20irp76f/test_pay_variants_1/lightning-1/regtest",
"our_features": {"init": "8808226aa2", "node": "80008808226aa2", "channel": "", "invoice": "024200"}});
let u: cln_rpc::model::responses::GetinfoResponse = serde_json::from_value(j.clone()).unwrap();
let _g: GetinfoResponse = u.into();
Expand Down Expand Up @@ -307,10 +307,10 @@ fn test_keysend() {
"payment_hash": "e74b03a98453dcb5a7ed5406b97ec3566dde4be85ef71685110f4c0ebc600592",
"created_at": 1648222556.498,
"parts": 1,
"msatoshi": 10000,
"amount_msat": "10000msat",
"msatoshi": 1000,
"amount_msat": 10000,
"msatoshi_sent": 10001,
"amount_sent_msat": "10001msat",
"amount_sent_msat": 10001,
"payment_preimage": "e56c22b9ed85560b021e1577daad5742502d25c0c2f636b817f5c0c7580a66a8",
"status": "complete"
}"#;
Expand All @@ -324,6 +324,46 @@ fn test_keysend() {
assert_eq!(v, v2);
}

#[cfg(feature = "server")]
#[test]
fn test_xkeysend() {
use std::collections::HashMap;

let g = XkeysendRequest {
destination: hex::decode(
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
)
.unwrap(),
amount_msat: Some(Amount { msat: 10000 }),

label: Some("hello".to_string()),
maxdelay: None,
retry_for: None,
extratlvs: HashMap::new(),
maxfee: None,
layers: vec!["xpay".to_owned()],
};

let u: cln_rpc::model::requests::XkeysendRequest = g.into();
let _ser = serde_json::to_string(&u);

let j = r#"{
"failed_parts": 1,
"amount_msat": 10000,
"amount_sent_msat": 10001,
"payment_preimage": "e56c22b9ed85560b021e1577daad5742502d25c0c2f636b817f5c0c7580a66a8",
"successful_parts": 1
}"#;
let u: cln_rpc::model::responses::XkeysendResponse = serde_json::from_str(j).unwrap();
let g: XkeysendResponse = u.clone().into();
println!("{:?}", g);

let v: serde_json::Value = serde_json::to_value(u.clone()).unwrap();
let g: cln_rpc::model::responses::XkeysendResponse = u.into();
let v2 = serde_json::to_value(g).unwrap();
assert_eq!(v, v2);
}

/// Verify serde round-trip: serialize to JSON, deserialize back, and
/// check the re-serialized value matches the first serialization.
macro_rules! assert_serde_roundtrip {
Expand All @@ -344,12 +384,12 @@ fn test_balance_snapshot() {
"accounts": [
{
"account_id": "wallet",
"balance_msat": "500000000msat",
"balance_msat": 500000000,
"coin_type": "bcrt"
},
{
"account_id": "44b77a6d66ca54f0c365c84b13a95fbde462415a0549228baa25ee1bb1dfef66",
"balance_msat": "1000000000msat",
"balance_msat": 1000000000,
"coin_type": "bcrt"
}
]
Expand All @@ -371,14 +411,14 @@ fn test_coin_movement() {
"type": "channel_mvt",
"account_id": "44b77a6d66ca54f0c365c84b13a95fbde462415a0549228baa25ee1bb1dfef66",
"created_index": 1,
"credit_msat": "100000000msat",
"debit_msat": "0msat",
"credit_msat": 100000000,
"debit_msat": 0,
"timestamp": 1648222556,
"primary_tag": "invoice",
"payment_hash": "d17a42c4f7f49648064a0ce7ce848bd92c4c50f24d35fe5c3d1f3a7a9bf474b2",
"part_id": 0,
"group_id": 1,
"fees_msat": "1001msat",
"fees_msat": 1001,
"peer_id": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"extra_tags": ["keysend"]
});
Expand All @@ -403,14 +443,14 @@ fn test_coin_movement() {
"type": "chain_mvt",
"account_id": "wallet",
"created_index": 2,
"credit_msat": "0msat",
"debit_msat": "50000000msat",
"credit_msat": 0,
"debit_msat": 50000000,
"timestamp": 1648222600,
"primary_tag": "withdrawal",
"utxo": "9e76017c75baab960aa7aad24f3b7b0a9708f2dbfdc9544a5cfa72fc44206a00:0",
"blockheight": 110,
"spending_txid": "67efdfb11bee25aa8b2249055a4162e4bd5fa9134bc865c3f054ca666d7ab744",
"output_msat": "49000000msat",
"output_msat": 49000000,
"output_count": 2
});
let u2: cln_rpc::notifications::CoinMovementNotification = serde_json::from_value(j2).unwrap();
Expand Down Expand Up @@ -474,11 +514,11 @@ fn test_forward_event() {
"status": "settled",
"in_channel": "103x1x0",
"in_htlc_id": 0,
"in_msat": "100001001msat",
"in_msat": 100001001,
"out_channel": "103x2x1",
"out_htlc_id": 0,
"out_msat": "100000000msat",
"fee_msat": "1001msat",
"out_msat": 100000000,
"fee_msat": 1001,
"payment_hash": "d17a42c4f7f49648064a0ce7ce848bd92c4c50f24d35fe5c3d1f3a7a9bf474b2",
"received_time": 1648222556.498,
"resolved_time": 1648222557.123,
Expand All @@ -502,7 +542,7 @@ fn test_forward_event() {
"status": "local_failed",
"in_channel": "103x1x0",
"in_htlc_id": 1,
"in_msat": "50000000msat",
"in_msat": 50000000,
"payment_hash": "d17a42c4f7f49648064a0ce7ce848bd92c4c50f24d35fe5c3d1f3a7a9bf474b2",
"received_time": 1648222600.0,
"failcode": 16399,
Expand Down Expand Up @@ -532,8 +572,8 @@ fn test_sendpay_failure() {
"updated_index": 1,
"partid": 0,
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"amount_msat": "10000msat",
"amount_sent_msat": "10001msat",
"amount_msat": 10000,
"amount_sent_msat": 10001,
"created_at": 1648222556,
"completed_at": 1648222557,
"status": "failed",
Expand Down Expand Up @@ -568,8 +608,8 @@ fn test_sendpay_success() {
"updated_index": 1,
"partid": 0,
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"amount_msat": "10000msat",
"amount_sent_msat": "10001msat",
"amount_msat": 10000,
"amount_sent_msat": 10001,
"created_at": 1648222556,
"completed_at": 1648222557,
"status": "complete",
Expand Down
2 changes: 1 addition & 1 deletion cln-rpc/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ pub mod actions{
#[serde(skip_serializing_if = "Option::is_none")]
pub mindepth: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reserve: Option<Amount>,
pub reserve: Option<AmountSat>,
// Path `openchannel.result`
pub result: OpenchannelResult,
}
Expand Down
Loading
Loading