Skip to content

Commit c96981b

Browse files
authored
Merge pull request #91 from TheBlueMatt/main
0.0.111
2 parents eee3524 + 709706e commit c96981b

35 files changed

+5574
-1254
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
git clone https://github.com/rust-bitcoin/rust-lightning
3939
cd rust-lightning
40-
git checkout 0.0.110-bindings
40+
git checkout 0.0.111-bindings
4141
- name: Rebuild bindings without std, and check the sample app builds + links
4242
run: ./genbindings.sh ./rust-lightning false
4343
- name: Rebuild bindings, and check the sample app builds + links
@@ -88,7 +88,7 @@ jobs:
8888
run: |
8989
git clone https://github.com/rust-bitcoin/rust-lightning
9090
cd rust-lightning
91-
git checkout 0.0.110-bindings
91+
git checkout 0.0.111-bindings
9292
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
9393
run: ./genbindings.sh ./rust-lightning true
9494
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/main.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
102102
},
103103
"lightning::util::ser::Readable"|"lightning::util::ser::ReadableArgs"|"lightning::util::ser::MaybeReadable" => {
104104
// Create the Result<Object, DecodeError> syn::Type
105-
let mut res_ty: syn::Type = parse_quote!(Result<#for_ty, ::ln::msgs::DecodeError>);
105+
let mut res_ty: syn::Type = parse_quote!(Result<#for_ty, lightning::ln::msgs::DecodeError>);
106106

107107
writeln!(w, "#[no_mangle]").unwrap();
108108
writeln!(w, "/// Read a {} from a byte array, created by {}_write", for_obj, for_obj).unwrap();
@@ -151,7 +151,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
151151
} else { unreachable!(); }
152152
} else { unreachable!(); }
153153
} else if t == "lightning::util::ser::MaybeReadable" {
154-
res_ty = parse_quote!(Result<Option<#for_ty>, ::ln::msgs::DecodeError>);
154+
res_ty = parse_quote!(Result<Option<#for_ty>, lightning::ln::msgs::DecodeError>);
155155
}
156156
write!(w, ") -> ").unwrap();
157157
types.write_c_type(w, &res_ty, Some(generics), false);
@@ -947,7 +947,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
947947
// mappings from a trai defined in a different file, we may mis-resolve or
948948
// fail to resolve the mapped types. Thus, we have to construct a new
949949
// resolver for the module that the trait was defined in here first.
950-
let trait_resolver = get_module_type_resolver!(full_trait_path, types.crate_libs, types.crate_types);
950+
let mut trait_resolver = get_module_type_resolver!(full_trait_path, types.crate_libs, types.crate_types);
951951
gen_types.learn_associated_types(trait_obj, &trait_resolver);
952952
let mut impl_associated_types = HashMap::new();
953953
for item in i.items.iter() {
@@ -1107,17 +1107,12 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
11071107
_ => {}
11081108
}
11091109
}
1110-
if uncallable_function {
1111-
let mut trait_resolver = get_module_type_resolver!(full_trait_path, $types.crate_libs, $types.crate_types);
1112-
write_method_params(w, &$trait_meth.sig, "c_void", &mut trait_resolver, Some(&meth_gen_types), true, true);
1113-
} else {
1114-
write_method_params(w, &$m.sig, "c_void", $types, Some(&meth_gen_types), true, true);
1115-
}
1110+
write_method_params(w, &$trait_meth.sig, "c_void", &mut trait_resolver, Some(&meth_gen_types), true, true);
11161111
write!(w, " {{\n\t").unwrap();
11171112
if uncallable_function {
11181113
write!(w, "unreachable!();").unwrap();
11191114
} else {
1120-
write_method_var_decl_body(w, &$m.sig, "", $types, Some(&meth_gen_types), false);
1115+
write_method_var_decl_body(w, &$trait_meth.sig, "", &mut trait_resolver, Some(&meth_gen_types), false);
11211116
let mut takes_self = false;
11221117
for inp in $m.sig.inputs.iter() {
11231118
if let syn::FnArg::Receiver(_) = inp {
@@ -1130,6 +1125,14 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
11301125
if idx != 0 { t_gen_args += ", " };
11311126
t_gen_args += "_"
11321127
}
1128+
// rustc doesn't like <_> if the _ is actually a lifetime, so
1129+
// if all the parameters are lifetimes just skip it.
1130+
let mut nonlifetime_param = false;
1131+
for param in $trait.generics.params.iter() {
1132+
if let syn::GenericParam::Lifetime(_) = param {}
1133+
else { nonlifetime_param = true; }
1134+
}
1135+
if !nonlifetime_param { t_gen_args = String::new(); }
11331136
if takes_self {
11341137
write!(w, "<native{} as {}<{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap();
11351138
} else {
@@ -1147,7 +1150,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
11471150
},
11481151
_ => {},
11491152
}
1150-
write_method_call_params(w, &$m.sig, "", $types, Some(&meth_gen_types), &real_type, false);
1153+
write_method_call_params(w, &$trait_meth.sig, "", &mut trait_resolver, Some(&meth_gen_types), &real_type, false);
11511154
}
11521155
write!(w, "\n}}\n").unwrap();
11531156
if let syn::ReturnType::Type(_, rtype) = &$m.sig.output {
@@ -1185,7 +1188,6 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
11851188
assert!(meth.default.is_some());
11861189
let old_gen_types = gen_types;
11871190
gen_types = GenericTypes::new(Some(resolved_path.clone()));
1188-
let mut trait_resolver = get_module_type_resolver!(full_trait_path, types.crate_libs, types.crate_types);
11891191
impl_meth!(meth, meth, full_trait_path, trait_obj, "", &mut trait_resolver);
11901192
gen_types = old_gen_types;
11911193
},

c-bindings-gen/src/types.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn export_status(attrs: &[syn::Attribute]) -> ExportStatus {
147147
}
148148

149149
pub fn assert_simple_bound(bound: &syn::TraitBound) {
150-
if bound.paren_token.is_some() || bound.lifetimes.is_some() { unimplemented!(); }
150+
if bound.paren_token.is_some() { unimplemented!(); }
151151
if let syn::TraitBoundModifier::Maybe(_) = bound.modifier { unimplemented!(); }
152152
}
153153

@@ -936,6 +936,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
936936
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature"),
937937
"bitcoin::secp256k1::SecretKey" if is_ref => Some("*const [u8; 32]"),
938938
"bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey"),
939+
"bitcoin::secp256k1::Scalar" if is_ref => Some("*const crate::c_types::BigEndianScalar"),
940+
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar"),
941+
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
942+
939943
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"),
940944
"bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
941945
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
@@ -1021,6 +1025,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10211025
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(""),
10221026
"bitcoin::secp256k1::SecretKey" if is_ref => Some("&::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *"),
10231027
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(""),
1028+
"bitcoin::secp256k1::Scalar" if !is_ref => Some(""),
1029+
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes("),
1030+
10241031
"bitcoin::blockdata::script::Script" if is_ref => Some("&::bitcoin::blockdata::script::Script::from(Vec::from("),
10251032
"bitcoin::blockdata::script::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("),
10261033
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("&"),
@@ -1104,6 +1111,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11041111
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(".into_rust()"),
11051112
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(".into_rust()"),
11061113
"bitcoin::secp256k1::SecretKey" if is_ref => Some("}[..]).unwrap()"),
1114+
"bitcoin::secp256k1::Scalar" if !is_ref => Some(".into_rust()"),
1115+
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".data)"),
1116+
11071117
"bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"),
11081118
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"),
11091119
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(".into_bitcoin()"),
@@ -1196,6 +1206,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11961206
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature::from_rust(&"),
11971207
"bitcoin::secp256k1::SecretKey" if is_ref => Some(""),
11981208
"bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey::from_rust("),
1209+
"bitcoin::secp256k1::Scalar" if !is_ref => Some("crate::c_types::BigEndianScalar::from_rust("),
1210+
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
1211+
11991212
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
12001213
"bitcoin::blockdata::script::Script" if !is_ref => Some(""),
12011214
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("crate::c_types::Transaction::from_bitcoin("),
@@ -1273,6 +1286,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12731286
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(")"),
12741287
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(")"),
12751288
"bitcoin::secp256k1::SecretKey" if is_ref => Some(".as_ref()"),
1289+
"bitcoin::secp256k1::Scalar" if !is_ref => Some(")"),
1290+
"bitcoin::secp256k1::ecdh::SharedSecret" if !is_ref => Some(".secret_bytes() }"),
1291+
12761292
"bitcoin::blockdata::script::Script" if is_ref => Some("[..])"),
12771293
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"),
12781294
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(")"),
@@ -1381,7 +1397,19 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13811397
if let Some(resolved) = self.maybe_resolve_path(&p.path, generics) {
13821398
if self.c_type_has_inner_from_path(&resolved) { return true; }
13831399
if self.is_primitive(&resolved) { return false; }
1384-
if self.c_type_from_path(&resolved, false, false).is_some() { true } else { false }
1400+
// We want to move to using `Option_` mappings where possible rather than
1401+
// manual mappings, as it makes downstream bindings simpler and is more
1402+
// clear for users. Thus, we default to false but override for a few
1403+
// types which had mappings defined when we were avoiding the `Option_`s.
1404+
match &resolved as &str {
1405+
"lightning::ln::PaymentSecret" => true,
1406+
"lightning::ln::PaymentHash" => true,
1407+
"lightning::ln::PaymentPreimage" => true,
1408+
"lightning::ln::channelmanager::PaymentId" => true,
1409+
"bitcoin::hash_types::BlockHash" => true,
1410+
"secp256k1::PublicKey"|"bitcoin::secp256k1::PublicKey" => true,
1411+
_ => false,
1412+
}
13851413
} else { unimplemented!(); }
13861414
},
13871415
syn::Type::Tuple(_) => false,
@@ -1456,7 +1484,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14561484
(".is_none() { core::ptr::null_mut() } else { ".to_owned(), format!("({}.unwrap())", var_access))
14571485
], " }", ContainerPrefixLocation::OutsideConv));
14581486
}
1459-
} else if self.is_primitive(&inner_path) || self.c_type_from_path(&inner_path, false, false).is_none() {
1487+
} else if !self.is_transparent_container("Option", is_ref, [single_contained.unwrap()].iter().map(|a| *a), generics) {
14601488
if self.is_primitive(&inner_path) || (!is_contained_ref && !is_ref) || only_contained_has_inner {
14611489
let inner_name = self.get_c_mangled_container_type(vec![single_contained.unwrap()], generics, "Option").unwrap();
14621490
return Some(("if ", vec![

lightning-c-bindings/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ no-std = ["bitcoin/no-std", "lightning/no-std", "lightning-invoice/no-std", "cor
1919
std = ["bitcoin/std", "lightning/std", "lightning-invoice/std"]
2020

2121
[dependencies]
22-
bitcoin = { version = "0.28", default-features = false }
23-
secp256k1 = { version = "0.22", features = ["global-context", "recovery"] }
22+
bitcoin = { version = "0.29", default-features = false }
23+
secp256k1 = { version = "0.24", features = ["global-context", "recovery"] }
2424
# Note that the following line is matched by genbindings to update the path
25-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.110-bindings", default-features = false }
26-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.110-bindings", default-features = false }
27-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.110-bindings", default-features = false }
28-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.110-bindings", default-features = false }
29-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.110-bindings", default-features = false }
25+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
26+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
27+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
28+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
29+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
3030

3131
core2 = { version = "0.3.0", optional = true, default-features = false }
3232

0 commit comments

Comments
 (0)