mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
msggen: Add RoutehintList as a primitive
This commit is contained in:
committed by
Rusty Russell
parent
ec5cd92580
commit
ef145c7900
@@ -59,3 +59,17 @@ message OutputDesc {
|
|||||||
string address = 1;
|
string address = 1;
|
||||||
Amount amount = 2;
|
Amount amount = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message RouteHop {
|
||||||
|
bytes id = 1;
|
||||||
|
string short_channel_id = 2;
|
||||||
|
Amount feebase = 3;
|
||||||
|
uint32 feeprop = 4;
|
||||||
|
uint32 expirydelta = 5;
|
||||||
|
}
|
||||||
|
message Routehint {
|
||||||
|
repeated RouteHop hops = 1;
|
||||||
|
}
|
||||||
|
message RoutehintList {
|
||||||
|
repeated Routehint hints = 2;
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ tonic::include_proto!("cln");
|
|||||||
|
|
||||||
use cln_rpc::primitives::{
|
use cln_rpc::primitives::{
|
||||||
Amount as JAmount, AmountOrAll as JAmountOrAll, AmountOrAny as JAmountOrAny,
|
Amount as JAmount, AmountOrAll as JAmountOrAll, AmountOrAny as JAmountOrAny,
|
||||||
Feerate as JFeerate, OutputDesc as JOutputDesc, Outpoint as JOutpoint,
|
Feerate as JFeerate, Outpoint as JOutpoint, OutputDesc as JOutputDesc,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl From<JAmount> for Amount {
|
impl From<JAmount> for Amount {
|
||||||
@@ -101,3 +101,28 @@ impl From<&AmountOrAny> for JAmountOrAny {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<RouteHop> for cln_rpc::primitives::Routehop {
|
||||||
|
fn from(c: RouteHop) -> Self {
|
||||||
|
Self {
|
||||||
|
id: hex::encode(c.id),
|
||||||
|
scid: c.short_channel_id,
|
||||||
|
feebase: c.feebase.as_ref().unwrap().into(),
|
||||||
|
feeprop: c.feeprop,
|
||||||
|
expirydelta: c.expirydelta as u16,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<Routehint> for cln_rpc::primitives::Routehint {
|
||||||
|
fn from(c: Routehint) -> Self {
|
||||||
|
Self {
|
||||||
|
hops: c.hops.into_iter().map(|h| h.into()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<RoutehintList> for cln_rpc::primitives::RoutehintList {
|
||||||
|
fn from(c: RoutehintList) -> Self {
|
||||||
|
Self {
|
||||||
|
hints: c.hints.into_iter().map(|h| h.into()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -425,3 +425,22 @@ impl Serialize for OutputDesc {
|
|||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Routehop {
|
||||||
|
pub id: String,
|
||||||
|
pub scid: String,
|
||||||
|
pub feebase: Amount,
|
||||||
|
pub feeprop: u32,
|
||||||
|
pub expirydelta: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Routehint {
|
||||||
|
pub hops: Vec<Routehop>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct RoutehintList {
|
||||||
|
pub hints: Vec<Routehint>,
|
||||||
|
}
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator):
|
|||||||
if isinstance(f, ArrayField):
|
if isinstance(f, ArrayField):
|
||||||
typ = f.itemtype.typename
|
typ = f.itemtype.typename
|
||||||
mapping = {
|
mapping = {
|
||||||
'hex': f'hex::decode(s).unwrap()',
|
'hex': f'hex::encode(s)',
|
||||||
'u32': f's.clone()',
|
'u32': f's.clone()',
|
||||||
}.get(typ, f's.into()')
|
}.get(typ, f's.into()')
|
||||||
self.write(f"{name}: c.{name}.iter().map(|s| {mapping}).collect(),\n", numindent=3)
|
self.write(f"{name}: c.{name}.iter().map(|s| {mapping}).collect(),\n", numindent=3)
|
||||||
@@ -410,6 +410,7 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator):
|
|||||||
'msat|any?': f'c.{name}.as_ref().map(|a| a.into())',
|
'msat|any?': f'c.{name}.as_ref().map(|a| a.into())',
|
||||||
'feerate': f'c.{name}.as_ref().unwrap().into()',
|
'feerate': f'c.{name}.as_ref().unwrap().into()',
|
||||||
'feerate?': f'c.{name}.as_ref().map(|a| a.into())',
|
'feerate?': f'c.{name}.as_ref().map(|a| a.into())',
|
||||||
|
'RoutehintList?': f'c.{name}.clone().map(|rl| rl.into())',
|
||||||
}.get(
|
}.get(
|
||||||
typ,
|
typ,
|
||||||
f'c.{name}.clone()' # default to just assignment
|
f'c.{name}.clone()' # default to just assignment
|
||||||
|
|||||||
@@ -340,6 +340,7 @@ InvoiceLabelField = PrimitiveField("string", None, None)
|
|||||||
DatastoreKeyField = ArrayField(itemtype=PrimitiveField("string", None, None), dims=1, path=None, description=None)
|
DatastoreKeyField = ArrayField(itemtype=PrimitiveField("string", None, None), dims=1, path=None, description=None)
|
||||||
InvoiceExposeprivatechannelsField = PrimitiveField("boolean", None, None)
|
InvoiceExposeprivatechannelsField = PrimitiveField("boolean", None, None)
|
||||||
PayExclude = ArrayField(itemtype=PrimitiveField("string", None, None), dims=1, path=None, description=None)
|
PayExclude = ArrayField(itemtype=PrimitiveField("string", None, None), dims=1, path=None, description=None)
|
||||||
|
RoutehintListField = PrimitiveField("RoutehintList", None, None)
|
||||||
# Override fields with manually managed types, fieldpath -> field mapping
|
# Override fields with manually managed types, fieldpath -> field mapping
|
||||||
overrides = {
|
overrides = {
|
||||||
'Invoice.label': InvoiceLabelField,
|
'Invoice.label': InvoiceLabelField,
|
||||||
@@ -350,6 +351,7 @@ overrides = {
|
|||||||
'ListDatastore.key': DatastoreKeyField,
|
'ListDatastore.key': DatastoreKeyField,
|
||||||
'Invoice.exposeprivatechannels': InvoiceExposeprivatechannelsField,
|
'Invoice.exposeprivatechannels': InvoiceExposeprivatechannelsField,
|
||||||
'Pay.exclude': PayExclude,
|
'Pay.exclude': PayExclude,
|
||||||
|
'KeySend.routehints': RoutehintListField,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ def gen_array(a):
|
|||||||
return ("", "") # Override said not to include
|
return ("", "") # Override said not to include
|
||||||
|
|
||||||
itemtype = typemap.get(itemtype, itemtype)
|
itemtype = typemap.get(itemtype, itemtype)
|
||||||
alias = a.name.normalized()[:-2] # Strip the `[]` suffix for arrays.
|
alias = a.name.normalized()
|
||||||
defi = f" #[serde(alias = \"{alias}\")]\n pub {name}: {'Vec<'*a.dims}{itemtype}{'>'*a.dims},\n"
|
defi = f" #[serde(alias = \"{alias}\")]\n pub {name}: {'Vec<'*a.dims}{itemtype}{'>'*a.dims},\n"
|
||||||
|
|
||||||
return (defi, decl)
|
return (defi, decl)
|
||||||
|
|||||||
Reference in New Issue
Block a user