@@ -7,6 +7,8 @@ use crate::FFIResult;
7
7
use lightning:: chain:: chaininterface:: ChainError ;
8
8
use lightning:: ln:: channelmanager:: PaymentHash ;
9
9
use lightning:: ln:: router:: { RouteHop , Route } ;
10
+ use lightning:: util:: ser:: Readable ;
11
+ use bitcoin_hashes:: core:: fmt:: { Formatter , Error } ;
10
12
11
13
macro_rules! array_struct{
12
14
(
@@ -34,6 +36,12 @@ macro_rules! array_struct{
34
36
}
35
37
}
36
38
39
+ impl <' a> std:: fmt:: Debug for $name<' a> {
40
+ fn fmt( & self , f: & mut Formatter <' _>) -> std:: fmt:: Result {
41
+ hex:: encode( self ) . fmt( f)
42
+ }
43
+ }
44
+
37
45
impl <' a> AsRef <[ $ty] > for $name<' a> {
38
46
fn as_ref( & self ) -> & [ $ty] {
39
47
unsafe_block!( "" => std:: slice:: from_raw_parts( self . ptr, self . len) )
@@ -132,72 +140,14 @@ impl From<FFIChainError> for ChainError {
132
140
}
133
141
}
134
142
135
- array_struct ! ( NodeFeatures , u8 ) ;
136
-
137
- impl < ' a > From < NodeFeatures < ' a > > for lightning:: ln:: features:: NodeFeatures {
138
- fn from ( value : NodeFeatures < ' a > ) -> Self {
139
- let v = value. as_ref ( ) . to_vec ( ) ;
140
- lightning:: ln:: features:: NodeFeatures :: from_le_bytes ( v)
141
- }
142
- }
143
-
144
- array_struct ! ( ChannelFeatures , u8 ) ;
145
- impl < ' a > From < ChannelFeatures < ' a > > for lightning:: ln:: features:: ChannelFeatures {
146
- fn from ( value : ChannelFeatures < ' a > ) -> Self {
147
- let v = value. as_ref ( ) . to_vec ( ) ;
148
- lightning:: ln:: features:: ChannelFeatures :: from_le_bytes ( v)
149
- }
150
- }
151
-
152
-
153
-
154
- #[ derive( Clone ) ]
155
- #[ repr( C ) ]
156
- pub struct FFIRouteHop < ' a > {
157
- /// The node_id of the node at this hop.
158
- pub pubkey : PublicKey < ' a > ,
159
- /// The node_announcement features of the node at this hop. For the last hop, these may be
160
- /// amended to match the features present in the invoice this node generated.
161
- pub node_features : NodeFeatures < ' a > ,
162
- /// The channel that should be used from the previous hop to reach this node.
163
- pub short_channel_id : u64 ,
164
- /// The channel_announcement features of the channel that should be used from the previous hop
165
- /// to reach this node.
166
- pub channel_features : ChannelFeatures < ' a > ,
167
- /// The fee taken on this hop. For the last hop, this should be the full value of the payment.
168
- pub fee_msat : u64 ,
169
- /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
170
- /// expected at the destination, in excess of the current block height.
171
- pub cltv_expiry_delta : u32 ,
172
- }
173
-
174
- impl < ' a > TryFrom < FFIRouteHop < ' a > > for RouteHop {
175
- type Error = FFIResult ;
176
-
177
- fn try_from ( value : FFIRouteHop < ' a > ) -> Result < Self , Self :: Error > {
178
- Ok ( RouteHop {
179
- pubkey : value. pubkey . try_into ( ) ?,
180
- node_features : value. node_features . into ( ) ,
181
- short_channel_id : value. short_channel_id ,
182
- channel_features : value. channel_features . into ( ) ,
183
- fee_msat : value. fee_msat ,
184
- cltv_expiry_delta : value. cltv_expiry_delta
185
- } )
186
- }
187
- }
188
-
189
- array_struct ! ( FFIRoute , FFIRouteHop <' a>) ;
143
+ array_struct ! ( FFIRoute , u8 ) ;
190
144
191
145
impl < ' a > TryFrom < FFIRoute < ' a > > for Route {
192
- type Error = FFIResult ;
146
+ type Error = lightning :: ln :: msgs :: DecodeError ;
193
147
194
148
fn try_from ( value : FFIRoute < ' a > ) -> Result < Self , Self :: Error > {
195
- let r: & [ FFIRouteHop ] = value. as_ref ( ) ;
196
- let mut hops: Vec < RouteHop > = Vec :: with_capacity ( r. len ( ) ) ;
197
- for i in r. iter ( ) {
198
- hops. push ( i. clone ( ) . try_into ( ) ?) ;
199
- }
200
- Ok ( Route { hops } )
149
+ let mut slice = value. as_ref ( ) ;
150
+ <Route as Readable >:: read ( & mut slice)
201
151
}
202
152
}
203
153
0 commit comments