From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Wed, 13 Apr 2022 20:51:24 +0000 (+0000) Subject: Merge pull request #70 from TheBlueMatt/main X-Git-Tag: v0.0.106.1^0 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=commitdiff_plain;h=d4f7ca4bd4e16b9311b4d6bcd518e6bac2778fe4;hp=da34358617f52371cbafa7ebe429ce8c8b1b32c4 Merge pull request #70 from TheBlueMatt/main Expose consistent free+clone methods for `Bech32Error` --- diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index ee15c0f..cb929f6 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -459,6 +459,56 @@ typedef struct LDKStr { bool chars_is_owned; } LDKStr; +/** + * Represents an error returned from the bech32 library during validation of some bech32 data + */ +typedef enum LDKBech32Error_Tag { + /** + * String does not contain the separator character + */ + LDKBech32Error_MissingSeparator, + /** + * The checksum does not match the rest of the data + */ + LDKBech32Error_InvalidChecksum, + /** + * The data or human-readable part is too long or too short + */ + LDKBech32Error_InvalidLength, + /** + * Some part of the string contains an invalid character + */ + LDKBech32Error_InvalidChar, + /** + * Some part of the data has an invalid value + */ + LDKBech32Error_InvalidData, + /** + * The bit conversion failed due to a padding issue + */ + LDKBech32Error_InvalidPadding, + /** + * The whole string must be of one case + */ + LDKBech32Error_MixedCase, + /** + * Must be last for serialization purposes + */ + LDKBech32Error_Sentinel, +} LDKBech32Error_Tag; + +typedef struct LDKBech32Error { + LDKBech32Error_Tag tag; + union { + struct { + uint32_t invalid_char; + }; + struct { + uint8_t invalid_data; + }; + }; +} LDKBech32Error; + /** * A serialized transaction, in (pointer, length) form. * @@ -7131,56 +7181,6 @@ typedef struct LDKCResult_PaymentIdPaymentErrorZ { bool result_ok; } LDKCResult_PaymentIdPaymentErrorZ; -/** - * Represents an error returned from the bech32 library during validation of some bech32 data - */ -typedef enum LDKBech32Error_Tag { - /** - * String does not contain the separator character - */ - LDKBech32Error_MissingSeparator, - /** - * The checksum does not match the rest of the data - */ - LDKBech32Error_InvalidChecksum, - /** - * The data or human-readable part is too long or too short - */ - LDKBech32Error_InvalidLength, - /** - * Some part of the string contains an invalid character - */ - LDKBech32Error_InvalidChar, - /** - * Some part of the data has an invalid value - */ - LDKBech32Error_InvalidData, - /** - * The bit conversion failed due to a padding issue - */ - LDKBech32Error_InvalidPadding, - /** - * The whole string must be of one case - */ - LDKBech32Error_MixedCase, - /** - * Must be last for serialization purposes - */ - LDKBech32Error_Sentinel, -} LDKBech32Error_Tag; - -typedef struct LDKBech32Error { - LDKBech32Error_Tag tag; - union { - struct { - uint32_t invalid_char; - }; - struct { - uint8_t invalid_data; - }; - }; -} LDKBech32Error; - /** * Sub-errors which don't have specific information in them use this type. */ @@ -12473,6 +12473,16 @@ struct LDKStr _ldk_get_compiled_version(void); struct LDKStr _ldk_c_bindings_get_compiled_version(void); +/** + * Creates a new Bech32Error which has the same data as `orig` + */ +struct LDKBech32Error Bech32Error_clone(const struct LDKBech32Error *NONNULL_PTR orig); + +/** + * Releases any memory held by the given `Bech32Error` (which is currently none) + */ +void Bech32Error_free(struct LDKBech32Error o); + /** * Frees the data buffer, if data_is_owned is set and datalen > 0. */ diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 80f04c5..1e88f05 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -227,6 +227,12 @@ impl Bech32Error { } } } +#[no_mangle] +/// Creates a new Bech32Error which has the same data as `orig` +pub extern "C" fn Bech32Error_clone(orig: &Bech32Error) -> Bech32Error { orig.clone() } +#[no_mangle] +/// Releases any memory held by the given `Bech32Error` (which is currently none) +pub extern "C" fn Bech32Error_free(o: Bech32Error) { } #[repr(C)] #[derive(Clone, Copy, PartialEq)]