Skip to content

Commit e8ac901

Browse files
committed
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.
1 parent 2c2c974 commit e8ac901

File tree

1 file changed

+38
-6
lines changed
  • lightning-c-bindings/src/c_types

1 file changed

+38
-6
lines changed

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,39 @@ impl TxIn {
628628
}
629629
}
630630
}
631-
632-
#[no_mangle]
633-
/// Frees the witness and script_sig in a TxIn
634-
pub extern "C" fn TxIn_free(_res: TxIn) { }
635-
636631
#[no_mangle]
637632
/// Convenience function for constructing a new TxIn
638633
pub extern "C" fn TxIn_new(witness: Witness, script_sig: derived::CVec_u8Z, sequence: u32, previous_txid: ThirtyTwoBytes, previous_vout: u32) -> TxIn {
639634
TxIn { witness, script_sig, sequence, previous_txid, previous_vout }
640635
}
641-
636+
#[no_mangle]
637+
/// Gets the `witness` in the given `TxIn`.
638+
pub extern "C" fn TxIn_get_witness(txin: &TxIn) -> Witness {
639+
txin.witness.clone()
640+
}
641+
#[no_mangle]
642+
/// Gets the `script_sig` in the given `TxIn`.
643+
pub extern "C" fn TxIn_get_script_sig(txin: &TxIn) -> u8slice {
644+
u8slice::from_vec(&txin.script_sig)
645+
}
646+
#[no_mangle]
647+
/// Gets the `sequence` in the given `TxIn`.
648+
pub extern "C" fn TxIn_get_sequence(txin: &TxIn) -> u32 {
649+
txin.sequence
650+
}
651+
#[no_mangle]
652+
/// Gets the previous outpoint txid in the given `TxIn`.
653+
pub extern "C" fn TxIn_get_previous_txid(txin: &TxIn) -> ThirtyTwoBytes {
654+
txin.previous_txid
655+
}
656+
#[no_mangle]
657+
/// Gets the previout outpoint index in the given `TxIn`.
658+
pub extern "C" fn TxIn_get_previous_vout(txin: &TxIn) -> u32 {
659+
txin.previous_vout
660+
}
661+
#[no_mangle]
662+
/// Frees the witness and script_sig in a TxIn
663+
pub extern "C" fn TxIn_free(_res: TxIn) { }
642664

643665
#[repr(C)]
644666
#[derive(Clone)]
@@ -672,6 +694,16 @@ pub extern "C" fn TxOut_new(script_pubkey: derived::CVec_u8Z, value: u64) -> TxO
672694
TxOut { script_pubkey, value }
673695
}
674696
#[no_mangle]
697+
/// Gets the `script_pubkey` in the given `TxOut`.
698+
pub extern "C" fn TxOut_get_script_pubkey(txout: &TxOut) -> u8slice {
699+
u8slice::from_vec(&txout.script_pubkey)
700+
}
701+
#[no_mangle]
702+
/// Gets the value in the given `TxOut`.
703+
pub extern "C" fn TxOut_get_value(txout: &TxOut) -> u64 {
704+
txout.value
705+
}
706+
#[no_mangle]
675707
/// Frees the data pointed to by script_pubkey.
676708
pub extern "C" fn TxOut_free(_res: TxOut) { }
677709
#[no_mangle]

0 commit comments

Comments
 (0)