essential-eth 0.9.1-next.0 → 0.9.1-next.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.
Files changed (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,34 +1,9 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
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
- */ export function cleanTransaction(transaction) {
44
- var cleanedTransaction = _object_spread({}, transaction);
45
- Object.keys(transaction).forEach(function(key) {
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]) return;
49
- switch(key){
50
- case "blockNumber":
51
- case "chainId":
52
- case "transactionIndex":
53
- case "type":
54
- case "v":
55
- cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
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 "from":
58
- case "to":
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 "value":
64
- case "gas":
65
- case "gasPrice":
66
- case "maxFeePerGas":
67
- case "maxPriorityFeePerGas":
68
- case "nonce":
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
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _iterable_to_array_limit(arr, i) {
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
- */ function hexToUtf8(hex) {
57
- var str = "";
58
- var i = 0;
59
- var l = hex.length;
60
- if (hex.substring(0, 2) === "0x") {
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
- var code = parseInt(hex.substr(i, 2), 16);
65
- if (code === 0) continue; // Skip null bytes
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
- } catch (e) {
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
- */ function expandType(type) {
45
+ */
46
+ function expandType(type) {
86
47
  // https://docs.soliditylang.org/en/v0.8.7/types.html#integers
87
- if (type === "uint[]") {
88
- return "uint256[]";
89
- } else if (type === "int[]") {
90
- return "int256[]";
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
- */ export function encodeData(jsonABIArgument, args) {
100
- var hash = new Keccak(256);
101
- /* first 4 bytes will create the data parameter */ var functionString = "".concat(jsonABIArgument.name, "(").concat(jsonABIArgument.inputs.map(function(input) {
102
- return expandType(input.type);
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
- var functionHash = hash.update(functionString).digest("hex");
67
+ const functionHash = hash.update(functionString).digest('hex');
106
68
  // no arrays
107
- var jsonABIInputsLength = jsonABIArgument.inputs.length;
108
- var shouldValidateInputLength = true;
69
+ const jsonABIInputsLength = jsonABIArgument.inputs.length;
70
+ let shouldValidateInputLength = true;
109
71
  // inputs contains 1 or more arrays
110
- if (jsonABIArgument.inputs.find(function(input) {
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('args inputs of "'.concat(args.length, '" does not match expected length of "').concat(jsonABIArgument.inputs.length, '"'));
76
+ throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
117
77
  }
118
- var argsWithTypes = (jsonABIArgument.inputs || []).reduce(function(acc, input, i) {
119
- if (input.type.includes("[")) {
120
- var _exec;
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
- var basicType = (_exec = /([^[]*)\[.*$/g.exec(input.type)) === null || _exec === void 0 ? void 0 : _exec[1];
123
- args.forEach(function(arg) {
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
- } else {
133
- return acc.concat([
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
- var encodedArgs = argsWithTypes.map(function(param) {
142
- var _param = _sliced_to_array(param, 2), arg = _param[0], inputType = _param[1];
143
- var rawArg = arg;
144
- switch(inputType){
145
- case "bool":
146
- return arg ? hexTrue : hexFalse;
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, "").toLowerCase();
99
+ rawArg = arg.replace(/^0x/g, '').toLowerCase();
150
100
  break;
151
101
  default:
152
- if (inputType.startsWith("bytes")) {
102
+ if (inputType.startsWith('bytes')) {
153
103
  // encode each character to hex
154
- var argEncoded = rawArg.split("").map(function(character) {
155
- return character.charCodeAt(0).toString(16);
156
- }).join("");
157
- var paddedEncodedArg = argEncoded.padEnd(64, "0");
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
- } else if (inputType === "uint256") {
160
- var argEncoded1 = BigInt(arg).toString(16);
161
- var paddedEncodedArg1 = argEncoded1.padStart(64, "0");
162
- return paddedEncodedArg1;
163
- } else if (inputType.startsWith("uint")) {
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
- } else {
166
- throw new Error('essential-eth does not yet support "'.concat(inputType, '" inputs. Make a PR today!"'));
118
+ }
119
+ else {
120
+ throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
167
121
  }
168
122
  }
169
- var argEncoded2 = rawArg.toString(16);
170
- var paddedEncodedArg2 = argEncoded2.padStart(64, "0");
171
- return paddedEncodedArg2;
123
+ const argEncoded = rawArg.toString(16);
124
+ const paddedEncodedArg = argEncoded.padStart(64, '0');
125
+ return paddedEncodedArg;
172
126
  });
173
- var functionEncoded = functionHash.slice(0, 8);
174
- var data = "0x".concat(functionEncoded).concat(encodedArgs.join(""));
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
- */ export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
183
- var _jsonABIArgument_outputs;
184
- var rawOutputs = jsonABIArgument.outputs;
185
- var slicedResponse = nodeResponse.slice(2);
186
- if ((jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : (_jsonABIArgument_outputs = jsonABIArgument.outputs) === null || _jsonABIArgument_outputs === void 0 ? void 0 : _jsonABIArgument_outputs.length) === 1 && jsonABIArgument.outputs[0].type === "string") {
187
- var _ref = [
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
- ], hexOffset = _ref[0], responseData = _ref[1];
191
- var decimalOffset = Number(hexToDecimal("0x".concat(hexOffset)));
192
- var hexLength = responseData.slice(0, decimalOffset * 2);
193
- var decimalLength = Number(hexToDecimal("0x".concat(hexLength)));
194
- var hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
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
- var encodedOutputs = slicedResponse.match(/.{1,64}/g);
199
- var outputs = (encodedOutputs || []).map(function(output, i) {
200
- var outputType = (rawOutputs || [])[i].type;
201
- switch(outputType){
202
- case "bool":
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 "address":
205
- /* address types have 24 leading zeroes to remove */ return toChecksumAddress("0x".concat(output.slice(24)));
206
- case "uint256":
207
- case "uint120":
208
- return tinyBig(hexToDecimal("0x".concat(output)));
209
- case "bytes32":
210
- return "0x".concat(output);
211
- case "uint8":
212
- return Number(hexToDecimal("0x".concat(output)));
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('essential-eth does not yet support "'.concat(outputType, '" outputs. Make a PR today!"'));
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;