polish some symbol exceptions
This commit is contained in:
parent
d9ecca2a4e
commit
527229272b
@ -316,8 +316,10 @@ from borsh_construct import String, CStruct
|
||||
|
||||
async def get_token_metadata_symbol(mint_address):
|
||||
global TOKENS_INFO
|
||||
|
||||
if mint_address in TOKENS_INFO and 'symbol' in TOKENS_INFO[mint_address]:
|
||||
return TOKENS_INFO[mint_address].get('symbol')
|
||||
|
||||
try:
|
||||
account_data_result = await solana_jsonrpc("getAccountInfo", mint_address)
|
||||
if 'value' in account_data_result and 'data' in account_data_result['value']:
|
||||
@ -334,20 +336,14 @@ async def get_token_metadata_symbol(mint_address):
|
||||
TOKENS_INFO[mint_address]['name'] = account_data_info['tokenName']
|
||||
else:
|
||||
TOKENS_INFO[mint_address] = {'name': account_data_info['tokenName']}
|
||||
# token_address = Pubkey.from_string(mint_address)
|
||||
# # token = Token(solana_client, token_address, TOKEN_PROGRAM_ID, Keypair())
|
||||
# token = AsyncToken(solana_client, token_address, TOKEN_PROGRAM_ID, Keypair())
|
||||
# tokenInfo = await token.get_mint_info()
|
||||
# token_info = await solana_client.get_account_info_json_parsed(Pubkey.from_string(mint_address))
|
||||
# if token_info.value and 'symbol' in token_info.value:
|
||||
# return token_info.value['symbol']
|
||||
|
||||
metadata = await get_token_metadata(mint_address)
|
||||
if metadata:
|
||||
if mint_address in TOKENS_INFO:
|
||||
TOKENS_INFO[mint_address].update(metadata)
|
||||
else:
|
||||
TOKENS_INFO[mint_address] = metadata
|
||||
|
||||
save_token_info()
|
||||
# TOKENS_INFO[mint_address] = metadata
|
||||
# return metadata.get('symbol') or metadata.get('name')
|
||||
return TOKENS_INFO[mint_address].get('symbol')
|
||||
@ -409,13 +405,17 @@ async def get_token_metadata(mint_address):
|
||||
name_length = struct.unpack("<I", data[offset:offset+4])[0]
|
||||
offset += 4
|
||||
# Read the name
|
||||
name = data[offset:offset+name_length].decode('utf-8').rstrip("\x00")
|
||||
try:
|
||||
name = data[offset:offset+name_length].decode('utf-8').rstrip("\x00")
|
||||
except Exception as e: name = None
|
||||
offset += name_length
|
||||
# Read the symbol length (u32)
|
||||
symbol_length = struct.unpack("<I", data[offset:offset+4])[0]
|
||||
offset += 4
|
||||
# Read the symbol
|
||||
symbol = data[offset:offset+symbol_length].decode('utf-8').rstrip("\x00")
|
||||
try:
|
||||
symbol = data[offset:offset+symbol_length].decode('utf-8').rstrip("\x00")
|
||||
except Exception as e: symbol = None
|
||||
|
||||
# metadata = METADATA_STRUCT.parse(data)
|
||||
# ERROR:root:Error fetching token metadata for 3psH1Mj1f7yUfaD5gh6Zj7epE8hhrMkMETgv5TshQA4o: Error in path (parsing) -> update_authority
|
||||
|
Loading…
x
Reference in New Issue
Block a user