@@ -688,7 +688,7 @@ const refreshSolanaBalances = async (
688688 if ( ! node ) {
689689 return ;
690690 }
691- const solanaRPC_url = `https://${ node . domain } /solana-rpc ` ;
691+ const solanaRPC_url = `https://${ node . domain } ` ;
692692 try {
693693 const [ sol , sp ] = await Promise . all ( [
694694 scanSolanaSol ( solanaProfile . keyID , solanaRPC_url ) ,
@@ -946,13 +946,16 @@ const getSpClubMemberId = async (profile: profile) => {
946946 return profile . spClub . memberId ;
947947} ;
948948
949- async function getReceivedAmounts ( walletAddress : string ) {
950- const connection = new Connection ( solanaRpc , "confirmed" ) ;
951-
949+ async function getReceivedAmounts (
950+ walletAddress : string ,
951+ allNodes : nodes_info [ ]
952+ ) {
952953 try {
953954 const walletPubKey = new PublicKey ( walletAddress ) ;
954955 const senderPubKey = new PublicKey ( rewardWalletAddress ) ;
955956
957+ const connection = new Connection ( solanaRpc , "confirmed" ) ;
958+
956959 // Step 1: Get transaction signatures
957960 const signatures = await connection . getSignaturesForAddress ( walletPubKey , {
958961 limit : 20 ,
@@ -965,74 +968,91 @@ async function getReceivedAmounts(walletAddress: string) {
965968
966969 // For only one transaction it works. Here's an example.
967970 // For multiple transactions it fails because the server doesn't support it.
968- // const transaction = await connection.getTransaction(
969- // signatures[0].signature,
970- // {
971- // commitment: "confirmed",
972- // maxSupportedTransactionVersion: 0, // Ensures we handle versioned transactions
973- // }
974- // );
975- // console.log(transaction);
976-
977- // Step 2: Fetch all transactions in **one batch request**
978- const transactions = await connection . getTransactions (
979- signatures . map ( ( sig ) => sig . signature ) ,
980- { commitment : "confirmed" }
971+ const _node1 = allNodes [ Math . floor ( Math . random ( ) * ( allNodes . length - 1 ) ) ] ;
972+ const _connection1 = new Connection (
973+ `https://${ _node1 . domain } ` ,
974+ "confirmed"
981975 ) ;
982- // Step 3: Filter transactions where sender matches
983- const receivedTransactions = transactions
984- . filter ( ( tx : any ) => tx && tx . meta )
985- . map ( ( tx ) => {
986- if ( ! tx || ! tx . meta ) return null ;
987-
988- // Get account balances before and after the transaction
989- const preBalances = tx . meta . preBalances ;
990- const postBalances = tx . meta . postBalances ;
991-
992- // Get account keys (supports both legacy & versioned transactions)
993- const accountKeys =
994- tx . transaction . message . getAccountKeys ( ) . staticAccountKeys ;
995-
996- // Find the index of the recipient (walletAddress) in the account keys
997- const recipientIndex = accountKeys . findIndex (
998- ( key : any ) => key . toBase58 ( ) === walletPubKey . toBase58 ( )
999- ) ;
1000-
1001- if ( recipientIndex === - 1 ) return null ; // Wallet not found in the transaction
1002-
1003- // Calculate SOL received (in lamports, convert to SOL)
1004- const solReceived =
1005- ( postBalances [ recipientIndex ] - preBalances [ recipientIndex ] ) / 1e9 ;
1006-
1007- // Extract token transfers (SPL tokens)
1008- const tokenTransfers = tx . meta . postTokenBalances ?. map (
1009- ( tokenBalance : any ) => {
1010- const preToken = tx ?. meta ?. preTokenBalances ?. find (
1011- ( pre ) =>
1012- pre . mint === tokenBalance . mint && pre . owner === walletAddress
1013- ) ;
1014-
1015- const receivedAmount =
1016- ( tokenBalance . uiTokenAmount . uiAmount || 0 ) -
1017- ( preToken ?. uiTokenAmount . uiAmount || 0 ) ;
1018-
1019- return {
1020- mint : tokenBalance . mint ,
1021- receivedAmount,
1022- } ;
1023- }
1024- ) ;
976+ const transaction = await _connection1 . getTransaction (
977+ signatures [ 0 ] . signature ,
978+ {
979+ commitment : "confirmed" ,
980+ maxSupportedTransactionVersion : 0 , // Ensures we handle versioned transactions
981+ }
982+ ) ;
983+ console . log ( transaction ) ;
1025984
1026- return {
1027- signature : tx . transaction . signatures [ 0 ] ,
1028- solReceived,
1029- tokenTransfers,
1030- } ;
1031- } ) ;
985+ // Step 2: Fetch transactions with a delay to avoid rate limits
986+ // const transactions = [];
987+ // for (const sig of signatures) {
988+ // const _node = allNodes[Math.floor(Math.random() * (allNodes.length - 1))];
1032989
1033- console . log ( receivedTransactions . filter ( ( tx : any ) => tx !== null ) ) ;
990+ // const _connection = new Connection(
991+ // `https://${_node.domain}/solana-rpc`,
992+ // "confirmed"
993+ // );
1034994
1035- return receivedTransactions . filter ( ( tx : any ) => tx !== null ) ;
995+ // const tx = await _connection.getTransaction(sig.signature, {
996+ // commitment: "confirmed",
997+ // maxSupportedTransactionVersion: 0,
998+ // });
999+ // if (tx) transactions.push(tx);
1000+ // }
1001+
1002+ // Step 3: Filter transactions where sender matches
1003+ // const receivedTransactions = transactions
1004+ // .filter((tx: any) => tx && tx.meta)
1005+ // .map((tx) => {
1006+ // if (!tx || !tx.meta) return null;
1007+
1008+ // // Get account balances before and after the transaction
1009+ // const preBalances = tx.meta.preBalances;
1010+ // const postBalances = tx.meta.postBalances;
1011+
1012+ // // Get account keys (supports both legacy & versioned transactions)
1013+ // const accountKeys =
1014+ // tx.transaction.message.getAccountKeys().staticAccountKeys;
1015+
1016+ // // Find the index of the recipient (walletAddress) in the account keys
1017+ // const recipientIndex = accountKeys.findIndex(
1018+ // (key: any) => key.toBase58() === walletPubKey.toBase58()
1019+ // );
1020+
1021+ // if (recipientIndex === -1) return null; // Wallet not found in the transaction
1022+
1023+ // // Calculate SOL received (in lamports, convert to SOL)
1024+ // const solReceived =
1025+ // (postBalances[recipientIndex] - preBalances[recipientIndex]) / 1e9;
1026+
1027+ // // Extract token transfers (SPL tokens)
1028+ // const tokenTransfers = tx.meta.postTokenBalances?.map(
1029+ // (tokenBalance: any) => {
1030+ // const preToken = tx?.meta?.preTokenBalances?.find(
1031+ // (pre) =>
1032+ // pre.mint === tokenBalance.mint && pre.owner === walletAddress
1033+ // );
1034+
1035+ // const receivedAmount =
1036+ // (tokenBalance.uiTokenAmount.uiAmount || 0) -
1037+ // (preToken?.uiTokenAmount.uiAmount || 0);
1038+
1039+ // return {
1040+ // mint: tokenBalance.mint,
1041+ // receivedAmount,
1042+ // };
1043+ // }
1044+ // );
1045+
1046+ // return {
1047+ // signature: tx.transaction.signatures[0],
1048+ // solReceived,
1049+ // tokenTransfers,
1050+ // };
1051+ // });
1052+
1053+ // console.log(receivedTransactions.filter((tx: any) => tx !== null));
1054+
1055+ // return receivedTransactions.filter((tx: any) => tx !== null);
10361056 } catch ( error ) {
10371057 console . error ( "Error fetching transaction history:" , error ) ;
10381058 return [ ] ;
0 commit comments