mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
msggen: Add RoutehintList as a primitive
This commit is contained in:
parent
ec5cd92580
commit
ef145c7900
6 changed files with 65 additions and 4 deletions
|
@ -58,4 +58,18 @@ message Feerate {
|
|||
message OutputDesc {
|
||||
string address = 1;
|
||||
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::{
|
||||
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 {
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ impl Serialize for Feerate {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let s: String = self.into();
|
||||
let s: String = self.into();
|
||||
serializer.serialize_str(&s)
|
||||
}
|
||||
}
|
||||
|
@ -425,3 +425,22 @@ impl Serialize for OutputDesc {
|
|||
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):
|
||||
typ = f.itemtype.typename
|
||||
mapping = {
|
||||
'hex': f'hex::decode(s).unwrap()',
|
||||
'hex': f'hex::encode(s)',
|
||||
'u32': f's.clone()',
|
||||
}.get(typ, f's.into()')
|
||||
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())',
|
||||
'feerate': f'c.{name}.as_ref().unwrap().into()',
|
||||
'feerate?': f'c.{name}.as_ref().map(|a| a.into())',
|
||||
'RoutehintList?': f'c.{name}.clone().map(|rl| rl.into())',
|
||||
}.get(
|
||||
typ,
|
||||
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)
|
||||
InvoiceExposeprivatechannelsField = PrimitiveField("boolean", None, 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
|
||||
overrides = {
|
||||
'Invoice.label': InvoiceLabelField,
|
||||
|
@ -350,6 +351,7 @@ overrides = {
|
|||
'ListDatastore.key': DatastoreKeyField,
|
||||
'Invoice.exposeprivatechannels': InvoiceExposeprivatechannelsField,
|
||||
'Pay.exclude': PayExclude,
|
||||
'KeySend.routehints': RoutehintListField,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ def gen_array(a):
|
|||
return ("", "") # Override said not to include
|
||||
|
||||
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"
|
||||
|
||||
return (defi, decl)
|
||||
|
|
Loading…
Add table
Reference in a new issue