Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkru69 committed Jan 15, 2024
1 parent e32039e commit 487ebd1
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 658 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"concurrency": "^0.1.4"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"commitizen": "^4.2.5",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.22.0",
"eslint": "8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
Expand All @@ -44,7 +44,7 @@
"lint-staged": "^12.3.7",
"semantic-release": "^19.0.2",
"semantic-release-monorepo": "^7.0.5",
"typescript": "^4.8.4"
"typescript": "^5.3.3"
},
"config": {
"commitizen": {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"mocha": "^9",
"ts-node": "^10.2.1",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
"typescript": "^5.3.3"
},
"oclif": {
"bin": "tpe",
Expand All @@ -80,4 +80,4 @@
"/oclif.manifest.json"
],
"gitHead": "9b47ac3af1c98386acb9a3ba68301569f793bb97"
}
}
8 changes: 4 additions & 4 deletions packages/cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4136,10 +4136,10 @@ typedi@^0.10.0:
resolved "https://registry.yarnpkg.com/typedi/-/typedi-0.10.0.tgz#e8f9a5ee100b84addbdfb57fe90d8d9ed2a21dea"
integrity sha512-v3UJF8xm68BBj6AF4oQML3ikrfK2c9EmZUyLOfShpJuItAqVBHWP/KtpGinkSsIiP6EZyyb6Z3NXyW9dgS9X1w==

typescript@^4.4.3:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
typescript@^5.3.3:
version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==

unique-filename@^1.1.1:
version "1.1.1"
Expand Down
13 changes: 6 additions & 7 deletions packages/tssdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
},
"license": "MIT",
"dependencies": {
"@ethereumjs/common": "^2.6.4",
"@ethereumjs/tx": "^3.5.2",
"@ethereumjs/vm": "^5.9.2",
"@ethereumjs/common": "^4.1.0",
"@ethereumjs/tx": "^5.1.0",
"@ethereumjs/util": "^9.0.1",
"@ethereumjs/vm": "^7.1.0",
"@thepowereco/msgpack": "^1.5.3",
"@types/bitcoinjs-lib": "^5.0.0",
"axios": "^0.27.2",
"bignumber.js": "^9.1.0",
"bip32": "1.0.2",
"bip39": "^3.0.4",
"bitcoinjs-lib": "3.3.2",
Expand All @@ -34,7 +33,6 @@
"crypto-browserify": "^3.12.0",
"debug": "^4.3.4",
"ecpair": "^2.0.1",
"ethereumjs-util": "^7.1.5",
"lz4js": "^0.2.0",
"safe-buffer": "^5.2.1",
"solc": "^0.8.14-fixed",
Expand All @@ -46,6 +44,7 @@
"wif": "^2.0.6"
},
"devDependencies": {
"@types/bitcoinjs-lib": "^5.0.0",
"@types/create-hash": "^1.2.2",
"@types/debug": "^4.1.7",
"@types/node": "^18.7.4",
Expand All @@ -56,7 +55,7 @@
"ts-loader": "^9.2.8",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.14.1",
"typescript": "^4.6.3",
"typescript": "^5.3.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/tssdk/src/helpers/abi.helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PrefixedHexString } from '@ethereumjs/util';
import { decodeParameters, encodeFunctionCall } from 'web3-eth-abi';

export const encodeFunction = (
Expand All @@ -17,7 +18,7 @@ export const encodeFunction = (

export const decodeReturnValue = (
method: string,
returnValue: Buffer,
returnValue: PrefixedHexString,
abi: any,
) => {
const abiItem = abi?.find((item: any) => item.name === method);
Expand All @@ -26,6 +27,6 @@ export const decodeReturnValue = (
throw new Error('ABI item not found');
}

const paramStringAbi: any = decodeParameters(abiItem.outputs, returnValue.toString('hex'));
const paramStringAbi: any = decodeParameters(abiItem.outputs, returnValue);
return paramStringAbi;
};
12 changes: 6 additions & 6 deletions packages/tssdk/src/libs/evm-api/evm-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VM from '@ethereumjs/vm';
import { Address } from 'ethereumjs-util';
import { VM } from '@ethereumjs/vm';
import { Address } from '@ethereumjs/util';
import { NetworkApi, TransactionsApi } from '../index';

import { AccountKey } from '../../typings';
Expand Down Expand Up @@ -51,17 +51,17 @@ export class EvmApi {
const data = this.cache.get(this.scAddress);
const contractAddress = Address.fromString(this.defaultAddress);

const greetResult = await this.vm.runCall({
const getResult = await this.vm.evm.runCall({
to: contractAddress,
data: Buffer.from(encodedFunction, 'hex'),
code: data,
});

if (greetResult.execResult.exceptionError) {
throw greetResult.execResult.exceptionError;
if (getResult.execResult.exceptionError) {
throw getResult.execResult.exceptionError;
}

const results = decodeReturnValue(method, greetResult.execResult.returnValue, this.abi);
const results = decodeReturnValue(method, `0x${Buffer.from(getResult.execResult.returnValue).toString('hex')}`, this.abi);

// eslint-disable-next-line no-underscore-dangle
return results?.__length__ === 1 ? results[0] : results;
Expand Down
8 changes: 4 additions & 4 deletions packages/tssdk/src/libs/evm-api/evmCore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VM from '@ethereumjs/vm';
import { Address } from 'ethereumjs-util';
import { VM } from '@ethereumjs/vm';
import { Address } from '@ethereumjs/util';
import { AddressApi, NetworkApi, TransactionsApi } from '../index';

import { AccountKey } from '../../typings';
Expand Down Expand Up @@ -32,7 +32,7 @@ export class EvmContract {

const contractAddress = Address.fromString(AddressApi.textAddressToEvmAddress(this.address));

const getResult = await this.evm.vm.runCall({
const getResult = await this.evm.vm.evm.runCall({
to: contractAddress,
data: Buffer.from(encodedFunction, 'hex'),
code: this.code as any,
Expand All @@ -42,7 +42,7 @@ export class EvmContract {
throw getResult.execResult.exceptionError;
}

const results = decodeReturnValue(method, getResult.execResult.returnValue, this.abi);
const results = decodeReturnValue(method, `0x${Buffer.from(getResult.execResult.returnValue).toString('hex')}`, this.abi);

// eslint-disable-next-line no-underscore-dangle
return results?.__length__ === 1 ? results[0] : results;
Expand Down
Loading

0 comments on commit 487ebd1

Please sign in to comment.