essential-eth 0.9.1-next.0 → 0.9.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/dist/cjs/classes/Contract.js +66 -311
- package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
- package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
- package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
- package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
- package/dist/cjs/classes/utils/clean-block.js +30 -52
- package/dist/cjs/classes/utils/clean-log.js +20 -42
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
- package/dist/cjs/classes/utils/clean-transaction.js +30 -52
- package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
- package/dist/cjs/classes/utils/fetchers.js +44 -166
- package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
- package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
- package/dist/cjs/index.js +56 -25
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +29 -123
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +4 -1
- package/dist/cjs/providers/AlchemyProvider.js +9 -82
- package/dist/cjs/providers/BaseProvider.js +520 -958
- package/dist/cjs/providers/FallthroughProvider.js +47 -156
- package/dist/cjs/providers/JsonRpcProvider.js +28 -114
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
- package/dist/cjs/providers/test/mock-of.js +6 -3
- package/dist/cjs/providers/test/rpc-urls.js +23 -15
- package/dist/cjs/providers/utils/chains-info.js +3 -1
- package/dist/cjs/shared/tiny-big/helpers.js +42 -93
- package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +2 -1
- package/dist/cjs/types/Contract.types.js +2 -1
- package/dist/cjs/types/FeeData.types.js +2 -1
- package/dist/cjs/types/Filter.types.js +2 -1
- package/dist/cjs/types/Network.types.js +2 -3
- package/dist/cjs/types/Transaction.types.js +2 -1
- package/dist/cjs/utils/bytes.js +318 -286
- package/dist/cjs/utils/compute-address.js +15 -8
- package/dist/cjs/utils/compute-public-key.js +10 -5
- package/dist/cjs/utils/ether-to-gwei.js +11 -10
- package/dist/cjs/utils/ether-to-wei.js +11 -10
- package/dist/cjs/utils/gwei-to-ether.js +11 -10
- package/dist/cjs/utils/hash-message.js +16 -11
- package/dist/cjs/utils/is-address.js +12 -8
- package/dist/cjs/utils/keccak256.js +14 -8
- package/dist/cjs/utils/solidity-keccak256.js +60 -49
- package/dist/cjs/utils/split-signature.js +73 -55
- package/dist/cjs/utils/to-checksum-address.js +20 -15
- package/dist/cjs/utils/to-utf8-bytes.js +6 -1
- package/dist/cjs/utils/wei-to-ether.js +15 -13
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
- package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
- package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
- package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
- package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
- package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
- package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
- package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
- package/dist/cjs/utils/tests/compute-address.test.js +0 -49
- package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
- package/dist/cjs/utils/tests/hash-message.test.js +0 -32
- package/dist/cjs/utils/tests/is-address.test.js +0 -48
- package/dist/cjs/utils/tests/keccak256.test.js +0 -121
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
- package/dist/cjs/utils/tests/split-signature.test.js +0 -46
- package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
- package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _object_spread(target) {
|
|
15
|
-
for(var i = 1; i < arguments.length; i++){
|
|
16
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
-
var ownKeys = Object.keys(source);
|
|
18
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_define_property(target, key, source[key]);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
import { tinyBig } from "../../shared/tiny-big/tiny-big";
|
|
30
|
-
import { toChecksumAddress } from "../../utils/to-checksum-address";
|
|
31
|
-
import { hexToDecimal } from "./hex-to-decimal";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanTransaction = void 0;
|
|
4
|
+
const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
|
|
5
|
+
const to_checksum_address_1 = require("../../utils/to-checksum-address");
|
|
6
|
+
const hex_to_decimal_1 = require("./hex-to-decimal");
|
|
32
7
|
/**
|
|
33
8
|
* Converts RPC transaction response to more JS-friendly format
|
|
34
9
|
*
|
|
@@ -40,35 +15,38 @@ import { hexToDecimal } from "./hex-to-decimal";
|
|
|
40
15
|
* cleanTransaction(RPCTransaction);
|
|
41
16
|
* // { accessList: [], blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, chainId: 1, from: '0x642824FaB1D0141073ed74326332950bEc4701e3', gas: Big { s: 1, e: 5, c: [ 1, 6, 0, 9, 5, 1 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, gasPrice: Big { s: 1, e: 10, c: [ 2, 6, 5, 4, 0, 6, 2, 3, 4, 0, 4 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, hash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', input: '0xa0712d68000000000000000000000000000000000000000000000000000000000000000a', maxFeePerGas: Big { s: 1, e: 10, c: [ 4, 0, 9, 3, 6, 9, 8, 9, 6, 8 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, maxPriorityFeePerGas: Big { s: 1, e: 9, c: [ 1 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, nonce: 66, r: '0x304682f8b22006dd1347c3722f6e43a5ad8e3a1ae51939cc0d6f07981602f5c0', s: '0x207ad110eb5c014cb628814b92396785fabfbe74542293300eeadf156f50f105', to: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', transactionIndex: 41, type: 2, v: 1, value: Big { s: 1, e: 16, c: [ 2 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, confirmations: 53 }
|
|
42
17
|
* ```
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
Object.
|
|
18
|
+
*/
|
|
19
|
+
function cleanTransaction(transaction) {
|
|
20
|
+
const cleanedTransaction = Object.assign({}, transaction);
|
|
21
|
+
Object.keys(transaction).forEach((key) => {
|
|
46
22
|
// pending blocks have null instead of a difficulty
|
|
47
23
|
// pending blocks have null instead of a miner address
|
|
48
|
-
if (!transaction[key])
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
case
|
|
52
|
-
case
|
|
53
|
-
case
|
|
54
|
-
case
|
|
55
|
-
|
|
24
|
+
if (!transaction[key])
|
|
25
|
+
return;
|
|
26
|
+
switch (key) {
|
|
27
|
+
case 'blockNumber':
|
|
28
|
+
case 'chainId':
|
|
29
|
+
case 'transactionIndex':
|
|
30
|
+
case 'type':
|
|
31
|
+
case 'v':
|
|
32
|
+
cleanedTransaction[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
|
|
56
33
|
break;
|
|
57
|
-
case
|
|
58
|
-
case
|
|
34
|
+
case 'from':
|
|
35
|
+
case 'to':
|
|
59
36
|
if (transaction[key]) {
|
|
60
|
-
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
37
|
+
cleanedTransaction[key] = (0, to_checksum_address_1.toChecksumAddress)(transaction[key]);
|
|
61
38
|
}
|
|
62
39
|
break;
|
|
63
|
-
case
|
|
64
|
-
case
|
|
65
|
-
case
|
|
66
|
-
case
|
|
67
|
-
case
|
|
68
|
-
case
|
|
69
|
-
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
40
|
+
case 'value':
|
|
41
|
+
case 'gas':
|
|
42
|
+
case 'gasPrice':
|
|
43
|
+
case 'maxFeePerGas':
|
|
44
|
+
case 'maxPriorityFeePerGas':
|
|
45
|
+
case 'nonce':
|
|
46
|
+
cleanedTransaction[key] = (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
|
|
70
47
|
break;
|
|
71
48
|
}
|
|
72
49
|
});
|
|
73
50
|
return cleanedTransaction;
|
|
74
51
|
}
|
|
52
|
+
exports.cleanTransaction = cleanTransaction;
|
|
@@ -1,73 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
-
if (_i == null) return;
|
|
12
|
-
var _arr = [];
|
|
13
|
-
var _n = true;
|
|
14
|
-
var _d = false;
|
|
15
|
-
var _s, _e;
|
|
16
|
-
try {
|
|
17
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
18
|
-
_arr.push(_s.value);
|
|
19
|
-
if (i && _arr.length === i) break;
|
|
20
|
-
}
|
|
21
|
-
} catch (err) {
|
|
22
|
-
_d = true;
|
|
23
|
-
_e = err;
|
|
24
|
-
} finally{
|
|
25
|
-
try {
|
|
26
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
27
|
-
} finally{
|
|
28
|
-
if (_d) throw _e;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return _arr;
|
|
32
|
-
}
|
|
33
|
-
function _non_iterable_rest() {
|
|
34
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
35
|
-
}
|
|
36
|
-
function _sliced_to_array(arr, i) {
|
|
37
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
38
|
-
}
|
|
39
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
40
|
-
if (!o) return;
|
|
41
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
42
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
43
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
44
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
46
|
-
}
|
|
47
|
-
import { Keccak } from "sha3";
|
|
48
|
-
import { tinyBig } from "../../shared/tiny-big/tiny-big";
|
|
49
|
-
import { toChecksumAddress } from "../../utils/to-checksum-address";
|
|
50
|
-
import { hexToDecimal } from "./hex-to-decimal";
|
|
51
|
-
export var hexFalse = "0".repeat(64);
|
|
52
|
-
var hexTrue = "0".repeat(63) + "1";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeRPCResponse = exports.encodeData = exports.hexFalse = void 0;
|
|
4
|
+
const sha3_1 = require("sha3");
|
|
5
|
+
const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
|
|
6
|
+
const to_checksum_address_1 = require("../../utils/to-checksum-address");
|
|
7
|
+
const hex_to_decimal_1 = require("./hex-to-decimal");
|
|
8
|
+
exports.hexFalse = '0'.repeat(64);
|
|
9
|
+
const hexTrue = '0'.repeat(63) + '1';
|
|
53
10
|
/**
|
|
54
11
|
* @param hex
|
|
55
12
|
* @example
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
13
|
+
*/
|
|
14
|
+
function hexToUtf8(hex) {
|
|
15
|
+
let str = '';
|
|
16
|
+
let i = 0;
|
|
17
|
+
const l = hex.length;
|
|
18
|
+
if (hex.substring(0, 2) === '0x') {
|
|
61
19
|
i = 2;
|
|
62
20
|
}
|
|
63
|
-
for(; i < l; i += 2){
|
|
64
|
-
|
|
65
|
-
if (code === 0)
|
|
21
|
+
for (; i < l; i += 2) {
|
|
22
|
+
const code = parseInt(hex.substr(i, 2), 16);
|
|
23
|
+
if (code === 0)
|
|
24
|
+
continue; // Skip null bytes
|
|
66
25
|
str += String.fromCharCode(code);
|
|
67
26
|
}
|
|
68
27
|
try {
|
|
69
28
|
return decodeURIComponent(escape(str)); // Convert UTF-8 to Unicode
|
|
70
|
-
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
71
31
|
return str; // Return original string if conversion fails
|
|
72
32
|
}
|
|
73
33
|
}
|
|
@@ -82,12 +42,14 @@ var hexTrue = "0".repeat(63) + "1";
|
|
|
82
42
|
* expandType('uint[]');
|
|
83
43
|
* // 'uint256[]'
|
|
84
44
|
* ```
|
|
85
|
-
*/
|
|
45
|
+
*/
|
|
46
|
+
function expandType(type) {
|
|
86
47
|
// https://docs.soliditylang.org/en/v0.8.7/types.html#integers
|
|
87
|
-
if (type ===
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
48
|
+
if (type === 'uint[]') {
|
|
49
|
+
return 'uint256[]';
|
|
50
|
+
}
|
|
51
|
+
else if (type === 'int[]') {
|
|
52
|
+
return 'int256[]';
|
|
91
53
|
}
|
|
92
54
|
return type;
|
|
93
55
|
}
|
|
@@ -96,123 +58,120 @@ var hexTrue = "0".repeat(63) + "1";
|
|
|
96
58
|
* @param jsonABIArgument
|
|
97
59
|
* @param args
|
|
98
60
|
* @example
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
})
|
|
61
|
+
*/
|
|
62
|
+
function encodeData(jsonABIArgument, args) {
|
|
63
|
+
const hash = new sha3_1.Keccak(256);
|
|
64
|
+
/* first 4 bytes will create the data parameter */
|
|
65
|
+
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
|
|
104
66
|
// encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
|
|
105
|
-
|
|
67
|
+
const functionHash = hash.update(functionString).digest('hex');
|
|
106
68
|
// no arrays
|
|
107
|
-
|
|
108
|
-
|
|
69
|
+
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
70
|
+
let shouldValidateInputLength = true;
|
|
109
71
|
// inputs contains 1 or more arrays
|
|
110
|
-
if (jsonABIArgument.inputs.find(
|
|
111
|
-
return input.type.includes("[");
|
|
112
|
-
})) {
|
|
72
|
+
if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
|
|
113
73
|
shouldValidateInputLength = false;
|
|
114
74
|
}
|
|
115
75
|
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
116
|
-
throw new Error(
|
|
76
|
+
throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
|
|
117
77
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
78
|
+
const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
|
|
79
|
+
var _a;
|
|
80
|
+
if (input.type.includes('[')) {
|
|
121
81
|
// strip array and length like "[2]" from type
|
|
122
|
-
|
|
123
|
-
args.forEach(
|
|
124
|
-
acc = acc.concat([
|
|
125
|
-
[
|
|
126
|
-
arg,
|
|
127
|
-
basicType
|
|
128
|
-
]
|
|
129
|
-
]);
|
|
82
|
+
const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
|
|
83
|
+
args.forEach((arg) => {
|
|
84
|
+
acc = acc.concat([[arg, basicType]]);
|
|
130
85
|
});
|
|
131
86
|
return acc;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
args[i],
|
|
136
|
-
input.type
|
|
137
|
-
]
|
|
138
|
-
]);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return acc.concat([[args[i], input.type]]);
|
|
139
90
|
}
|
|
140
91
|
}, []);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
case "address":
|
|
92
|
+
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
93
|
+
let rawArg = arg;
|
|
94
|
+
switch (inputType) {
|
|
95
|
+
case 'bool':
|
|
96
|
+
return arg ? hexTrue : exports.hexFalse;
|
|
97
|
+
case 'address':
|
|
148
98
|
// remove leading "0x"
|
|
149
|
-
rawArg = arg.replace(/^0x/g,
|
|
99
|
+
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
150
100
|
break;
|
|
151
101
|
default:
|
|
152
|
-
if (inputType.startsWith(
|
|
102
|
+
if (inputType.startsWith('bytes')) {
|
|
153
103
|
// encode each character to hex
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
104
|
+
const argEncoded = rawArg
|
|
105
|
+
.split('')
|
|
106
|
+
.map((character) => character.charCodeAt(0).toString(16))
|
|
107
|
+
.join('');
|
|
108
|
+
const paddedEncodedArg = argEncoded.padEnd(64, '0');
|
|
158
109
|
return paddedEncodedArg;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
110
|
+
}
|
|
111
|
+
else if (inputType === 'uint256') {
|
|
112
|
+
const argEncoded = BigInt(arg).toString(16);
|
|
113
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
114
|
+
return paddedEncodedArg;
|
|
115
|
+
}
|
|
116
|
+
else if (inputType.startsWith('uint')) {
|
|
164
117
|
break;
|
|
165
|
-
}
|
|
166
|
-
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
|
|
167
121
|
}
|
|
168
122
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return
|
|
123
|
+
const argEncoded = rawArg.toString(16);
|
|
124
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
125
|
+
return paddedEncodedArg;
|
|
172
126
|
});
|
|
173
|
-
|
|
174
|
-
|
|
127
|
+
const functionEncoded = functionHash.slice(0, 8);
|
|
128
|
+
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
175
129
|
return data;
|
|
176
130
|
}
|
|
131
|
+
exports.encodeData = encodeData;
|
|
177
132
|
/**
|
|
178
133
|
* @internal
|
|
179
134
|
* @param jsonABIArgument
|
|
180
135
|
* @param nodeResponse
|
|
181
136
|
* @example
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
137
|
+
*/
|
|
138
|
+
function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
139
|
+
var _a;
|
|
140
|
+
const rawOutputs = jsonABIArgument.outputs;
|
|
141
|
+
const slicedResponse = nodeResponse.slice(2);
|
|
142
|
+
if (((_a = jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : jsonABIArgument.outputs) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
143
|
+
jsonABIArgument.outputs[0].type === 'string') {
|
|
144
|
+
const [hexOffset, responseData] = [
|
|
188
145
|
slicedResponse.slice(0, 64),
|
|
189
|
-
slicedResponse.slice(64)
|
|
190
|
-
]
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
146
|
+
slicedResponse.slice(64),
|
|
147
|
+
];
|
|
148
|
+
const decimalOffset = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexOffset}`));
|
|
149
|
+
const hexLength = responseData.slice(0, decimalOffset * 2);
|
|
150
|
+
const decimalLength = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexLength}`));
|
|
151
|
+
const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
|
|
195
152
|
return hexToUtf8(hexToDecode);
|
|
196
153
|
}
|
|
197
154
|
// chunk response every 64 characters
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
switch(outputType){
|
|
202
|
-
case
|
|
155
|
+
const encodedOutputs = slicedResponse.match(/.{1,64}/g);
|
|
156
|
+
const outputs = (encodedOutputs || []).map((output, i) => {
|
|
157
|
+
const outputType = (rawOutputs || [])[i].type;
|
|
158
|
+
switch (outputType) {
|
|
159
|
+
case 'bool':
|
|
203
160
|
return output === hexTrue;
|
|
204
|
-
case
|
|
205
|
-
/* address types have 24 leading zeroes to remove */
|
|
206
|
-
|
|
207
|
-
case
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
161
|
+
case 'address':
|
|
162
|
+
/* address types have 24 leading zeroes to remove */
|
|
163
|
+
return (0, to_checksum_address_1.toChecksumAddress)(`0x${output.slice(24)}`);
|
|
164
|
+
case 'uint256':
|
|
165
|
+
case 'uint120':
|
|
166
|
+
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
|
|
167
|
+
case 'bytes32':
|
|
168
|
+
return `0x${output}`;
|
|
169
|
+
case 'uint8':
|
|
170
|
+
return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
|
|
213
171
|
default:
|
|
214
|
-
throw new Error(
|
|
172
|
+
throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
|
|
215
173
|
}
|
|
216
174
|
});
|
|
217
175
|
return outputs.length === 1 ? outputs[0] : outputs;
|
|
218
176
|
}
|
|
177
|
+
exports.decodeRPCResponse = decodeRPCResponse;
|