Skip to content

Commit 128710c

Browse files
committed
cln-rpc: purge msats and encode amounts as u64
Drop conversion to string and instead implement Display Changelog-None
1 parent 066056d commit 128710c

3 files changed

Lines changed: 156 additions & 96 deletions

File tree

cln-grpc/src/test.rs

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn test_getinfo() {
247247
"version": "v0.10.2-509-ged26651-modded",
248248
"blockheight": 103,
249249
"network": "regtest",
250-
"fees_collected_msat": "0msat", "lightning-dir": "/tmp/ltests-20irp76f/test_pay_variants_1/lightning-1/regtest",
250+
"fees_collected_msat": 0, "lightning-dir": "/tmp/ltests-20irp76f/test_pay_variants_1/lightning-1/regtest",
251251
"our_features": {"init": "8808226aa2", "node": "80008808226aa2", "channel": "", "invoice": "024200"}});
252252
let u: cln_rpc::model::responses::GetinfoResponse = serde_json::from_value(j.clone()).unwrap();
253253
let _g: GetinfoResponse = u.into();
@@ -307,10 +307,10 @@ fn test_keysend() {
307307
"payment_hash": "e74b03a98453dcb5a7ed5406b97ec3566dde4be85ef71685110f4c0ebc600592",
308308
"created_at": 1648222556.498,
309309
"parts": 1,
310-
"msatoshi": 10000,
311-
"amount_msat": "10000msat",
310+
"msatoshi": 1000,
311+
"amount_msat": 10000,
312312
"msatoshi_sent": 10001,
313-
"amount_sent_msat": "10001msat",
313+
"amount_sent_msat": 10001,
314314
"payment_preimage": "e56c22b9ed85560b021e1577daad5742502d25c0c2f636b817f5c0c7580a66a8",
315315
"status": "complete"
316316
}"#;
@@ -324,6 +324,46 @@ fn test_keysend() {
324324
assert_eq!(v, v2);
325325
}
326326

327+
#[cfg(feature = "server")]
328+
#[test]
329+
fn test_xkeysend() {
330+
use std::collections::HashMap;
331+
332+
let g = XkeysendRequest {
333+
destination: hex::decode(
334+
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
335+
)
336+
.unwrap(),
337+
amount_msat: Some(Amount { msat: 10000 }),
338+
339+
label: Some("hello".to_string()),
340+
maxdelay: None,
341+
retry_for: None,
342+
extratlvs: HashMap::new(),
343+
maxfee: None,
344+
layers: vec!["xpay".to_owned()],
345+
};
346+
347+
let u: cln_rpc::model::requests::XkeysendRequest = g.into();
348+
let _ser = serde_json::to_string(&u);
349+
350+
let j = r#"{
351+
"failed_parts": 1,
352+
"amount_msat": 10000,
353+
"amount_sent_msat": 10001,
354+
"payment_preimage": "e56c22b9ed85560b021e1577daad5742502d25c0c2f636b817f5c0c7580a66a8",
355+
"successful_parts": 1
356+
}"#;
357+
let u: cln_rpc::model::responses::XkeysendResponse = serde_json::from_str(j).unwrap();
358+
let g: XkeysendResponse = u.clone().into();
359+
println!("{:?}", g);
360+
361+
let v: serde_json::Value = serde_json::to_value(u.clone()).unwrap();
362+
let g: cln_rpc::model::responses::XkeysendResponse = u.into();
363+
let v2 = serde_json::to_value(g).unwrap();
364+
assert_eq!(v, v2);
365+
}
366+
327367
/// Verify serde round-trip: serialize to JSON, deserialize back, and
328368
/// check the re-serialized value matches the first serialization.
329369
macro_rules! assert_serde_roundtrip {
@@ -344,12 +384,12 @@ fn test_balance_snapshot() {
344384
"accounts": [
345385
{
346386
"account_id": "wallet",
347-
"balance_msat": "500000000msat",
387+
"balance_msat": 500000000,
348388
"coin_type": "bcrt"
349389
},
350390
{
351391
"account_id": "44b77a6d66ca54f0c365c84b13a95fbde462415a0549228baa25ee1bb1dfef66",
352-
"balance_msat": "1000000000msat",
392+
"balance_msat": 1000000000,
353393
"coin_type": "bcrt"
354394
}
355395
]
@@ -371,14 +411,14 @@ fn test_coin_movement() {
371411
"type": "channel_mvt",
372412
"account_id": "44b77a6d66ca54f0c365c84b13a95fbde462415a0549228baa25ee1bb1dfef66",
373413
"created_index": 1,
374-
"credit_msat": "100000000msat",
375-
"debit_msat": "0msat",
414+
"credit_msat": 100000000,
415+
"debit_msat": 0,
376416
"timestamp": 1648222556,
377417
"primary_tag": "invoice",
378418
"payment_hash": "d17a42c4f7f49648064a0ce7ce848bd92c4c50f24d35fe5c3d1f3a7a9bf474b2",
379419
"part_id": 0,
380420
"group_id": 1,
381-
"fees_msat": "1001msat",
421+
"fees_msat": 1001,
382422
"peer_id": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
383423
"extra_tags": ["keysend"]
384424
});
@@ -403,14 +443,14 @@ fn test_coin_movement() {
403443
"type": "chain_mvt",
404444
"account_id": "wallet",
405445
"created_index": 2,
406-
"credit_msat": "0msat",
407-
"debit_msat": "50000000msat",
446+
"credit_msat": 0,
447+
"debit_msat": 50000000,
408448
"timestamp": 1648222600,
409449
"primary_tag": "withdrawal",
410450
"utxo": "9e76017c75baab960aa7aad24f3b7b0a9708f2dbfdc9544a5cfa72fc44206a00:0",
411451
"blockheight": 110,
412452
"spending_txid": "67efdfb11bee25aa8b2249055a4162e4bd5fa9134bc865c3f054ca666d7ab744",
413-
"output_msat": "49000000msat",
453+
"output_msat": 49000000,
414454
"output_count": 2
415455
});
416456
let u2: cln_rpc::notifications::CoinMovementNotification = serde_json::from_value(j2).unwrap();
@@ -474,11 +514,11 @@ fn test_forward_event() {
474514
"status": "settled",
475515
"in_channel": "103x1x0",
476516
"in_htlc_id": 0,
477-
"in_msat": "100001001msat",
517+
"in_msat": 100001001,
478518
"out_channel": "103x2x1",
479519
"out_htlc_id": 0,
480-
"out_msat": "100000000msat",
481-
"fee_msat": "1001msat",
520+
"out_msat": 100000000,
521+
"fee_msat": 1001,
482522
"payment_hash": "d17a42c4f7f49648064a0ce7ce848bd92c4c50f24d35fe5c3d1f3a7a9bf474b2",
483523
"received_time": 1648222556.498,
484524
"resolved_time": 1648222557.123,
@@ -502,7 +542,7 @@ fn test_forward_event() {
502542
"status": "local_failed",
503543
"in_channel": "103x1x0",
504544
"in_htlc_id": 1,
505-
"in_msat": "50000000msat",
545+
"in_msat": 50000000,
506546
"payment_hash": "d17a42c4f7f49648064a0ce7ce848bd92c4c50f24d35fe5c3d1f3a7a9bf474b2",
507547
"received_time": 1648222600.0,
508548
"failcode": 16399,
@@ -532,8 +572,8 @@ fn test_sendpay_failure() {
532572
"updated_index": 1,
533573
"partid": 0,
534574
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
535-
"amount_msat": "10000msat",
536-
"amount_sent_msat": "10001msat",
575+
"amount_msat": 10000,
576+
"amount_sent_msat": 10001,
537577
"created_at": 1648222556,
538578
"completed_at": 1648222557,
539579
"status": "failed",
@@ -568,8 +608,8 @@ fn test_sendpay_success() {
568608
"updated_index": 1,
569609
"partid": 0,
570610
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
571-
"amount_msat": "10000msat",
572-
"amount_sent_msat": "10001msat",
611+
"amount_msat": 10000,
612+
"amount_sent_msat": 10001,
573613
"created_at": 1648222556,
574614
"completed_at": 1648222557,
575615
"status": "complete",

0 commit comments

Comments
 (0)