Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

fix: Reimplement decodeArgs #617

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/api-server/src/base/decode-args.ts
Original file line number Diff line number Diff line change
@@ -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 };
}
2 changes: 1 addition & 1 deletion packages/api-server/src/erc20-decoder.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/src/methods/modules/gw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/src/methods/modules/poly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { Query } from "../../db";
import { isAddressMatch, isShortAddressOnChain } from "../../base/address";
import {
decodeArgs,
deserializeL2TransactionWithAddressMapping,
deserializeRawL2TransactionWithAddressMapping,
deserializeAbiItem,
Expand All @@ -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;

Expand Down