From f8cd666a31bd47181fcdadf1e1dd75382c6c9076 Mon Sep 17 00:00:00 2001 From: jackkru69 Date: Mon, 22 Jan 2024 18:06:56 +0300 Subject: [PATCH] fixed EvmCore.build, Evm20Contract.getDecimals --- packages/tssdk/src/contracts/evm20Contract.ts | 2 +- packages/tssdk/src/helpers/bnHex.helper.ts | 6 ++++++ packages/tssdk/src/libs/evm-api/evmCore.ts | 7 +++++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 packages/tssdk/src/helpers/bnHex.helper.ts diff --git a/packages/tssdk/src/contracts/evm20Contract.ts b/packages/tssdk/src/contracts/evm20Contract.ts index 1906bb3b..fbe43d13 100644 --- a/packages/tssdk/src/contracts/evm20Contract.ts +++ b/packages/tssdk/src/contracts/evm20Contract.ts @@ -34,7 +34,7 @@ export class Evm20Contract { return symbol; } - public async getDecimals(): Promise { + public async getDecimals(): Promise { const decimals = await this.evmContract.scGet('decimals', []); return decimals; } diff --git a/packages/tssdk/src/helpers/bnHex.helper.ts b/packages/tssdk/src/helpers/bnHex.helper.ts new file mode 100644 index 00000000..cde30f38 --- /dev/null +++ b/packages/tssdk/src/helpers/bnHex.helper.ts @@ -0,0 +1,6 @@ +export function bnToHex(bnParam: any) { + const bn = BigInt(bnParam); + let hex = bn.toString(16); + if (hex.length % 2) { hex = `0${hex}`; } + return hex; +} diff --git a/packages/tssdk/src/libs/evm-api/evmCore.ts b/packages/tssdk/src/libs/evm-api/evmCore.ts index 4d76b2c0..bbe4879e 100755 --- a/packages/tssdk/src/libs/evm-api/evmCore.ts +++ b/packages/tssdk/src/libs/evm-api/evmCore.ts @@ -1,5 +1,8 @@ import { VM } from '@ethereumjs/vm'; -import { Address, bytesToHex, hexToBytes } from '@ethereumjs/util'; +import { + Address, bytesToHex, hexToBytes, +} from '@ethereumjs/util'; +import { bnToHex } from '../../helpers/bnHex.helper'; import { AddressApi, NetworkApi, TransactionsApi } from '../index'; import { AccountKey } from '../../typings'; @@ -106,7 +109,7 @@ export class EvmCore { const vm = await VM.create(); vm.stateManager.getContractStorage = async (address: Address, key: Uint8Array) => { - const val = bytesToHex(key); + const val = bnToHex(bytesToHex(key)); const state = await network.loadScStateByKey(AddressApi.hexToTextAddress(AddressApi.evmAddressToHexAddress(address.toString())), val); return Buffer.from(state);