Skip to content

Commit

Permalink
num total signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Jul 22, 2024
1 parent 5f7ec9c commit 11e8420
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/transaction_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pub unsafe fn create_transaction_interface<Tx: SVMTransaction>(
transaction.signatures().as_ptr() as *const u8
}

extern "C" fn num_total_signatures<Tx: SVMTransaction>(transaction_ptr: TransactionPtr) -> u64 {
let transaction = unsafe { &*(transaction_ptr as *const Tx) };
transaction.num_total_signatures()
}

extern "C" fn num_write_locks<Tx: SVMTransaction>(transaction_ptr: TransactionPtr) -> u64 {
let transaction = unsafe { &*(transaction_ptr as *const Tx) };
transaction.num_write_locks()
Expand Down Expand Up @@ -121,6 +126,7 @@ pub unsafe fn create_transaction_interface<Tx: SVMTransaction>(
transaction_ptr: transaction as *const Tx as *const core::ffi::c_void,
num_signatures_fn: num_signatures::<Tx>,
signatures_fn: signatures::<Tx>,
num_total_signatures_fn: num_total_signatures::<Tx>,
num_write_locks_fn: num_write_locks::<Tx>,
recent_blockhash_fn: recent_blockhash::<Tx>,
num_instructions_fn: num_instructions::<Tx>,
Expand Down
14 changes: 14 additions & 0 deletions transaction-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ pub type TransactionNumSignaturesFn =
pub type TransactionSignaturesFn =
unsafe extern "C" fn(transaction_ptr: TransactionPtr) -> *const u8;

/// Returns the total number of signatures in the transaction, including any
/// pre-compile signatures.
/// WARNING: This function should not be used to determine the number of
/// signatures returned by `TransactionSignaturesFn`. Instead, use
/// `TransactionNumSignaturesFn`.
/// # Safety
/// - The transaction pointer must be valid.
pub type TransactionNumTotalSignatures =
unsafe extern "C" fn(transaction_ptr: TransactionPtr) -> u64;

/// Returns the number of requested write-locks in this transaction.
/// This does not consider if write-locks are demoted.
/// # Safety
Expand Down Expand Up @@ -159,6 +169,10 @@ pub struct TransactionInterface {
/// Returns pointer to the first signature in the transaction.
/// See [`TransactionSignaturesFn`].
pub signatures_fn: TransactionSignaturesFn,
/// Returns the total number of signatures in the transaction, including
/// any pre-compile signatures.
/// See [`TransactionNumTotalSignatures`].
pub num_total_signatures_fn: TransactionNumTotalSignatures,
/// Returns the number of requested write-locks in this transaction.
/// See [`TransactionNumWriteLocksFn`].
pub num_write_locks_fn: TransactionNumWriteLocksFn,
Expand Down

0 comments on commit 11e8420

Please sign in to comment.