From e8ac9011500460f5d13174c6bad634aa69de154e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 23 Jan 2024 22:31:55 +0000 Subject: [PATCH] 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. --- lightning-c-bindings/src/c_types/mod.rs | 44 +++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 19e5672..3fe5eb6 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -628,17 +628,39 @@ impl TxIn { } } } - -#[no_mangle] -/// Frees the witness and script_sig in a TxIn -pub extern "C" fn TxIn_free(_res: TxIn) { } - #[no_mangle] /// Convenience function for constructing a new TxIn pub extern "C" fn TxIn_new(witness: Witness, script_sig: derived::CVec_u8Z, sequence: u32, previous_txid: ThirtyTwoBytes, previous_vout: u32) -> TxIn { TxIn { witness, script_sig, sequence, previous_txid, previous_vout } } - +#[no_mangle] +/// Gets the `witness` in the given `TxIn`. +pub extern "C" fn TxIn_get_witness(txin: &TxIn) -> Witness { + txin.witness.clone() +} +#[no_mangle] +/// Gets the `script_sig` in the given `TxIn`. +pub extern "C" fn TxIn_get_script_sig(txin: &TxIn) -> u8slice { + u8slice::from_vec(&txin.script_sig) +} +#[no_mangle] +/// Gets the `sequence` in the given `TxIn`. +pub extern "C" fn TxIn_get_sequence(txin: &TxIn) -> u32 { + txin.sequence +} +#[no_mangle] +/// Gets the previous outpoint txid in the given `TxIn`. +pub extern "C" fn TxIn_get_previous_txid(txin: &TxIn) -> ThirtyTwoBytes { + txin.previous_txid +} +#[no_mangle] +/// Gets the previout outpoint index in the given `TxIn`. +pub extern "C" fn TxIn_get_previous_vout(txin: &TxIn) -> u32 { + txin.previous_vout +} +#[no_mangle] +/// Frees the witness and script_sig in a TxIn +pub extern "C" fn TxIn_free(_res: TxIn) { } #[repr(C)] #[derive(Clone)] @@ -672,6 +694,16 @@ pub extern "C" fn TxOut_new(script_pubkey: derived::CVec_u8Z, value: u64) -> TxO TxOut { script_pubkey, value } } #[no_mangle] +/// Gets the `script_pubkey` in the given `TxOut`. +pub extern "C" fn TxOut_get_script_pubkey(txout: &TxOut) -> u8slice { + u8slice::from_vec(&txout.script_pubkey) +} +#[no_mangle] +/// Gets the value in the given `TxOut`. +pub extern "C" fn TxOut_get_value(txout: &TxOut) -> u64 { + txout.value +} +#[no_mangle] /// Frees the data pointed to by script_pubkey. pub extern "C" fn TxOut_free(_res: TxOut) { } #[no_mangle] -- 2.30.2