Skip to content

Commit 822fc4d

Browse files
authored
Merge pull request #141 from TheBlueMatt/0.2
Update for LDK 0.2
2 parents d31c8f6 + 0e88304 commit 822fc4d

File tree

103 files changed

+75386
-60167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+75386
-60167
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ jobs:
2929
uses: actions/checkout@v2
3030
with:
3131
fetch-depth: 0
32+
- name: Pin syn and quote to meet MSRV
33+
working-directory: lightning-c-bindings
34+
run: |
35+
cargo update -p syn --precise "2.0.106" --verbose
36+
cargo update -p quote --precise "1.0.41" --verbose
3237
- name: Sanity test bindings against Cargo.toml RL
3338
working-directory: lightning-c-bindings
3439
run: |
@@ -46,7 +51,9 @@ jobs:
4651
run: |
4752
git clone https://github.com/rust-bitcoin/rust-lightning
4853
cd rust-lightning
49-
git checkout 0.1-bindings
54+
git checkout 0.2-bindings
55+
cargo update -p syn --precise "2.0.106" --verbose
56+
cargo update -p quote --precise "1.0.41" --verbose
5057
- name: Fix Github Actions to not be broken
5158
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
5259
- name: Pin proc-macro and quote to meet MSRV
@@ -89,6 +96,11 @@ jobs:
8996
uses: actions/checkout@v2
9097
with:
9198
fetch-depth: 0
99+
- name: Pin syn and quote to meet MSRV
100+
working-directory: lightning-c-bindings
101+
run: |
102+
cargo update -p syn --precise "2.0.106" --verbose
103+
cargo update -p quote --precise "1.0.41" --verbose
92104
- name: Sanity test bindings against Cargo.toml RL
93105
working-directory: lightning-c-bindings
94106
run: |
@@ -106,9 +118,16 @@ jobs:
106118
run: |
107119
git clone https://github.com/rust-bitcoin/rust-lightning
108120
cd rust-lightning
109-
git checkout 0.1-bindings
121+
git checkout 0.2-bindings
122+
cargo update -p syn --precise "2.0.106" --verbose
123+
cargo update -p quote --precise "1.0.41" --verbose
110124
- name: Fix Github Actions to not be broken
111125
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
126+
- name: Pin proc-macro and quote to meet MSRV
127+
run: |
128+
cd c-bindings-gen
129+
cargo update -p quote --precise "1.0.30" --verbose
130+
cargo update -p proc-macro2 --precise "1.0.65" --verbose
112131
- name: Fetch MacOS SDK
113132
run: |
114133
wget https://bitcoincore.org/depends-sources/sdks/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
@@ -152,7 +171,7 @@ jobs:
152171
run: |
153172
git clone https://github.com/rust-bitcoin/rust-lightning
154173
cd rust-lightning
155-
git checkout 0.1-bindings
174+
git checkout 0.2-bindings
156175
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
157176
run: ./genbindings.sh ./rust-lightning true
158177
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/blocks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ pub fn write_vec_block<W: std::io::Write>(w: &mut W, mangled_container: &str, in
226226
writeln!(w, "impl {} {{", mangled_container).unwrap();
227227
writeln!(w, "\t#[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec<{}> {{", inner_type).unwrap();
228228
writeln!(w, "\t\tif self.datalen == 0 {{ return Vec::new(); }}").unwrap();
229-
writeln!(w, "\t\tlet ret = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }}.into();").unwrap();
229+
writeln!(w, "\t\tlet ret = unsafe {{ Box::from_raw(crate::c_types::from_raw_parts_safer_mut(self.data, self.datalen)) }}.into();").unwrap();
230230
writeln!(w, "\t\tself.data = core::ptr::null_mut();").unwrap();
231231
writeln!(w, "\t\tself.datalen = 0;").unwrap();
232232
writeln!(w, "\t\tret").unwrap();
233233
writeln!(w, "\t}}").unwrap();
234234
writeln!(w, "\t#[allow(unused)] pub(crate) fn as_slice(&self) -> &[{}] {{", inner_type).unwrap();
235-
writeln!(w, "\t\tunsafe {{ core::slice::from_raw_parts_mut(self.data, self.datalen) }}").unwrap();
235+
writeln!(w, "\t\tunsafe {{ crate::c_types::from_raw_parts_safer_mut(self.data, self.datalen) }}").unwrap();
236236
writeln!(w, "\t}}").unwrap();
237237
writeln!(w, "}}").unwrap();
238238

@@ -250,15 +250,15 @@ pub fn write_vec_block<W: std::io::Write>(w: &mut W, mangled_container: &str, in
250250
writeln!(w, "impl Drop for {} {{", mangled_container).unwrap();
251251
writeln!(w, "\tfn drop(&mut self) {{").unwrap();
252252
writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap();
253-
writeln!(w, "\t\tlet _ = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
253+
writeln!(w, "\t\tlet _ = unsafe {{ Box::from_raw(crate::c_types::from_raw_parts_safer_mut(self.data, self.datalen)) }};").unwrap();
254254
writeln!(w, "\t}}").unwrap();
255255
writeln!(w, "}}").unwrap();
256256
if clonable {
257257
writeln!(w, "impl Clone for {} {{", mangled_container).unwrap();
258258
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
259259
writeln!(w, "\t\tlet mut res = Vec::new();").unwrap();
260260
writeln!(w, "\t\tif self.datalen == 0 {{ return Self::from(res); }}").unwrap();
261-
writeln!(w, "\t\tres.extend_from_slice(unsafe {{ core::slice::from_raw_parts_mut(self.data, self.datalen) }});").unwrap();
261+
writeln!(w, "\t\tres.extend_from_slice(unsafe {{ crate::c_types::from_raw_parts_safer_mut(self.data, self.datalen) }});").unwrap();
262262
writeln!(w, "\t\tSelf::from(res)").unwrap();
263263
writeln!(w, "\t}}").unwrap();
264264
writeln!(w, "}}").unwrap();

c-bindings-gen/src/main.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
108108
}
109109
writeln!(w, "}}").unwrap();
110110
},
111-
"lightning::util::ser::Readable"|"lightning::util::ser::ReadableArgs"|"lightning::util::ser::MaybeReadable" => {
111+
"lightning::util::ser::Readable"|"lightning::util::ser::LengthReadable"|"lightning::util::ser::ReadableArgs"|"lightning::util::ser::MaybeReadable" => {
112112
// Create the Result<Object, DecodeError> syn::Type
113113
let mut res_ty: syn::Type = parse_quote!(Result<#for_ty, lightning::ln::msgs::DecodeError>);
114114

@@ -850,7 +850,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
850850
writeln_arg_docs(w, &$field.attrs, "", types, Some(&gen_types), vec![].drain(..), Some(&ref_type));
851851
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_get_{}(this_ptr: &{}) -> ", struct_name, $new_name, struct_name).unwrap();
852852
types.write_c_type(w, &ref_type, Some(&gen_types), true);
853-
write!(w, " {{\n\tlet mut inner_val = &mut this_ptr.get_native_mut_ref().{};\n\t", $real_name).unwrap();
853+
write!(w, " {{\n\tlet mut inner_val = &mut {}::get_native_mut_ref(this_ptr).{};\n\t", struct_name, $real_name).unwrap();
854854
let local_var = types.write_to_c_conversion_from_ownable_ref_new_var(w, &format_ident!("inner_val"), &ref_type, Some(&gen_types));
855855
if local_var { write!(w, "\n\t").unwrap(); }
856856
types.write_to_c_conversion_inline_prefix(w, &ref_type, Some(&gen_types), true);
@@ -867,7 +867,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
867867
writeln_arg_docs(w, &$field.attrs, "", types, Some(&gen_types), vec![].drain(..), Some(&$field.ty));
868868
writeln!(w, "///\n/// Returns a copy of the field.").unwrap();
869869
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_get_{}(this_ptr: &{}) -> {}", struct_name, $new_name, struct_name, s).unwrap();
870-
write!(w, " {{\n\tlet mut inner_val = this_ptr.get_native_mut_ref().{}.clone();\n\t", $real_name).unwrap();
870+
write!(w, " {{\n\tlet mut inner_val = {}::get_native_mut_ref(this_ptr).{}.clone();\n\t", struct_name, $real_name).unwrap();
871871
let local_var = types.write_to_c_conversion_new_var(w, &format_ident!("inner_val"), &$field.ty, Some(&gen_types), true);
872872
if local_var { write!(w, "\n\t").unwrap(); }
873873
types.write_to_c_conversion_inline_prefix(w, &$field.ty, Some(&gen_types), true);
@@ -981,8 +981,6 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
981981
write!(w, "\t}}").unwrap();
982982
},
983983
syn::Fields::Unnamed(fields) => {
984-
assert!(!s.generics.params.iter()
985-
.any(|gen| if let syn::GenericParam::Lifetime(_) = gen { false } else { true }));
986984
writeln!(w, "{} (", types.maybe_resolve_ident(&s.ident).unwrap()).unwrap();
987985
for (idx, field) in fields.unnamed.iter().enumerate() {
988986
write!(w, "\t\t").unwrap();
@@ -1395,7 +1393,39 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
13951393
// instantiated.
13961394
return;
13971395
}
1398-
if path_matches_nongeneric(&trait_path.1, &["From"]) {
1396+
if path_matches_ignoring_generics(&trait_path.1, &["From"]) {
1397+
let from_ty;
1398+
if let syn::PathArguments::AngleBracketed(args) = &trait_path.1.segments.last().unwrap().arguments {
1399+
assert_eq!(args.args.len(), 1);
1400+
if let syn::GenericArgument::Type(ref ty) = &args.args[0] {
1401+
from_ty = ty;
1402+
} else {
1403+
panic!("From needs arguments?");
1404+
}
1405+
} else {
1406+
panic!("From needs arguments?");
1407+
}
1408+
let to_std = resolved_path.starts_with("core::") || resolved_path.starts_with("std::");
1409+
if !to_std && types.understood_c_type(&from_ty, Some(&gen_types)) {
1410+
if let syn::Type::Path(from_path) = &from_ty {
1411+
let mut from_resolved_bytes = Vec::new();
1412+
types.write_c_type(&mut from_resolved_bytes, from_ty, Some(&gen_types), true);
1413+
let from_resolved = String::from_utf8(from_resolved_bytes).unwrap();
1414+
let from_ty_ident = from_resolved.rsplit("::").next().unwrap();
1415+
writeln!(w, "#[no_mangle]").unwrap();
1416+
writeln!(w, "/// Build a {ident} from a {from_ty_ident}").unwrap();
1417+
writeln!(w, "pub extern \"C\" fn {ident}_from_{from_ty_ident}(f: {from_resolved}) -> crate::{resolved_path} {{").unwrap();
1418+
write!(w, "\tlet from_obj = ").unwrap();
1419+
types.write_from_c_conversion_prefix(w, from_ty, Some(&gen_types));
1420+
write!(w, "f").unwrap();
1421+
types.write_from_c_conversion_suffix(w, from_ty, Some(&gen_types));
1422+
write!(w, ";\n\t").unwrap();
1423+
types.write_to_c_conversion_inline_prefix(w, &*i.self_ty, Some(&gen_types), true);
1424+
write!(w, "({resolved_path}::from(from_obj))").unwrap();
1425+
types.write_to_c_conversion_inline_suffix(w, &*i.self_ty, Some(&gen_types), true);
1426+
writeln!(w, "\n}}").unwrap();
1427+
} else { panic!("wat {:?}", from_ty); }
1428+
}
13991429
} else if path_matches_nongeneric(&trait_path.1, &["Default"]) {
14001430
writeln!(w, "/// Creates a \"default\" {}. See struct and individual field documentaiton for details on which values are used.", ident).unwrap();
14011431
write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_default() -> {} {{\n", ident, ident).unwrap();
@@ -1454,18 +1484,18 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
14541484
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
14551485
writeln!(w, "\t\tSelf {{").unwrap();
14561486
writeln!(w, "\t\t\tinner: if <*mut native{}>::is_null(self.inner) {{ core::ptr::null_mut() }} else {{", ident).unwrap();
1457-
writeln!(w, "\t\t\t\tObjOps::heap_alloc(unsafe {{ &*ObjOps::untweak_ptr(self.inner) }}.clone()) }},").unwrap();
1487+
writeln!(w, "\t\t\t\tObjOps::heap_alloc(Clone::clone(unsafe {{ &*ObjOps::untweak_ptr(self.inner) }})) }},").unwrap();
14581488
writeln!(w, "\t\t\tis_owned: true,").unwrap();
14591489
writeln!(w, "\t\t}}\n\t}}\n}}").unwrap();
14601490
writeln!(w, "#[allow(unused)]").unwrap();
14611491
writeln!(w, "/// Used only if an object of this type is returned as a trait impl by a method").unwrap();
14621492
writeln!(w, "pub(crate) extern \"C\" fn {}_clone_void(this_ptr: *const c_void) -> *mut c_void {{", ident).unwrap();
1463-
writeln!(w, "\tBox::into_raw(Box::new(unsafe {{ (*(this_ptr as *const native{})).clone() }})) as *mut c_void", ident).unwrap();
1493+
writeln!(w, "\tBox::into_raw(Box::new(Clone::clone(unsafe {{ &*(this_ptr as *const native{}) }}))) as *mut c_void", ident).unwrap();
14641494
writeln!(w, "}}").unwrap();
14651495
writeln!(w, "#[no_mangle]").unwrap();
14661496
writeln!(w, "/// Creates a copy of the {}", ident).unwrap();
14671497
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", ident, ident, ident).unwrap();
1468-
writeln!(w, "\torig.clone()").unwrap();
1498+
writeln!(w, "\tClone::clone(orig)").unwrap();
14691499
writeln!(w, "}}").unwrap();
14701500
} else if path_matches_nongeneric(&trait_path.1, &["FromStr"]) {
14711501
let mut err_opt = None;
@@ -2556,6 +2586,7 @@ fn main() {
25562586

25572587
// Write a few manually-defined types into the C++ header file
25582588
write_cpp_wrapper(&mut cpp_header_file, "Str", true, None);
2589+
write_cpp_wrapper(&mut cpp_header_file, "ECDSASignature", false, None);
25592590

25602591
// First parse the full crate's ASTs, caching them so that we can hold references to the AST
25612592
// objects in other datastructures:

c-bindings-gen/src/types.rs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ pub fn single_ident_generic_path_to_ident(p: &syn::Path) -> Option<&syn::Ident>
5656
} else { None }
5757
}
5858

59+
pub fn path_matches_ignoring_generics(p: &syn::Path, exp: &[&str]) -> bool {
60+
if p.segments.len() != exp.len() { return false; }
61+
for (seg, e) in p.segments.iter().zip(exp.iter()) {
62+
if &format!("{}", seg.ident) != *e { return false; }
63+
}
64+
true
65+
}
66+
5967
pub fn path_matches_nongeneric(p: &syn::Path, exp: &[&str]) -> bool {
6068
if p.segments.len() != exp.len() { return false; }
6169
for (seg, e) in p.segments.iter().zip(exp.iter()) {
@@ -576,6 +584,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
576584
Self::insert_primitive(&mut imports, "bool");
577585
Self::insert_primitive(&mut imports, "u128");
578586
Self::insert_primitive(&mut imports, "i64");
587+
Self::insert_primitive(&mut imports, "i32");
579588
Self::insert_primitive(&mut imports, "f64");
580589
Self::insert_primitive(&mut imports, "u64");
581590
Self::insert_primitive(&mut imports, "u32");
@@ -917,6 +926,11 @@ fn initial_clonable_types() -> HashSet<String> {
917926
// `write_c_mangled_container_path_intern` (which will add it here too), so we have to manually
918927
// add it on startup.
919928
res.insert("crate::c_types::derived::CVec_u8Z".to_owned());
929+
930+
// write_c_type_intern writes the empty string for the empty tuple. In order to ensure
931+
// COption_NoneZ is marked clonable, we have to support "cloning" "".
932+
res.insert("".to_owned());
933+
920934
res
921935
}
922936

@@ -1037,6 +1051,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10371051
match full_path {
10381052
"bool" => true,
10391053
"i64" => true,
1054+
"i32" => true,
10401055
"f64" => true,
10411056
"u64" => true,
10421057
"u32" => true,
@@ -1110,7 +1125,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11101125
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar"),
11111126
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
11121127

1113-
"bitcoin::amount::Amount" => Some("u64"),
1128+
"bitcoin::Amount"|"bitcoin::amount::Amount" => Some("u64"),
1129+
"bitcoin::Weight" => Some("u64"),
1130+
"bitcoin::Sequence" => Some("u32"),
11141131

11151132
"bitcoin::script::Script"|"bitcoin::Script" => Some("crate::c_types::u8slice"),
11161133
"bitcoin::script::ScriptBuf"|"bitcoin::ScriptBuf" => Some("crate::c_types::derived::CVec_u8Z"),
@@ -1160,7 +1177,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11601177
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
11611178
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
11621179

1163-
"lightning::io::Read" => Some("crate::c_types::u8slice"),
1180+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("crate::c_types::u8slice"),
11641181

11651182
_ => None,
11661183
}
@@ -1230,7 +1247,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12301247
"bitcoin::secp256k1::Scalar" if !is_ref => Some(""),
12311248
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes("),
12321249

1233-
"bitcoin::amount::Amount" => Some("::bitcoin::amount::Amount::from_sat("),
1250+
"bitcoin::Amount"|"bitcoin::amount::Amount" => Some("::bitcoin::amount::Amount::from_sat("),
1251+
"bitcoin::Weight" => Some("::bitcoin::Weight::from_wu("),
1252+
"bitcoin::Sequence" => Some("::bitcoin::Sequence("),
12341253

12351254
"bitcoin::script::Script"|"bitcoin::Script" => Some("::bitcoin::script::Script::from_bytes("),
12361255
"bitcoin::script::ScriptBuf"|"bitcoin::ScriptBuf" => Some("::bitcoin::script::ScriptBuf::from("),
@@ -1287,7 +1306,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12871306
"lightning::chain::ClaimId" if is_ref=> Some("&::lightning::chain::ClaimId( unsafe { *"),
12881307

12891308
// List of traits we map (possibly during processing of other files):
1290-
"lightning::io::Read" => Some("&mut "),
1309+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("&mut "),
12911310

12921311
_ => None,
12931312
}.map(|s| s.to_owned())
@@ -1349,7 +1368,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13491368
"bitcoin::secp256k1::Scalar" => Some(".into_rust()"),
13501369
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".data)"),
13511370

1352-
"bitcoin::amount::Amount" => Some(")"),
1371+
"bitcoin::Amount"|"bitcoin::amount::Amount" => Some(")"),
1372+
"bitcoin::Weight" => Some(")"),
1373+
"bitcoin::Sequence" => Some(")"),
13531374

13541375
"bitcoin::script::Script"|"bitcoin::Script" => Some(".to_slice())"),
13551376
"bitcoin::script::ScriptBuf"|"bitcoin::ScriptBuf" => Some(".into_rust())"),
@@ -1399,7 +1420,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13991420
if is_ref => Some(" })"),
14001421

14011422
// List of traits we map (possibly during processing of other files):
1402-
"lightning::io::Read" => Some(".to_reader()"),
1423+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some(".to_slice()"),
14031424

14041425
_ => None,
14051426
}.map(|s| s.to_owned())
@@ -1481,7 +1502,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14811502
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar::from_rust(&"),
14821503
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
14831504

1484-
"bitcoin::amount::Amount" => Some(""),
1505+
"bitcoin::Amount"|"bitcoin::amount::Amount" => Some(""),
1506+
"bitcoin::Weight" => Some(""),
1507+
"bitcoin::Sequence" => Some(""),
14851508

14861509
"bitcoin::script::Script"|"bitcoin::Script" => Some("crate::c_types::u8slice::from_slice("),
14871510
"bitcoin::script::ScriptBuf"|"bitcoin::ScriptBuf" => Some(""),
@@ -1530,7 +1553,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
15301553
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
15311554
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
15321555

1533-
"lightning::io::Read" => Some("crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec("),
1556+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec("),
15341557

15351558
_ => None,
15361559
}.map(|s| s.to_owned())
@@ -1594,7 +1617,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
15941617
"bitcoin::secp256k1::Scalar" if !is_ref => Some(")"),
15951618
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".secret_bytes() }"),
15961619

1597-
"bitcoin::amount::Amount" => Some(".to_sat()"),
1620+
"bitcoin::Amount"|"bitcoin::amount::Amount" => Some(".to_sat()"),
1621+
"bitcoin::Weight" => Some(".to_wu()"),
1622+
"bitcoin::Sequence" => Some(".0"),
15981623

15991624
"bitcoin::script::Script"|"bitcoin::Script" => Some(".as_ref())"),
16001625
"bitcoin::script::ScriptBuf"|"bitcoin::ScriptBuf" if is_ref => Some(".as_bytes().to_vec().into()"),
@@ -1640,7 +1665,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
16401665
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
16411666
if !is_ref => Some(".0 }"),
16421667

1643-
"lightning::io::Read" => Some("))"),
1668+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("))"),
16441669

16451670
_ => None,
16461671
}.map(|s| s.to_owned())
@@ -1661,7 +1686,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
16611686
/// TODO: We should never need to use this!
16621687
fn real_rust_type_mapping<'equiv>(&self, thing: &'equiv str) -> &'equiv str {
16631688
match thing {
1664-
"lightning::io::Read" => "crate::c_types::io::Read",
1689+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => "crate::c_types::io::Read",
16651690
_ => thing,
16661691
}
16671692
}

0 commit comments

Comments
 (0)