Skip to content

Commit

Permalink
fix: removed unnecessary dependency on web3-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ziegfried committed Mar 7, 2020
1 parent f8e3f3d commit 2939685
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 273 deletions.
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -25,16 +25,14 @@
"js-yaml": "^3.13.1",
"lodash": "^4.17.15",
"node-fetch": "^2.6.0",
"tslib": "^1",
"web3-utils": "^1.2.4"
"tslib": "^1"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@semantic-release/changelog": "^3.0.6",
"@semantic-release/git": "^7.0.18",
"@types/bl": "^2.1.0",
"@types/bn.js": "^4.11.5",
"@types/debug": "^4.1.5",
"@types/fs-extra": "^8.0.1",
"@types/jest": "^24.0.23",
Expand Down
3 changes: 1 addition & 2 deletions src/abi/files.ts
@@ -1,10 +1,9 @@
import { readdir, readFile, stat, createReadStream } from 'fs-extra';
import { basename, join as joinPath, resolve } from 'path';
import { AbiItem } from 'web3-utils';
import { AbiRepositoryConfig } from '../config';
import { Address } from '../msgs';
import { createModuleDebug, TRACE_ENABLED } from '../utils/debug';
import { AbiItemDefinition } from './item';
import { AbiItemDefinition, AbiItem } from './item';
import { computeContractFingerprint } from './contract';
import { computeSignature } from './signature';
import { createGunzip } from 'zlib';
Expand Down
28 changes: 27 additions & 1 deletion src/abi/item.ts
@@ -1,4 +1,30 @@
import { AbiInput } from 'web3-utils';
export type AbiType = 'function' | 'constructor' | 'event' | 'fallback';
export type StateMutabilityType = 'pure' | 'view' | 'nonpayable' | 'payable';

export interface AbiItem {
anonymous?: boolean;
constant?: boolean;
inputs?: AbiInput[];
name?: string;
outputs?: AbiOutput[];
payable?: boolean;
stateMutability?: StateMutabilityType;
type: AbiType;
}

export interface AbiInput {
name: string;
type: string;
indexed?: boolean;
components?: AbiInput[];
}

export interface AbiOutput {
name: string;
type: string;
components?: AbiOutput[];
internalType?: string;
}

/**
* A single ABI definition of a function or a log event, with additional
Expand Down
5 changes: 2 additions & 3 deletions src/abi/signature.ts
@@ -1,7 +1,6 @@
import { AbiInput } from 'web3-utils';
import { isValidAbiType } from './datatypes';
import { AbiItemDefinition } from './item';
import { parseFunctionSignature, parseEventSignature, sha3 } from './wasm';
import { AbiInput, AbiItemDefinition } from './item';
import { parseEventSignature, parseFunctionSignature, sha3 } from './wasm';

const err = (msg: string): never => {
throw new Error(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/abi/wasm.ts
@@ -1,4 +1,3 @@
import { AbiItem } from 'web3-utils';
import {
abi_decode_parameters,
get_data_size,
Expand All @@ -13,6 +12,7 @@ import {
import { memory } from '../../wasm/ethabi/pkg/ethlogger_ethabi_bg';
import { createModuleDebug } from '../utils/debug';
import { AbiType } from './datatypes';
import { AbiItem } from './item';

const { trace } = createModuleDebug('abi:decode');

Expand Down
5 changes: 2 additions & 3 deletions src/eth/requests.ts
@@ -1,5 +1,4 @@
import { numberToHex } from 'web3-utils';
import { bigIntToNumber } from '../utils/bn';
import { bigIntToNumber, numberToHex } from '../utils/bn';
import { JsonRpcResponse } from './jsonrpc';
import {
GethMemStats,
Expand All @@ -13,8 +12,8 @@ import {
ParityPendingTransaction,
RawBlockResponse,
RawTransactionReceipt,
SyncStatus,
RawTransactionResponse,
SyncStatus,
} from './responses';

export interface EthRequest<P extends any[], R> {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/bn.ts
@@ -1,5 +1,6 @@
const MAX_NUMBER = BigInt(Number.MAX_SAFE_INTEGER);
const MIN_NUMBER = BigInt(Number.MIN_SAFE_INTEGER);
const ZERO = BigInt(0);

/**
* Parses the given input using JS's native BigInt and returns a number or a string depending on the size of the number.
Expand All @@ -26,3 +27,12 @@ export function bigIntToNumber(input: number | string | BigInt): number {
}
return parseInt(n.toString(10), 10);
}

/**
* Returns hex representation of the given number if "0x" prefix
*/
export function numberToHex(input: number | string | BigInt): string {
const n = BigInt(input);
const hex = n.toString(16);
return n < ZERO ? `-0x${hex.slice(1)}` : `0x${hex}`;
}

0 comments on commit 2939685

Please sign in to comment.