-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix optional blockNumber property in eth_getTransactionCount * stash * Tron getBalance implemented * some code style fixes * removed TronWeb from dependencies reworked processTRC20TokenBalanceDetails added decodeUInt256 method * some code style fixes * rolled back yarn.lock * fixed issue with empty trc20 token balance and with multiply trc20 tokens * fixed issue with empty trc20 token balance and with multiply trc20 tokens * fixed code style * added getTokenSymbol in eth rpc node helpers fixed decodeUInt256 added decodeHexString * fix code style
- Loading branch information
1 parent
dd5d8cb
commit 0da427f
Showing
4 changed files
with
37 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
export async function decodeUInt256(uint256Hex: string): Promise<string | number> { | ||
const hexString = uint256Hex.replace(/^0+/, '') // Remove leading zeros | ||
const byteLength = hexString.length / 2 | ||
export function decodeUInt256(hex: string): number { | ||
const formattedHex = hex.replace(/^0x/, '') // Remove 0x | ||
return Number('0x' + formattedHex) | ||
} | ||
|
||
export function decodeHexString(hex: string): string { | ||
const formattedHex = hex.replace(/^(0x)?0+/, '') // Remove 0x and leading zeros | ||
const byteLength = formattedHex.length / 2 | ||
const bytes = [] | ||
|
||
for (let i = 0; i < byteLength; i++) { | ||
const byte = parseInt(hexString.substr(i * 2, 2), 16) // Get the current byte | ||
const byte = parseInt(formattedHex.substr(i * 2, 2), 16) // Get the current byte | ||
bytes.push(byte) | ||
} | ||
|
||
const firstByte = BigInt(bytes[0]) // Convert the first byte to a BigInt | ||
let decodedData | ||
|
||
if (firstByte < BigInt(10)) { | ||
// If the first byte is in the range of ASCII digits (0-9), decode as number | ||
decodedData = Number('0x' + uint256Hex) | ||
} else { | ||
decodedData = bytes | ||
.map(byte => String.fromCharCode(byte)) | ||
.filter(char => /[a-zA-Z0-9]/.test(char)) | ||
.join('') | ||
} | ||
|
||
return decodedData | ||
return bytes | ||
.map(byte => String.fromCharCode(byte)) | ||
.filter(char => /[a-zA-Z0-9]/.test(char)) | ||
.join('') | ||
} | ||
|