@@ -1770,3 +1770,104 @@ pub unsafe extern "C" fn dash_spv_ffi_client_get_filter_matched_heights(
17701770
17711771 result. unwrap_or ( std:: ptr:: null_mut ( ) )
17721772}
1773+
1774+ /// Get the total count of transactions across all wallets.
1775+ ///
1776+ /// This returns the persisted transaction count from the wallet,
1777+ /// not the ephemeral sync statistics. Use this to show how many
1778+ /// blocks contained relevant transactions for the user's wallets.
1779+ ///
1780+ /// # Parameters
1781+ /// - `client`: Valid pointer to an FFIDashSpvClient
1782+ ///
1783+ /// # Returns
1784+ /// - Transaction count (0 or higher)
1785+ /// - Returns 0 if client not initialized or wallet not available
1786+ ///
1787+ /// # Safety
1788+ /// - `client` must be a valid, non-null pointer
1789+ #[ no_mangle]
1790+ pub unsafe extern "C" fn dash_spv_ffi_client_get_transaction_count (
1791+ client : * mut FFIDashSpvClient ,
1792+ ) -> usize {
1793+ null_check ! ( client, 0 ) ;
1794+
1795+ let client = & ( * client) ;
1796+ let inner = client. inner . clone ( ) ;
1797+
1798+ let result = client. runtime . block_on ( async {
1799+ // Get wallet without taking the client
1800+ let guard = inner. lock ( ) . unwrap ( ) ;
1801+ match guard. as_ref ( ) {
1802+ Some ( spv_client) => {
1803+ // Access wallet and get transaction count
1804+ let wallet = spv_client. wallet ( ) ;
1805+ let wallet_guard = wallet. read ( ) . await ;
1806+ let tx_history = wallet_guard. transaction_history ( ) ;
1807+ tx_history. len ( )
1808+ }
1809+ None => {
1810+ tracing:: warn!( "Client not initialized when querying transaction count" ) ;
1811+ 0
1812+ }
1813+ }
1814+ } ) ;
1815+
1816+ result
1817+ }
1818+
1819+ /// Get the count of blocks that contained relevant transactions.
1820+ ///
1821+ /// This counts unique block heights from the wallet's transaction history,
1822+ /// representing how many blocks actually had transactions for the user's wallets.
1823+ /// This is a persistent metric that survives app restarts.
1824+ ///
1825+ /// # Parameters
1826+ /// - `client`: Valid pointer to an FFIDashSpvClient
1827+ ///
1828+ /// # Returns
1829+ /// - Count of blocks with transactions (0 or higher)
1830+ /// - Returns 0 if client not initialized or wallet not available
1831+ ///
1832+ /// # Safety
1833+ /// - `client` must be a valid, non-null pointer
1834+ #[ no_mangle]
1835+ pub unsafe extern "C" fn dash_spv_ffi_client_get_blocks_with_transactions_count (
1836+ client : * mut FFIDashSpvClient ,
1837+ ) -> usize {
1838+ null_check ! ( client, 0 ) ;
1839+
1840+ let client = & ( * client) ;
1841+ let inner = client. inner . clone ( ) ;
1842+
1843+ let result = client. runtime . block_on ( async {
1844+ // Get wallet without taking the client
1845+ let guard = inner. lock ( ) . unwrap ( ) ;
1846+ match guard. as_ref ( ) {
1847+ Some ( spv_client) => {
1848+ // Access wallet and get unique block heights
1849+ let wallet = spv_client. wallet ( ) ;
1850+ let wallet_guard = wallet. read ( ) . await ;
1851+ let tx_history = wallet_guard. transaction_history ( ) ;
1852+
1853+ // Count unique block heights (confirmed transactions only)
1854+ let mut unique_heights = std:: collections:: HashSet :: new ( ) ;
1855+ for tx in tx_history {
1856+ if let Some ( height) = tx. height {
1857+ unique_heights. insert ( height) ;
1858+ }
1859+ }
1860+
1861+ unique_heights. len ( )
1862+ }
1863+ None => {
1864+ tracing:: warn!(
1865+ "Client not initialized when querying blocks with transactions count"
1866+ ) ;
1867+ 0
1868+ }
1869+ }
1870+ } ) ;
1871+
1872+ result
1873+ }
0 commit comments