Skip to content

Commit d4f7ca4

Browse files
authored
Merge pull request #70 from TheBlueMatt/main
Expose consistent free+clone methods for `Bech32Error`
2 parents da34358 + 9b2593e commit d4f7ca4

File tree

2 files changed

+66
-50
lines changed

2 files changed

+66
-50
lines changed

lightning-c-bindings/include/lightning.h

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,56 @@ typedef struct LDKStr {
459459
bool chars_is_owned;
460460
} LDKStr;
461461

462+
/**
463+
* Represents an error returned from the bech32 library during validation of some bech32 data
464+
*/
465+
typedef enum LDKBech32Error_Tag {
466+
/**
467+
* String does not contain the separator character
468+
*/
469+
LDKBech32Error_MissingSeparator,
470+
/**
471+
* The checksum does not match the rest of the data
472+
*/
473+
LDKBech32Error_InvalidChecksum,
474+
/**
475+
* The data or human-readable part is too long or too short
476+
*/
477+
LDKBech32Error_InvalidLength,
478+
/**
479+
* Some part of the string contains an invalid character
480+
*/
481+
LDKBech32Error_InvalidChar,
482+
/**
483+
* Some part of the data has an invalid value
484+
*/
485+
LDKBech32Error_InvalidData,
486+
/**
487+
* The bit conversion failed due to a padding issue
488+
*/
489+
LDKBech32Error_InvalidPadding,
490+
/**
491+
* The whole string must be of one case
492+
*/
493+
LDKBech32Error_MixedCase,
494+
/**
495+
* Must be last for serialization purposes
496+
*/
497+
LDKBech32Error_Sentinel,
498+
} LDKBech32Error_Tag;
499+
500+
typedef struct LDKBech32Error {
501+
LDKBech32Error_Tag tag;
502+
union {
503+
struct {
504+
uint32_t invalid_char;
505+
};
506+
struct {
507+
uint8_t invalid_data;
508+
};
509+
};
510+
} LDKBech32Error;
511+
462512
/**
463513
* A serialized transaction, in (pointer, length) form.
464514
*
@@ -7131,56 +7181,6 @@ typedef struct LDKCResult_PaymentIdPaymentErrorZ {
71317181
bool result_ok;
71327182
} LDKCResult_PaymentIdPaymentErrorZ;
71337183

7134-
/**
7135-
* Represents an error returned from the bech32 library during validation of some bech32 data
7136-
*/
7137-
typedef enum LDKBech32Error_Tag {
7138-
/**
7139-
* String does not contain the separator character
7140-
*/
7141-
LDKBech32Error_MissingSeparator,
7142-
/**
7143-
* The checksum does not match the rest of the data
7144-
*/
7145-
LDKBech32Error_InvalidChecksum,
7146-
/**
7147-
* The data or human-readable part is too long or too short
7148-
*/
7149-
LDKBech32Error_InvalidLength,
7150-
/**
7151-
* Some part of the string contains an invalid character
7152-
*/
7153-
LDKBech32Error_InvalidChar,
7154-
/**
7155-
* Some part of the data has an invalid value
7156-
*/
7157-
LDKBech32Error_InvalidData,
7158-
/**
7159-
* The bit conversion failed due to a padding issue
7160-
*/
7161-
LDKBech32Error_InvalidPadding,
7162-
/**
7163-
* The whole string must be of one case
7164-
*/
7165-
LDKBech32Error_MixedCase,
7166-
/**
7167-
* Must be last for serialization purposes
7168-
*/
7169-
LDKBech32Error_Sentinel,
7170-
} LDKBech32Error_Tag;
7171-
7172-
typedef struct LDKBech32Error {
7173-
LDKBech32Error_Tag tag;
7174-
union {
7175-
struct {
7176-
uint32_t invalid_char;
7177-
};
7178-
struct {
7179-
uint8_t invalid_data;
7180-
};
7181-
};
7182-
} LDKBech32Error;
7183-
71847184
/**
71857185
* Sub-errors which don't have specific information in them use this type.
71867186
*/
@@ -12473,6 +12473,16 @@ struct LDKStr _ldk_get_compiled_version(void);
1247312473

1247412474
struct LDKStr _ldk_c_bindings_get_compiled_version(void);
1247512475

12476+
/**
12477+
* Creates a new Bech32Error which has the same data as `orig`
12478+
*/
12479+
struct LDKBech32Error Bech32Error_clone(const struct LDKBech32Error *NONNULL_PTR orig);
12480+
12481+
/**
12482+
* Releases any memory held by the given `Bech32Error` (which is currently none)
12483+
*/
12484+
void Bech32Error_free(struct LDKBech32Error o);
12485+
1247612486
/**
1247712487
* Frees the data buffer, if data_is_owned is set and datalen > 0.
1247812488
*/

lightning-c-bindings/src/c_types/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ impl Bech32Error {
227227
}
228228
}
229229
}
230+
#[no_mangle]
231+
/// Creates a new Bech32Error which has the same data as `orig`
232+
pub extern "C" fn Bech32Error_clone(orig: &Bech32Error) -> Bech32Error { orig.clone() }
233+
#[no_mangle]
234+
/// Releases any memory held by the given `Bech32Error` (which is currently none)
235+
pub extern "C" fn Bech32Error_free(o: Bech32Error) { }
230236

231237
#[repr(C)]
232238
#[derive(Clone, Copy, PartialEq)]

0 commit comments

Comments
 (0)