Skip to content

Commit

Permalink
feat: 🎸 decodeTxInputToEvmInput return params with object(abi)
Browse files Browse the repository at this point in the history
✅ Closes: #15
  • Loading branch information
waynewyang committed Dec 27, 2023
1 parent d4b7df1 commit 5cafda7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/evm/engine/ether/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ export class EthersEvmEngine implements IEVMEngine {
method: abi!.name,
params:
params instanceof EthersResult
? params.toArray()
? convertArrayToObjectByAbiAndName(
this.getContractABI(),
"function",
abi!.name,
params.toArray(),
true
)
: params,
},
}
Expand Down
12 changes: 11 additions & 1 deletion src/evm/engine/web3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,21 @@ export class Web3EvmEngine implements IEVMEngine {
}
}

const paramsResult = parseEvmReplyData(decodedParams)
return {
ok: true,
data: {
method: matchingFunction.name,
params: parseEvmReplyData(decodedParams),
params:
paramsResult instanceof Array
? convertArrayToObjectByAbiAndName(
this.getContractABI(),
"function",
matchingFunction.name,
paramsResult,
true
)
: paramsResult,
},
}
} catch (error) {
Expand Down
21 changes: 19 additions & 2 deletions test/evm/decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ import { web3Proof, ethersProof } from "./env/proof"

const txInput =
"0xa31e76710000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000001e84800000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000a5367757a46505851584e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a347373674f3836327a7500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a457758386353716d4d3900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a644d6e4658505550613300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a7452393954375947326c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4c4d32744d365157343800000000000000000000000000000000000000000000"
const evmInput_Obj = {
ok: true,
data: {
method: "submitDatasetMetadata",
params: {
title: "SguzFPXQXN",
industry: "4ssgO862zu",
name: "EwX8cSqmM9",
description: "dMnFXPUPa3",
source: "tR99T7YG2l",
accessMethod: "LM2tM6QW48",
sizeInBytes: BigInt(512000000),
isPublic: true,
version: BigInt(1),
},
},
}

const evmInput = {
ok: true,
Expand Down Expand Up @@ -67,7 +84,7 @@ describe("Encoding and decoding test", () => {
describe("decodeTxInput Test", () => {
it("web3 correct test(multi params)", () => {
const web3Decode = web3Datasets.decodeTxInputToEvmInput(txInput)
assert.deepStrictEqual(web3Decode, evmInput)
assert.deepStrictEqual(web3Decode, evmInput_Obj)
})

it("web3 correct test(one param)", () => {
Expand All @@ -78,7 +95,7 @@ describe("Encoding and decoding test", () => {

it("ethers correct test(multi params)", () => {
const ethersDecode = ethersDatasets.decodeTxInputToEvmInput(txInput)
assert.deepStrictEqual(ethersDecode, evmInput)
assert.deepStrictEqual(ethersDecode, evmInput_Obj)
})

it("ethers correct test(one param)", () => {
Expand Down

0 comments on commit 5cafda7

Please sign in to comment.