-
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
- Loading branch information
1 parent
af151eb
commit 41397f5
Showing
2 changed files
with
173 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export async function decodeUInt256(uint256Hex: string): Promise<string | number> { | ||
const hexString = uint256Hex.replace(/^0+/, '') // Remove leading zeros | ||
const byteLength = hexString.length / 2 | ||
const bytes = [] | ||
|
||
for (let i = 0; i < byteLength; i++) { | ||
const byte = parseInt(hexString.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 | ||
} |