Skip to content

Commit

Permalink
fixed EvmCore.build, Evm20Contract.getDecimals
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkru69 committed Jan 22, 2024
1 parent 1c110e9 commit f8cd666
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/tssdk/src/contracts/evm20Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Evm20Contract {
return symbol;
}

public async getDecimals(): Promise<number> {
public async getDecimals(): Promise<bigint> {
const decimals = await this.evmContract.scGet('decimals', []);
return decimals;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/tssdk/src/helpers/bnHex.helper.ts
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 5 additions & 2 deletions packages/tssdk/src/libs/evm-api/evmCore.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f8cd666

Please sign in to comment.