essential-eth 0.4.10 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/classes/utils/clean-block.d.ts +3 -3
- package/lib/cjs/classes/utils/clean-block.js +3 -2
- package/lib/cjs/classes/utils/clean-transaction.d.ts +3 -3
- package/lib/cjs/classes/utils/clean-transaction.js +10 -6
- package/lib/cjs/classes/utils/fetchers.d.ts +3 -3
- package/lib/cjs/index.d.ts +5 -3
- package/lib/cjs/index.js +16 -0
- package/lib/cjs/logger/logger.d.ts +11 -0
- package/lib/cjs/logger/logger.js +36 -0
- package/lib/cjs/logger/package-version.d.ts +1 -0
- package/lib/cjs/logger/package-version.js +5 -0
- package/lib/cjs/providers/JsonRpcProvider.d.ts +190 -3
- package/lib/cjs/providers/JsonRpcProvider.js +214 -19
- package/lib/cjs/providers/test/rpc-urls.d.ts +2 -0
- package/lib/cjs/providers/test/rpc-urls.js +2 -0
- package/lib/cjs/providers/utils/chains-info.d.ts +11 -0
- package/lib/cjs/providers/utils/chains-info.js +34 -1
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +7 -0
- package/lib/cjs/shared/tiny-big/tiny-big.js +24 -0
- package/lib/cjs/types/Block.types.d.ts +9 -19
- package/lib/cjs/types/Transaction.types.d.ts +23 -14
- package/lib/cjs/utils/bytes.d.ts +90 -0
- package/lib/cjs/utils/bytes.js +484 -0
- package/lib/cjs/utils/solidity-keccak256.d.ts +30 -0
- package/lib/cjs/utils/solidity-keccak256.js +125 -0
- package/lib/esm/classes/utils/clean-block.d.ts +2 -2
- package/lib/esm/classes/utils/clean-block.js +2 -1
- package/lib/esm/classes/utils/clean-transaction.d.ts +2 -2
- package/lib/esm/classes/utils/clean-transaction.js +10 -6
- package/lib/esm/classes/utils/fetchers.d.ts +3 -3
- package/lib/esm/index.d.ts +5 -3
- package/lib/esm/index.js +2 -0
- package/lib/esm/logger/logger.d.ts +11 -0
- package/lib/esm/logger/logger.js +33 -0
- package/lib/esm/logger/package-version.d.ts +1 -0
- package/lib/esm/logger/package-version.js +1 -0
- package/lib/esm/providers/JsonRpcProvider.d.ts +6 -2
- package/lib/esm/providers/JsonRpcProvider.js +30 -19
- package/lib/esm/providers/test/rpc-urls.d.ts +2 -0
- package/lib/esm/providers/test/rpc-urls.js +2 -0
- package/lib/esm/providers/utils/chains-info.d.ts +11 -0
- package/lib/esm/providers/utils/chains-info.js +34 -1
- package/lib/esm/shared/tiny-big/tiny-big.d.ts +2 -0
- package/lib/esm/shared/tiny-big/tiny-big.js +19 -0
- package/lib/esm/types/Block.types.d.ts +8 -19
- package/lib/esm/types/Transaction.types.d.ts +22 -14
- package/lib/esm/utils/bytes.d.ts +39 -0
- package/lib/esm/utils/bytes.js +245 -0
- package/lib/esm/utils/solidity-keccak256.d.ts +3 -0
- package/lib/esm/utils/solidity-keccak256.js +91 -0
- package/package.json +15 -17
- package/readme.md +252 -62
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toChecksumAddress } from '../..';
|
|
1
|
+
import { tinyBig, toChecksumAddress } from '../..';
|
|
2
2
|
import { hexToDecimal } from './hex-to-decimal';
|
|
3
3
|
export function cleanTransaction(transaction) {
|
|
4
4
|
const cleanedTransaction = Object.assign({}, transaction);
|
|
@@ -7,22 +7,26 @@ export function cleanTransaction(transaction) {
|
|
|
7
7
|
return;
|
|
8
8
|
switch (key) {
|
|
9
9
|
case 'blockNumber':
|
|
10
|
-
case '
|
|
10
|
+
case 'chainId':
|
|
11
11
|
case 'nonce':
|
|
12
12
|
case 'transactionIndex':
|
|
13
13
|
case 'type':
|
|
14
|
+
case 'v':
|
|
14
15
|
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
15
16
|
break;
|
|
16
|
-
case 'gasPrice':
|
|
17
|
-
case 'value':
|
|
18
|
-
cleanedTransaction[key] = hexToDecimal(transaction[key]);
|
|
19
|
-
break;
|
|
20
17
|
case 'from':
|
|
21
18
|
case 'to':
|
|
22
19
|
if (transaction[key]) {
|
|
23
20
|
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
24
21
|
}
|
|
25
22
|
break;
|
|
23
|
+
case 'value':
|
|
24
|
+
case 'gas':
|
|
25
|
+
case 'gasPrice':
|
|
26
|
+
case 'maxFeePerGas':
|
|
27
|
+
case 'maxPriorityFeePerGas':
|
|
28
|
+
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
29
|
+
break;
|
|
26
30
|
}
|
|
27
31
|
});
|
|
28
32
|
return cleanedTransaction;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
2
|
-
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice';
|
|
3
|
-
export declare function buildRPCPostBody(method: RPCMethodName, params:
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash';
|
|
3
|
+
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
|
6
6
|
method: RPCMethodName;
|
|
7
|
-
params:
|
|
7
|
+
params: unknown[];
|
|
8
8
|
};
|
|
9
9
|
export {};
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Contract } from './classes/Contract';
|
|
2
2
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
3
3
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
4
|
-
import {
|
|
4
|
+
import { BlockResponse } from './types/Block.types';
|
|
5
5
|
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
6
6
|
import { Network } from './types/Network.types';
|
|
7
|
-
import {
|
|
7
|
+
import { TransactionResponse } from './types/Transaction.types';
|
|
8
8
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
9
9
|
import { etherToWei } from './utils/ether-to-wei';
|
|
10
10
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
11
11
|
import { isAddress } from './utils/is-address';
|
|
12
12
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
13
13
|
import { weiToEther } from './utils/wei-to-ether';
|
|
14
|
-
export
|
|
14
|
+
export * from './utils/bytes';
|
|
15
|
+
export * from './utils/solidity-keccak256';
|
|
16
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
|
package/lib/esm/index.js
CHANGED
|
@@ -7,4 +7,6 @@ import { gweiToEther } from './utils/gwei-to-ether';
|
|
|
7
7
|
import { isAddress } from './utils/is-address';
|
|
8
8
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
9
9
|
import { weiToEther } from './utils/wei-to-ether';
|
|
10
|
+
export * from './utils/bytes';
|
|
11
|
+
export * from './utils/solidity-keccak256';
|
|
10
12
|
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class Logger {
|
|
2
|
+
private packageVersion;
|
|
3
|
+
constructor();
|
|
4
|
+
throwError(message: string, args: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}): never;
|
|
7
|
+
throwArgumentError(message: string, arg: string, value: any): never;
|
|
8
|
+
checkSafeUint53(value: number, message?: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const logger: Logger;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { version } from './package-version';
|
|
2
|
+
class Logger {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.packageVersion = version;
|
|
5
|
+
}
|
|
6
|
+
throwError(message, args) {
|
|
7
|
+
const argsLength = Object.keys(args).length;
|
|
8
|
+
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
9
|
+
}
|
|
10
|
+
throwArgumentError(message, arg, value) {
|
|
11
|
+
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
12
|
+
}
|
|
13
|
+
checkSafeUint53(value, message = 'value not safe') {
|
|
14
|
+
if (typeof value !== 'number') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
18
|
+
this.throwError(message, {
|
|
19
|
+
operation: 'checkSafeInteger',
|
|
20
|
+
fault: 'out-of-safe-range',
|
|
21
|
+
value: value,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (value % 1) {
|
|
25
|
+
this.throwError(message, {
|
|
26
|
+
operation: 'checkSafeInteger',
|
|
27
|
+
fault: 'non-integer',
|
|
28
|
+
value: value,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const logger = new Logger();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.5.1";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '0.5.1';
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
-
import {
|
|
2
|
+
import { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
3
|
import { Network } from '../types/Network.types';
|
|
4
|
+
import { TransactionResponse } from '../types/Transaction.types';
|
|
4
5
|
export declare class JsonRpcProvider {
|
|
5
6
|
readonly _rpcUrl: string;
|
|
7
|
+
private post;
|
|
6
8
|
constructor(rpcUrl?: string);
|
|
7
|
-
getBlock(timeFrame
|
|
9
|
+
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
8
10
|
getNetwork(): Promise<Network>;
|
|
9
11
|
getGasPrice(): Promise<TinyBig>;
|
|
12
|
+
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
13
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
10
14
|
}
|
|
11
15
|
export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
|
|
@@ -8,15 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { cleanBlock } from '../classes/utils/clean-block';
|
|
11
|
+
import { cleanTransaction } from '../classes/utils/clean-transaction';
|
|
11
12
|
import { buildRPCPostBody, post } from '../classes/utils/fetchers';
|
|
12
13
|
import { hexToDecimal } from '../classes/utils/hex-to-decimal';
|
|
13
14
|
import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
14
15
|
import chainsInfo from './utils/chains-info';
|
|
15
16
|
export class JsonRpcProvider {
|
|
16
17
|
constructor(rpcUrl) {
|
|
18
|
+
this.post = (body) => post(this._rpcUrl, body);
|
|
17
19
|
this._rpcUrl = rpcUrl || 'https://free-eth-node.com/api/eth';
|
|
18
20
|
}
|
|
19
|
-
getBlock(timeFrame, returnTransactionObjects = false) {
|
|
21
|
+
getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
|
|
20
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
23
|
let rpcTimeFrame;
|
|
22
24
|
if (typeof timeFrame === 'number') {
|
|
@@ -25,23 +27,17 @@ export class JsonRpcProvider {
|
|
|
25
27
|
else {
|
|
26
28
|
rpcTimeFrame = timeFrame;
|
|
27
29
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
const nodeResponse = (yield req());
|
|
35
|
-
return cleanBlock(nodeResponse, returnTransactionObjects);
|
|
30
|
+
const rpcBlock = (yield this.post(buildRPCPostBody('eth_getBlockByNumber', [
|
|
31
|
+
rpcTimeFrame,
|
|
32
|
+
returnTransactionObjects,
|
|
33
|
+
])));
|
|
34
|
+
return cleanBlock(rpcBlock, returnTransactionObjects);
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
getNetwork() {
|
|
39
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
const nodeResponse = (yield req());
|
|
44
|
-
const chainId = hexToDecimal(nodeResponse);
|
|
39
|
+
const hexChainId = (yield this.post(buildRPCPostBody('eth_chainId', [])));
|
|
40
|
+
const chainId = hexToDecimal(hexChainId);
|
|
45
41
|
const info = chainsInfo[chainId];
|
|
46
42
|
return {
|
|
47
43
|
chainId: Number(chainId),
|
|
@@ -52,11 +48,26 @@ export class JsonRpcProvider {
|
|
|
52
48
|
}
|
|
53
49
|
getGasPrice() {
|
|
54
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
const hexGasPrice = (yield this.post(buildRPCPostBody('eth_gasPrice', [])));
|
|
52
|
+
return tinyBig(hexToDecimal(hexGasPrice));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getBalance(address, blockTag = 'latest') {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const hexBalance = (yield this.post(buildRPCPostBody('eth_getBalance', [address, blockTag])));
|
|
58
|
+
return tinyBig(hexToDecimal(hexBalance));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getTransaction(hash) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
64
|
+
this.post(buildRPCPostBody('eth_getTransactionByHash', [hash])),
|
|
65
|
+
this.getBlock('latest'),
|
|
66
|
+
]);
|
|
67
|
+
const cleanedTransaction = cleanTransaction(rpcTransaction);
|
|
68
|
+
cleanedTransaction.confirmations =
|
|
69
|
+
blockNumber.number - cleanedTransaction.blockNumber + 1;
|
|
70
|
+
return cleanedTransaction;
|
|
60
71
|
});
|
|
61
72
|
}
|
|
62
73
|
}
|
|
@@ -66,7 +66,9 @@ declare const _default: {
|
|
|
66
66
|
"76": string[];
|
|
67
67
|
"77": string[];
|
|
68
68
|
"78": string[];
|
|
69
|
+
"79": string[];
|
|
69
70
|
"80": string[];
|
|
71
|
+
"81": string[];
|
|
70
72
|
"82": string[];
|
|
71
73
|
"83": string[];
|
|
72
74
|
"85": string[];
|
|
@@ -147,6 +149,7 @@ declare const _default: {
|
|
|
147
149
|
"600": string[];
|
|
148
150
|
"666": string[];
|
|
149
151
|
"686": string[];
|
|
152
|
+
"700": string[];
|
|
150
153
|
"707": string[];
|
|
151
154
|
"708": string[];
|
|
152
155
|
"721": string[];
|
|
@@ -208,8 +211,11 @@ declare const _default: {
|
|
|
208
211
|
"2025": string[];
|
|
209
212
|
"2100": string[];
|
|
210
213
|
"2101": string[];
|
|
214
|
+
"2152": string[];
|
|
215
|
+
"2153": string[];
|
|
211
216
|
"2213": string[];
|
|
212
217
|
"2221": string[];
|
|
218
|
+
"2223": string[];
|
|
213
219
|
"2559": string[];
|
|
214
220
|
"3000": string[];
|
|
215
221
|
"3001": string[];
|
|
@@ -228,6 +234,8 @@ declare const _default: {
|
|
|
228
234
|
"4918": string[];
|
|
229
235
|
"5197": string[];
|
|
230
236
|
"5315": string[];
|
|
237
|
+
"5551": string[];
|
|
238
|
+
"5553": string[];
|
|
231
239
|
"5700": string[];
|
|
232
240
|
"5777": string[];
|
|
233
241
|
"5851": string[];
|
|
@@ -262,6 +270,7 @@ declare const _default: {
|
|
|
262
270
|
"16000": string[];
|
|
263
271
|
"16001": string[];
|
|
264
272
|
"19845": string[];
|
|
273
|
+
"21337": string[];
|
|
265
274
|
"21816": string[];
|
|
266
275
|
"24484": string[];
|
|
267
276
|
"24734": string[];
|
|
@@ -291,6 +300,7 @@ declare const _default: {
|
|
|
291
300
|
"62320": string[];
|
|
292
301
|
"63000": string[];
|
|
293
302
|
"63001": string[];
|
|
303
|
+
"69420": string[];
|
|
294
304
|
"70000": string[];
|
|
295
305
|
"70001": string[];
|
|
296
306
|
"70002": string[];
|
|
@@ -344,6 +354,7 @@ declare const _default: {
|
|
|
344
354
|
"11155111": string[];
|
|
345
355
|
"13371337": string[];
|
|
346
356
|
"18289463": string[];
|
|
357
|
+
"20180430": string[];
|
|
347
358
|
"20181205": string[];
|
|
348
359
|
"28945486": string[];
|
|
349
360
|
"35855456": string[];
|
|
@@ -204,9 +204,15 @@ export default {
|
|
|
204
204
|
"78": [
|
|
205
205
|
"primuschain"
|
|
206
206
|
],
|
|
207
|
+
"79": [
|
|
208
|
+
"zenith"
|
|
209
|
+
],
|
|
207
210
|
"80": [
|
|
208
211
|
"GeneChain"
|
|
209
212
|
],
|
|
213
|
+
"81": [
|
|
214
|
+
"VIL"
|
|
215
|
+
],
|
|
210
216
|
"82": [
|
|
211
217
|
"Meter"
|
|
212
218
|
],
|
|
@@ -447,6 +453,9 @@ export default {
|
|
|
447
453
|
"686": [
|
|
448
454
|
"kar"
|
|
449
455
|
],
|
|
456
|
+
"700": [
|
|
457
|
+
"SNS"
|
|
458
|
+
],
|
|
450
459
|
"707": [
|
|
451
460
|
"bcs"
|
|
452
461
|
],
|
|
@@ -583,7 +592,7 @@ export default {
|
|
|
583
592
|
"mrock"
|
|
584
593
|
],
|
|
585
594
|
"1337": [
|
|
586
|
-
"cennz-
|
|
595
|
+
"cennz-old"
|
|
587
596
|
],
|
|
588
597
|
"1618": [
|
|
589
598
|
"cate"
|
|
@@ -630,12 +639,21 @@ export default {
|
|
|
630
639
|
"2101": [
|
|
631
640
|
"esp"
|
|
632
641
|
],
|
|
642
|
+
"2152": [
|
|
643
|
+
"fra"
|
|
644
|
+
],
|
|
645
|
+
"2153": [
|
|
646
|
+
"findora-testnet"
|
|
647
|
+
],
|
|
633
648
|
"2213": [
|
|
634
649
|
"evanesco"
|
|
635
650
|
],
|
|
636
651
|
"2221": [
|
|
637
652
|
"kava"
|
|
638
653
|
],
|
|
654
|
+
"2223": [
|
|
655
|
+
"VChain"
|
|
656
|
+
],
|
|
639
657
|
"2559": [
|
|
640
658
|
"ktoc"
|
|
641
659
|
],
|
|
@@ -690,6 +708,12 @@ export default {
|
|
|
690
708
|
"5315": [
|
|
691
709
|
"UZMI"
|
|
692
710
|
],
|
|
711
|
+
"5551": [
|
|
712
|
+
"Nahmii"
|
|
713
|
+
],
|
|
714
|
+
"5553": [
|
|
715
|
+
"Nahmii testnet"
|
|
716
|
+
],
|
|
693
717
|
"5700": [
|
|
694
718
|
"tsys"
|
|
695
719
|
],
|
|
@@ -792,6 +816,9 @@ export default {
|
|
|
792
816
|
"19845": [
|
|
793
817
|
"btcix"
|
|
794
818
|
],
|
|
819
|
+
"21337": [
|
|
820
|
+
"cennz-a"
|
|
821
|
+
],
|
|
795
822
|
"21816": [
|
|
796
823
|
"oml"
|
|
797
824
|
],
|
|
@@ -879,6 +906,9 @@ export default {
|
|
|
879
906
|
"63001": [
|
|
880
907
|
"ecs-testnet"
|
|
881
908
|
],
|
|
909
|
+
"69420": [
|
|
910
|
+
"cndr"
|
|
911
|
+
],
|
|
882
912
|
"70000": [
|
|
883
913
|
"TKM0"
|
|
884
914
|
],
|
|
@@ -1038,6 +1068,9 @@ export default {
|
|
|
1038
1068
|
"18289463": [
|
|
1039
1069
|
"ilt"
|
|
1040
1070
|
],
|
|
1071
|
+
"20180430": [
|
|
1072
|
+
"spectrum"
|
|
1073
|
+
],
|
|
1041
1074
|
"20181205": [
|
|
1042
1075
|
"qki"
|
|
1043
1076
|
],
|
|
@@ -3,6 +3,9 @@ import { scientificStrToDecimalStr } from './helpers';
|
|
|
3
3
|
export class TinyBig extends Big {
|
|
4
4
|
constructor(value) {
|
|
5
5
|
super(value);
|
|
6
|
+
this.padAndChop = (str, padChar, length) => {
|
|
7
|
+
return (Array(length).fill(padChar).join('') + str).slice(length * -1);
|
|
8
|
+
};
|
|
6
9
|
}
|
|
7
10
|
toHexString() {
|
|
8
11
|
return `0x${BigInt(this.toString()).toString(16)}`;
|
|
@@ -16,6 +19,22 @@ export class TinyBig extends Big {
|
|
|
16
19
|
}
|
|
17
20
|
return scientificStrToDecimalStr(super.toString());
|
|
18
21
|
}
|
|
22
|
+
toTwos(bitCount) {
|
|
23
|
+
let binaryStr;
|
|
24
|
+
if (this.gte(0)) {
|
|
25
|
+
const twosComp = this.toNumber().toString(2);
|
|
26
|
+
binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
|
|
30
|
+
if (Number(binaryStr) < 0) {
|
|
31
|
+
throw new Error('Cannot calculate twos complement');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const binary = `0b${binaryStr}`;
|
|
35
|
+
const decimal = Number(binary);
|
|
36
|
+
return tinyBig(decimal);
|
|
37
|
+
}
|
|
19
38
|
}
|
|
20
39
|
export function tinyBig(value) {
|
|
21
40
|
return new TinyBig(value);
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
difficulty: number;
|
|
5
|
-
extraData: string;
|
|
1
|
+
import { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
|
|
2
|
+
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
3
|
+
export declare type BlockResponse = Modify<RPCBlock, {
|
|
6
4
|
gasLimit: number;
|
|
7
5
|
gasUsed: number;
|
|
8
|
-
hash: string;
|
|
9
|
-
logsBloom: string;
|
|
10
|
-
miner: string;
|
|
11
|
-
mixHash: string;
|
|
12
|
-
nonce: string;
|
|
13
6
|
number: number;
|
|
14
|
-
parentHash: string;
|
|
15
|
-
receiptsRoot: string;
|
|
16
|
-
sha3Uncles: string;
|
|
17
7
|
size: number;
|
|
18
|
-
stateRoot: string;
|
|
19
8
|
timestamp: number;
|
|
20
|
-
|
|
21
|
-
transactions: string
|
|
22
|
-
|
|
23
|
-
uncles: unknown[];
|
|
24
|
-
}
|
|
9
|
+
baseFeePerGas: number;
|
|
10
|
+
transactions: Array<string | BlockTransactionResponse>;
|
|
11
|
+
}>;
|
|
25
12
|
export interface RPCBlock {
|
|
26
13
|
baseFeePerGas: string;
|
|
27
14
|
difficulty: string;
|
|
@@ -45,3 +32,5 @@ export interface RPCBlock {
|
|
|
45
32
|
transactionsRoot: string;
|
|
46
33
|
uncles: unknown[];
|
|
47
34
|
}
|
|
35
|
+
export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
|
|
36
|
+
export {};
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
+
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
3
|
+
export interface RPCTransaction extends RPCBlockTransaction {
|
|
4
|
+
maxFeePerGas: string;
|
|
5
|
+
maxPriorityFeePerGas: string;
|
|
6
|
+
}
|
|
7
|
+
export declare type TransactionResponse = Modify<RPCTransaction, {
|
|
3
8
|
blockNumber: number;
|
|
4
|
-
|
|
5
|
-
gas: number;
|
|
6
|
-
gasPrice: string;
|
|
7
|
-
hash: string;
|
|
8
|
-
input: string;
|
|
9
|
+
chainId: number;
|
|
9
10
|
nonce: number;
|
|
10
|
-
r: string;
|
|
11
|
-
s: string;
|
|
12
|
-
to: string;
|
|
13
11
|
transactionIndex: number;
|
|
14
12
|
type: number;
|
|
15
|
-
v:
|
|
16
|
-
value:
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
v: number;
|
|
14
|
+
value: TinyBig;
|
|
15
|
+
gasPrice: TinyBig;
|
|
16
|
+
gas: TinyBig;
|
|
17
|
+
gasLimit: TinyBig;
|
|
18
|
+
} & {
|
|
19
|
+
maxFeePerGas: TinyBig;
|
|
20
|
+
maxPriorityFeePerGas: TinyBig;
|
|
21
|
+
confirmations: number;
|
|
22
|
+
}>;
|
|
23
|
+
export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
|
|
24
|
+
export interface RPCBlockTransaction {
|
|
19
25
|
blockHash: string;
|
|
20
26
|
blockNumber: string;
|
|
27
|
+
chainId: string;
|
|
21
28
|
from: string;
|
|
22
29
|
gas: string;
|
|
23
30
|
gasPrice: string;
|
|
@@ -32,3 +39,4 @@ export interface RPCTransaction {
|
|
|
32
39
|
v: string;
|
|
33
40
|
value: string;
|
|
34
41
|
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare type Bytes = ArrayLike<number>;
|
|
2
|
+
export declare type BytesLike = Bytes | string | number;
|
|
3
|
+
export interface DataOptions {
|
|
4
|
+
allowMissingPrefix?: boolean;
|
|
5
|
+
hexPad?: 'left' | 'right' | null;
|
|
6
|
+
}
|
|
7
|
+
export interface Hexable {
|
|
8
|
+
toHexString(): string;
|
|
9
|
+
}
|
|
10
|
+
export declare type SignatureLike = {
|
|
11
|
+
r: string;
|
|
12
|
+
s?: string;
|
|
13
|
+
_vs?: string;
|
|
14
|
+
recoveryParam?: number;
|
|
15
|
+
v?: number;
|
|
16
|
+
} | BytesLike;
|
|
17
|
+
export interface Signature {
|
|
18
|
+
r: string;
|
|
19
|
+
s: string;
|
|
20
|
+
_vs: string;
|
|
21
|
+
recoveryParam: number;
|
|
22
|
+
v: number;
|
|
23
|
+
yParityAndS: string;
|
|
24
|
+
compact: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function isBytesLike(value: any): value is BytesLike;
|
|
27
|
+
export declare function isBytes(value: any): value is Bytes;
|
|
28
|
+
export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
|
|
29
|
+
export declare function concat(items: ReadonlyArray<BytesLike>): Uint8Array;
|
|
30
|
+
export declare function stripZeros(value: BytesLike): Uint8Array;
|
|
31
|
+
export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
|
|
32
|
+
export declare function isHexString(value: any, length?: number): boolean;
|
|
33
|
+
export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
|
|
34
|
+
export declare function hexDataLength(data: BytesLike): number | null;
|
|
35
|
+
export declare function hexDataSlice(data: BytesLike, offset: number, endOffset?: number): string;
|
|
36
|
+
export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
|
|
37
|
+
export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
|
|
38
|
+
export declare function hexStripZeros(value: BytesLike): string;
|
|
39
|
+
export declare function hexZeroPad(value: BytesLike, length: number): string;
|