Skip to content

Commit d51e4b2

Browse files
committed
Merge branch 'tokenProgramData' of https://github.com/leolambo/bitcore into v11
2 parents fcef0f7 + 105c25e commit d51e4b2

File tree

1 file changed

+30
-4
lines changed
  • packages/bitcore-node/src/providers/chain-state/svm/api

1 file changed

+30
-4
lines changed

packages/bitcore-node/src/providers/chain-state/svm/api/csp.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CacheStorage } from '../../../../models/cache';
1111
import { IBlock } from '../../../../types/Block';
1212
import { CoinListingJSON } from '../../../../types/Coin';
1313
import { IChainConfig, IProvider, ISVMNetworkConfig } from '../../../../types/Config';
14-
import { BroadcastTransactionParams, GetBalanceForAddressParams, GetBlockParams, GetCoinsForTxParams, GetEstimatePriorityFeeParams, GetWalletBalanceParams, IChainStateService, StreamAddressUtxosParams, StreamBlocksParams, StreamTransactionParams, StreamTransactionsParams, StreamWalletTransactionsParams, WalletBalanceType, GetBlockBeforeTimeParams } from '../../../../types/namespaces/ChainStateProvider';
14+
import { BroadcastTransactionParams, GetBalanceForAddressParams, GetBlockBeforeTimeParams, GetBlockParams, GetCoinsForTxParams, GetEstimatePriorityFeeParams, GetWalletBalanceParams, IChainStateService, StreamAddressUtxosParams, StreamBlocksParams, StreamTransactionParams, StreamTransactionsParams, StreamWalletTransactionsParams, WalletBalanceType } from '../../../../types/namespaces/ChainStateProvider';
1515
import { range } from '../../../../utils';
1616
import { TransformWithEventPipe } from '../../../../utils/streamWithEventPipe';
1717
import {
@@ -699,11 +699,16 @@ export class BaseSVMStateProvider extends InternalStateProvider implements IChai
699699
async getSPLTokenInfo(
700700
network: string,
701701
tokenAddress: string
702-
): Promise<{ name: string; symbol: string; decimals: number }> {
703-
const { umi } = await this.getRpc(network);
702+
): Promise<{ name: string; symbol: string; decimals: number; programType: string | undefined; programAddress: string | undefined; }> {
703+
const TOKEN_PROGRAM_ADDRESS = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
704+
const TOKEN_2022_ADDR = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
705+
const { umi, connection } = await this.getRpc(network);
704706
let decimals;
707+
let programType;
708+
let programAddress;
705709
let name = '';
706710
let symbol = '';
711+
707712
try {
708713
let error;
709714
let token;
@@ -745,7 +750,28 @@ export class BaseSVMStateProvider extends InternalStateProvider implements IChai
745750
} catch (err) {
746751
logger.error('Error getting SPL token info: %o', err);
747752
}
748-
return { name, symbol, decimals };
753+
754+
try {
755+
const result = await connection.getAccountInfo(tokenAddress).send();
756+
const owner = result?.value?.owner?.toString?.();
757+
if (!owner) {
758+
throw new Error(`Mint account not found or unreadable: ${tokenAddress}`);
759+
}
760+
if (owner === TOKEN_PROGRAM_ADDRESS) {
761+
programType = 'token';
762+
programAddress = TOKEN_PROGRAM_ADDRESS;
763+
} else if (owner === TOKEN_2022_ADDR) {
764+
programType = 'token2022';
765+
programAddress = TOKEN_2022_ADDR;
766+
}
767+
if (!programAddress) {
768+
logger.warn(`Unknown token program owner for ${tokenAddress}: ${owner}`);
769+
}
770+
} catch (err) {
771+
logger.error('Error getting SPL token program info: %o', err);
772+
}
773+
774+
return { name, symbol, decimals, programType, programAddress };
749775
}
750776

751777
async getLocalTip(params: any): Promise<IBlock> {

0 commit comments

Comments
 (0)