Matt Corallo [Tue, 4 Jun 2024 17:47:02 +0000 (17:47 +0000)]
Handle `Vec`s resolved as `alloc::vec::Vec`
Up until now we'd always relied on `Vec`s being imported through a
prelude, but LDK sometimes forgets to keep doing that. Thus, here
we move to also accepting `alloc::vec::Vec` by mapping it to `Vec`
during name resolution.
Matt Corallo [Tue, 23 Jan 2024 22:31:55 +0000 (22:31 +0000)]
Expose accessors for `TxIn` and `TxOut`
The fields themselves are already public, so there's not a lot of
value for C users for these, but it avoids having to have this
logic written out by hand in the Java bindings, which is nice.
Matt Corallo [Fri, 29 Dec 2023 20:50:22 +0000 (20:50 +0000)]
Support passing lifetime'd enums to C
While this is generally unsafe, we have to do something for
`CandidateRouteHop`, which is passed to the scorer. Because its
incredibly performance-sensitive, forcing the bindings users to
take a performance hit just to make the scoring interface marginally
safer seems like a bad trade-off.
Matt Corallo [Sun, 29 Oct 2023 18:40:47 +0000 (18:40 +0000)]
Fix race in peer connection in C++ demo app
When we disconnect then immediately reconnect from one peer we may
still get the second connection through before the disconnection is
handled on the other end, causing connection failures. We fix this
here by disconnecting on both ends before reconnecting.
Matt Corallo [Mon, 16 Oct 2023 01:35:28 +0000 (01:35 +0000)]
Drop `#[no_mangle]` from `*_write_void` to make cbindgen not export
cbindgen recently switched to exporting all `#[no_mangle]` and
`extern "C"` functions. Our `*_write_void` methods are
internal-only but we'd marked them `#[no_mangle]`, which resulted
in them spuriously appearing in `lightning.h`.
Matt Corallo [Sun, 8 Oct 2023 05:53:25 +0000 (05:53 +0000)]
Update args on supertraits of supertraits when cloning trait impls
When cloning implementations of traits from in-crate structs, we
forgot to update the arguments for supertraits of supertraits,
causing methods on that trait to be called against the previous
struct, not the cloned one.
This was ultimately identified downstream in the Java bindings,
fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/138
Matt Corallo [Thu, 28 Sep 2023 01:14:41 +0000 (01:14 +0000)]
Use the resolved type name in generic strings, not the original
This makes some generics less readable, but some more, and reduces
generic type pollution. Some cases are a loss, eg
`Option_PaymentHashZ` gets converted to `Option_ThirtyTwoBytesZ`
(which less less readable but fewer total types as a result), but
we ultimately need this because we now have `schnorr::Signature`
and `ecdsa::Signature` so we can't rely on just using `Signature`
and having it be unique :(.
Matt Corallo [Sun, 30 Jul 2023 03:36:56 +0000 (03:36 +0000)]
Include a `struct` before trait return fields
EIther `struct Type` or `Type` work fine because of our type
declarations, but cbindgen uses `struct Type` everywhere so its
easiest if we match it, especially for downstream code.
Matt Corallo [Sat, 22 Jul 2023 20:03:11 +0000 (20:03 +0000)]
Allow generation of manual types in reference options
The limiting of supported types in `write_template_generics` isn't
super useful as its only called once per type - later uses of the
same type with the reference flag set or wiped doesn't change
anything. Still, it is relied on somewhat, so we can't drop it
entirely.
Now that we've moved more of the `[u8; 32]` newtypes to option
wrappers, failing for non-primitive references spuriously breaks.
Instead, we just allow it for manually-mapped types and let the
compiler complain if we do something invalid.
Matt Corallo [Thu, 20 Jul 2023 22:51:01 +0000 (22:51 +0000)]
Handle all traits in type resolution, including no-export ones
In the previous commit, we set up handling of no-export traits with
only a single implementor. In order to utilize that, we need such
traits to participate in type resolution, which we add support for
here.
Matt Corallo [Mon, 17 Jul 2023 02:16:01 +0000 (02:16 +0000)]
Handle no-export traits which are only implemented once as the implementor
If we have a trait marked no-export, and there's a single
implementor, we can just pretend its always the implementor. This
makes sense in LDK, for example, for the `APeerManager` trait,
which is implemented for all `PeerManager`s, but doesn't make sense
in bindings.
Matt Corallo [Thu, 27 Jul 2023 20:00:25 +0000 (20:00 +0000)]
Fix strict-aliasing violation on traits holding inner fields
When we map a trait method which returns a reference to a struct,
we map it by storing said struct in the trait implementation
struct. Then, we create a setter method which ensures the new field
is set. Sadly, because the original Rust trait method may take a
non-mutable reference to self, we have to update the field without
a mutable reference to the trait implementation struct.
Previously we did this by simply unsafe-casting a pointer to
mutable, which violates the aliasing rules in Rust. In a recent
rustc (at least on macOS), this broke.
Here, we convert the stored struct to wrap it in an `UnsafeCell`,
which fixes the issue.