SHARD-2738: Fix how token contract data is parsed and stored#94
SHARD-2738: Fix how token contract data is parsed and stored#94
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| if (!contractInfo) { | ||
| try { | ||
| const fetchedInfo = await getContractInfo(contractAddress) | ||
| contractInfo = fetchedInfo.contractInfo | ||
| contractType = fetchedInfo.contractType | ||
|
|
||
| // Update the account record with the newly fetched info if account exists | ||
| if (accountExist) { | ||
| accountExist.contractInfo = contractInfo | ||
| accountExist.contractType = contractType | ||
| insertAccount(accountExist) |
There was a problem hiding this comment.
Suggestion: The call to insertAccount(accountExist) should be awaited since it may be asynchronous. Not awaiting it could lead to race conditions or unhandled promise rejections. [possible issue, importance: 7]
| if (!contractInfo) { | |
| try { | |
| const fetchedInfo = await getContractInfo(contractAddress) | |
| contractInfo = fetchedInfo.contractInfo | |
| contractType = fetchedInfo.contractType | |
| // Update the account record with the newly fetched info if account exists | |
| if (accountExist) { | |
| accountExist.contractInfo = contractInfo | |
| accountExist.contractType = contractType | |
| insertAccount(accountExist) | |
| if (!contractInfo) { | |
| try { | |
| const fetchedInfo = await getContractInfo(contractAddress) | |
| contractInfo = fetchedInfo.contractInfo | |
| contractType = fetchedInfo.contractType | |
| // Update the account record with the newly fetched info if account exists | |
| if (accountExist) { | |
| accountExist.contractInfo = contractInfo | |
| accountExist.contractType = contractType | |
| await insertAccount(accountExist) | |
| } | |
| } catch (e) { | |
| if (config.verbose) console.log(`Failed to fetch contract info for ${contractAddress}:`, e) | |
| } | |
| } |
| for (const [key, value] of Object.entries(object)) { | ||
| if (typeof value === 'object' && value !== null) { | ||
| inputs.push(StringUtils.safeStringify(value)) | ||
| } else if (typeof value === 'boolean') { | ||
| inputs.push(value ? 1 : 0) | ||
| } else { | ||
| inputs.push(value) | ||
| } | ||
| } |
There was a problem hiding this comment.
Suggestion: Serializing all objects, including arrays, may cause issues if arrays are expected to be stored as-is or handled differently. Consider checking for arrays separately and handling them appropriately to avoid data corruption. [general, importance: 6]
| for (const [key, value] of Object.entries(object)) { | |
| if (typeof value === 'object' && value !== null) { | |
| inputs.push(StringUtils.safeStringify(value)) | |
| } else if (typeof value === 'boolean') { | |
| inputs.push(value ? 1 : 0) | |
| } else { | |
| inputs.push(value) | |
| } | |
| } | |
| for (const [key, value] of Object.entries(object)) { | |
| if (Array.isArray(value)) { | |
| inputs.push(JSON.stringify(value)) | |
| } else if (typeof value === 'object' && value !== null) { | |
| inputs.push(StringUtils.safeStringify(value)) | |
| } else if (typeof value === 'boolean') { | |
| inputs.push(value ? 1 : 0) | |
| } else { | |
| inputs.push(value) | |
| } | |
| } |
PR Type
Bug fix, Enhancement
Description
Fix token contract info parsing and storage logic
Ensure correct types for decimals and totalSupply fields
Fetch and update missing contract info dynamically
Improve value extraction for database storage, including booleans
Changes walkthrough 📝
TxDecoder.ts
Correct token contract info type handling in decodersrc/class/TxDecoder.ts
account.ts
Dynamic fetching and updating of token contract infosrc/storage/account.ts
sqlite3storage.ts
Improve value extraction for database storagesrc/storage/sqlite3storage.ts
1/0