From 6c3b4ad0ec4b164e3b4977f6508f1dc9ee7800ea Mon Sep 17 00:00:00 2001 From: classicalliu Date: Thu, 23 Feb 2023 22:08:56 +0800 Subject: [PATCH] fix: Reimplement decodeArgs --- packages/api-server/src/base/decode-args.ts | 23 +++++++++++++++++++ packages/api-server/src/erc20-decoder.ts | 2 +- packages/api-server/src/methods/modules/gw.ts | 2 +- .../api-server/src/methods/modules/poly.ts | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 packages/api-server/src/base/decode-args.ts diff --git a/packages/api-server/src/base/decode-args.ts b/packages/api-server/src/base/decode-args.ts new file mode 100644 index 00000000..fa07178c --- /dev/null +++ b/packages/api-server/src/base/decode-args.ts @@ -0,0 +1,23 @@ +import { HexString } from "@ckb-lumos/base"; +import { Uint128, Uint32, Uint64 } from "./types/uint"; + +export function decodeArgs(args: HexString) { + args = args.slice(2); + const args_0_7 = "0x" + args.slice(0, 14); + const args_7 = "0x" + args.slice(14, 16); + const args_8_16 = "0x" + args.slice(16, 32); + const args_16_32 = "0x" + args.slice(32, 64); + const args_32_48 = "0x" + args.slice(64, 96); + const args_48_52 = "0x" + args.slice(96, 104); + const args_data = "0x" + args.slice(104); + + const header = Buffer.from(args_0_7.slice(8), "hex").toString("utf-8"); + const type = args_7; + const gas_limit = Uint64.fromLittleEndian(args_8_16).toHex(); + const gas_price = Uint128.fromLittleEndian(args_16_32).toHex(); + const value = Uint128.fromLittleEndian(args_32_48).toHex(); + const data_length = Uint32.fromLittleEndian(args_48_52).toHex(); + const data = args_data; + + return { header, type, gas_limit, gas_price, value, data_length, data }; +} diff --git a/packages/api-server/src/erc20-decoder.ts b/packages/api-server/src/erc20-decoder.ts index e01d75e5..437abae9 100644 --- a/packages/api-server/src/erc20-decoder.ts +++ b/packages/api-server/src/erc20-decoder.ts @@ -1,6 +1,6 @@ -import { decodeArgs } from "@polyjuice-provider/base"; import InputDataDecoder from "ethereum-input-data-decoder"; import { SUDT_ERC20_PROXY_ABI } from "./erc20"; +import { decodeArgs } from "./base/decode-args"; const deocder = new InputDataDecoder(SUDT_ERC20_PROXY_ABI as any); diff --git a/packages/api-server/src/methods/modules/gw.ts b/packages/api-server/src/methods/modules/gw.ts index a9164cb3..343d8518 100644 --- a/packages/api-server/src/methods/modules/gw.ts +++ b/packages/api-server/src/methods/modules/gw.ts @@ -8,7 +8,7 @@ import { CACHE_EXPIRED_TIME_MILSECS, GW_RPC_KEY } from "../../cache/constant"; import { logger } from "../../base/logger"; import { L2Transaction } from "@godwoken-web3/godwoken/schemas"; import { Reader } from "@ckb-lumos/toolkit"; -import { decodeArgs } from "@polyjuice-provider/base"; +import { decodeArgs } from "../../base/decode-args"; export class Gw { private rpc: RPC; diff --git a/packages/api-server/src/methods/modules/poly.ts b/packages/api-server/src/methods/modules/poly.ts index 8898dfb6..7f20026b 100644 --- a/packages/api-server/src/methods/modules/poly.ts +++ b/packages/api-server/src/methods/modules/poly.ts @@ -11,7 +11,6 @@ import { import { Query } from "../../db"; import { isAddressMatch, isShortAddressOnChain } from "../../base/address"; import { - decodeArgs, deserializeL2TransactionWithAddressMapping, deserializeRawL2TransactionWithAddressMapping, deserializeAbiItem, @@ -29,6 +28,7 @@ import { keccakFromHexString } from "ethereumjs-util"; import { DataCacheConstructor, RedisDataCache } from "../../cache/data"; import { BlockParameter } from "../types"; import { logger } from "../../base/logger"; +import { decodeArgs } from "../../base/decode-args"; type GodwokenBlockParameter = U64 | undefined;