Skip to content
Closed
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
10 changes: 10 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@
"Decode.payment_metadata": 67,
"Decode.payment_secret": 66,
"Decode.restrictions[]": 73,
"Decode.routes": 82,
"Decode.routes[][]": 68,
"Decode.signature": 77,
"Decode.string": 72,
Expand Down Expand Up @@ -978,6 +979,7 @@
"DecodePay.payment_hash": 6,
"DecodePay.payment_metadata": 13,
"DecodePay.payment_secret": 11,
"DecodePay.routes": 17,
"DecodePay.routes[][]": 15,
"DecodePay.signature": 7
},
Expand Down Expand Up @@ -3900,6 +3902,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"Decode.routes": {
"added": "pre-v0.10.1",
"deprecated": false
},
"Decode.routes[][]": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down Expand Up @@ -4164,6 +4170,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"DecodePay.routes": {
"added": "pre-v0.10.1",
"deprecated": false
},
"DecodePay.routes[][]": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down
2 changes: 2 additions & 0 deletions cln-grpc/proto/node.proto

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

17 changes: 15 additions & 2 deletions cln-grpc/proto/primitives.proto
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ message OutputDesc {

message RouteHop {
bytes id = 1;
string short_channel_id = 2;
string scid = 2;
Amount feebase = 3;
uint32 feeprop = 4;
uint32 feeprop = 4;
uint32 expirydelta = 5;
}
message Routehint {
Expand All @@ -98,6 +98,19 @@ message RoutehintList {
repeated Routehint hints = 2;
}

message DecodeRouteHop {
bytes pubkey = 1;
string short_channel_id = 2;
Amount fee_base_msat = 3;
uint32 fee_proportional_millionths = 4;
uint32 cltv_expiry_delta = 5;
}
message DecodeRoutehint {
repeated DecodeRouteHop hops = 1;
}
message DecodeRoutehintList {
repeated DecodeRoutehint hints = 2;
}

message TlvEntry {
uint64 type = 1;
Expand Down
2 changes: 2 additions & 0 deletions cln-grpc/src/convert.rs

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

63 changes: 61 additions & 2 deletions cln-grpc/src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod convert {
fn from(c: RouteHop) -> Self {
Self {
id: cln_rpc::primitives::PublicKey::from_slice(&c.id).unwrap(),
scid: cln_rpc::primitives::ShortChannelId::from_str(&c.short_channel_id).unwrap(),
scid: cln_rpc::primitives::ShortChannelId::from_str(&c.scid).unwrap(),
feebase: c.feebase.unwrap().into(),
feeprop: c.feeprop,
expirydelta: c.expirydelta as u16,
Expand Down Expand Up @@ -167,7 +167,7 @@ mod convert {
feebase: Some(c.feebase.into()),
feeprop: c.feeprop,
expirydelta: c.expirydelta as u32,
short_channel_id: c.scid.to_string(),
scid: c.scid.to_string(),
}
}
}
Expand All @@ -188,6 +188,65 @@ mod convert {
}
}

impl From<DecodeRouteHop> for cln_rpc::primitives::DecodeRoutehop {
fn from(c: DecodeRouteHop) -> Self {
Self {
pubkey: cln_rpc::primitives::PublicKey::from_slice(&c.pubkey).unwrap(),
short_channel_id: cln_rpc::primitives::ShortChannelId::from_str(
&c.short_channel_id,
)
.unwrap(),
fee_base_msat: c.fee_base_msat.unwrap().into(),
fee_proportional_millionths: c.fee_proportional_millionths,
cltv_expiry_delta: c.cltv_expiry_delta as u16,
}
}
}

impl From<DecodeRoutehint> for cln_rpc::primitives::DecodeRoutehint {
fn from(c: DecodeRoutehint) -> Self {
Self {
hops: c.hops.into_iter().map(|h| h.into()).collect(),
}
}
}

impl From<DecodeRoutehintList> for cln_rpc::primitives::DecodeRoutehintList {
fn from(c: DecodeRoutehintList) -> Self {
Self {
hints: c.hints.into_iter().map(|h| h.into()).collect(),
}
}
}

impl From<cln_rpc::primitives::DecodeRoutehop> for DecodeRouteHop {
fn from(c: cln_rpc::primitives::DecodeRoutehop) -> Self {
Self {
pubkey: c.pubkey.serialize().to_vec(),
fee_base_msat: Some(c.fee_base_msat.into()),
fee_proportional_millionths: c.fee_proportional_millionths,
cltv_expiry_delta: c.cltv_expiry_delta as u32,
short_channel_id: c.short_channel_id.to_string(),
}
}
}

impl From<cln_rpc::primitives::DecodeRoutehint> for DecodeRoutehint {
fn from(c: cln_rpc::primitives::DecodeRoutehint) -> Self {
Self {
hops: c.hops.into_iter().map(|h| h.into()).collect(),
}
}
}

impl From<cln_rpc::primitives::DecodeRoutehintList> for DecodeRoutehintList {
fn from(c: cln_rpc::primitives::DecodeRoutehintList) -> Self {
Self {
hints: c.hints.into_iter().map(|e| e.into()).collect(),
}
}
}

impl From<TlvStream> for cln_rpc::primitives::TlvStream {
fn from(s: TlvStream) -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions cln-grpc/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn test_keysend() {
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
)
.unwrap(),
short_channel_id: "12345x678x90".to_string(),
scid: "12345x678x90".to_string(),
feebase: Some(Amount { msat: 123 }),
feeprop: 1234,
expirydelta: 9,
Expand All @@ -285,7 +285,7 @@ fn test_keysend() {
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
)
.unwrap(),
short_channel_id: "12345x678x90".to_string(),
scid: "12345x678x90".to_string(),
feebase: Some(Amount { msat: 123 }),
feeprop: 1234,
expirydelta: 9,
Expand Down
4 changes: 4 additions & 0 deletions cln-rpc/src/model.rs

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

79 changes: 75 additions & 4 deletions cln-rpc/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,20 +881,91 @@ impl Serialize for RoutehintList {
}

impl<'de> Deserialize<'de> for RoutehintList {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
todo!("Required once we roundtrip, but not necessary for cln-rpc itself")
let hints: Vec<Routehint> = Vec::deserialize(deserializer)?;

Ok(RoutehintList { hints })
}
}

impl<'de> Deserialize<'de> for Routehint {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
todo!("Required once we roundtrip, but not necessary for cln-rpc itself")
let hops: Vec<Routehop> = Vec::deserialize(deserializer)?;

Ok(Routehint { hops })
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DecodeRoutehop {
pub pubkey: PublicKey,
pub short_channel_id: ShortChannelId,
pub fee_base_msat: Amount,
pub fee_proportional_millionths: u32,
pub cltv_expiry_delta: u16,
}

#[derive(Clone, Debug)]
pub struct DecodeRoutehint {
pub hops: Vec<DecodeRoutehop>,
}

#[derive(Clone, Debug)]
pub struct DecodeRoutehintList {
pub hints: Vec<DecodeRoutehint>,
}

impl Serialize for DecodeRoutehint {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = serializer.serialize_seq(Some(self.hops.len()))?;
for e in self.hops.iter() {
seq.serialize_element(e)?;
}
seq.end()
}
}

impl Serialize for DecodeRoutehintList {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = serializer.serialize_seq(Some(self.hints.len()))?;
for e in self.hints.iter() {
seq.serialize_element(e)?;
}
seq.end()
}
}

impl<'de> Deserialize<'de> for DecodeRoutehintList {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let hints: Vec<DecodeRoutehint> = Vec::deserialize(deserializer)?;

Ok(DecodeRoutehintList { hints })
}
}

impl<'de> Deserialize<'de> for DecodeRoutehint {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let hops: Vec<DecodeRoutehop> = Vec::deserialize(deserializer)?;

Ok(DecodeRoutehint { hops })
}
}

Expand Down
1 change: 1 addition & 0 deletions contrib/msggen/msggen/gen/grpc/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
"outpoint?": f"c.{name}.map(|o|o.into())",
"TlvStream?": f"c.{name}.map(|s| s.into())",
"RoutehintList?": f"c.{name}.map(|rl| rl.into())",
"DecodeRoutehintList?": f"c.{name}.map(|drl| drl.into())",
}.get(
typ, f"c.{name}" # default to just assignment
)
Expand Down
1 change: 1 addition & 0 deletions contrib/msggen/msggen/gen/grpc/unconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
"feerate?": f"c.{name}.map(|a| a.into())",
"outpoint?": f"c.{name}.map(|a| a.into())",
"RoutehintList?": f"c.{name}.map(|rl| rl.into())",
"DecodeRoutehintList?": f"c.{name}.map(|drl| drl.into())",
"short_channel_id": f"cln_rpc::primitives::ShortChannelId::from_str(&c.{name}).unwrap()",
"short_channel_id?": f"c.{name}.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap())",
"secret": f"c.{name}.try_into().unwrap()",
Expand Down
34 changes: 33 additions & 1 deletion contrib/msggen/msggen/gen/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def decamelcase(c):
override = {
"ListPeers.peers[].channels[].state_changes[]": None,
}
override_field = {
'RoutehintList': '"routes": [[decodekeysend_routes2py(i) for i in routehints] for routehints in m.routes]',
'DecodeRoutehintList': '"routes": [[decodepay_routes2py(i) for i in routehints] for routehints in m.routes]',
}


class Grpc2PyGenerator(IGenerator):
Expand Down Expand Up @@ -91,6 +95,32 @@ def remove_default(d):

self.generate_responses(service)

self.write("""\


def decodekeysend_routes2py(m): # manual override
return remove_default({
"expirydelta": m.expirydelta,
"feebase": amount2msat(m.feebase),
"feeprop": m.feeprop,
"id": hexlify(m.id),
"scid": m.scid,
})
""")

self.write("""\


def decodepay_routes2py(m): # manual override
return remove_default({
"cltv_expiry_delta": m.cltv_expiry_delta,
"fee_base_msat": amount2msat(m.fee_base_msat),
"fee_proportional_millionths": m.fee_proportional_millionths,
"pubkey": hexlify(m.pubkey),
"short_channel_id": m.short_channel_id,
})
""")

def generate_enum(self, prefix, field: EnumField):
name = field.name.normalized()
prefix = f"{prefix}_{str(name).lower()}"
Expand Down Expand Up @@ -130,7 +160,9 @@ def {converter_name}(m):

for f in field.fields:
name = f.normalized()
if isinstance(f, PrimitiveField):
if isinstance(f, PrimitiveField) and f.typename in override_field:
self.write(f' {override_field[f.typename]}, # OverrideField in {f.typename}\n', cleanup=False)
elif isinstance(f, PrimitiveField):
typ = f.typename

rhs = self.converters[typ].format(name=f.name)
Expand Down
Loading