From: Arik Date: Mon, 3 Oct 2022 21:22:28 +0000 (-0700) Subject: Merge pull request #92 from TheBlueMatt/main X-Git-Tag: v0.0.111.0 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c3f0595a4de3d13146f65c8b6b922191c30eaced;hp=c96981baf087d5441d079508ae71d2e046167ebf;p=ldk-c-bindings Merge pull request #92 from TheBlueMatt/main Add a convinience constructor for the new BigEndianScalar --- diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 05f07eb..c06fe65 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -467,6 +467,27 @@ typedef struct LDKStr { bool chars_is_owned; } LDKStr; +/** + * Represents a scalar value between zero and the secp256k1 curve order, in big endian. + */ +typedef struct LDKBigEndianScalar { + /** + * The bytes of the scalar value. + */ + uint8_t big_endian_bytes[32]; +} LDKBigEndianScalar; + +/** + * Arbitrary 32 bytes, which could represent one of a few different things. You probably want to + * look up the corresponding function in rust-lightning's docs. + */ +typedef struct LDKThirtyTwoBytes { + /** + * The thirty-two bytes + */ + uint8_t data[32]; +} LDKThirtyTwoBytes; + /** * Represents an error returned from the bech32 library during validation of some bech32 data */ @@ -2437,17 +2458,6 @@ typedef struct LDKCResult_RouteLightningErrorZ { bool result_ok; } LDKCResult_RouteLightningErrorZ; -/** - * Arbitrary 32 bytes, which could represent one of a few different things. You probably want to - * look up the corresponding function in rust-lightning's docs. - */ -typedef struct LDKThirtyTwoBytes { - /** - * The thirty-two bytes - */ - uint8_t data[32]; -} LDKThirtyTwoBytes; - /** * Some information provided on receipt of payment depends on whether the payment received is a * spontaneous payment or a \"conventional\" lightning payment that's paying an invoice. @@ -6407,16 +6417,6 @@ typedef struct LDKCResult_SecretKeyNoneZ { bool result_ok; } LDKCResult_SecretKeyNoneZ; -/** - * Represents a scalar value between zero and the secp256k1 curve order, in big endian. - */ -typedef struct LDKBigEndianScalar { - /** - * The bytes of the scalar value. - */ - uint8_t big_endian_bytes[32]; -} LDKBigEndianScalar; - /** * An enum which can either contain a crate::c_types::BigEndianScalar or not */ @@ -13896,6 +13896,11 @@ struct LDKStr _ldk_get_compiled_version(void); struct LDKStr _ldk_c_bindings_get_compiled_version(void); +/** + * Convenience function for constructing a new BigEndianScalar + */ +struct LDKBigEndianScalar BigEndianScalar_new(struct LDKThirtyTwoBytes big_endian_bytes); + /** * Creates a new Bech32Error which has the same data as `orig` */ diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 0c46581..3f8c900 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -166,6 +166,12 @@ impl BigEndianScalar { } } +#[no_mangle] +/// Convenience function for constructing a new BigEndianScalar +pub extern "C" fn BigEndianScalar_new(big_endian_bytes: ThirtyTwoBytes) -> BigEndianScalar { + BigEndianScalar { big_endian_bytes: big_endian_bytes.data } +} + #[repr(C)] #[derive(Copy, Clone)] /// Represents an error returned from libsecp256k1 during validation of some secp256k1 data