essential-eth 0.6.2 → 0.7.0

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 (111) hide show
  1. package/dist/cjs/classes/Contract.js +307 -66
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
  3. package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
  4. package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
  5. package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
  6. package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
  7. package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
  8. package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
  9. package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
  10. package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
  11. package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
  12. package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
  13. package/dist/cjs/classes/utils/clean-block.js +52 -30
  14. package/dist/cjs/classes/utils/clean-log.js +42 -20
  15. package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
  16. package/dist/cjs/classes/utils/clean-transaction.js +52 -29
  17. package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
  18. package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
  19. package/dist/cjs/classes/utils/fetchers.js +165 -41
  20. package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
  21. package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
  22. package/dist/cjs/index.js +25 -54
  23. package/dist/cjs/index.umd.js +1 -1
  24. package/dist/cjs/index.umd.js.map +1 -1
  25. package/dist/cjs/logger/logger.js +79 -23
  26. package/dist/cjs/logger/package-version.d.ts +1 -1
  27. package/dist/cjs/logger/package-version.js +1 -4
  28. package/dist/cjs/providers/BaseProvider.js +824 -475
  29. package/dist/cjs/providers/FallthroughProvider.js +118 -37
  30. package/dist/cjs/providers/JsonRpcProvider.js +93 -28
  31. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
  32. package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
  33. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
  34. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
  35. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
  36. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
  37. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
  38. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
  41. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
  42. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
  43. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
  44. package/dist/cjs/providers/test/rpc-urls.js +9 -12
  45. package/dist/cjs/providers/utils/chains-info.js +1 -3
  46. package/dist/cjs/shared/tiny-big/helpers.js +93 -42
  47. package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
  48. package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
  49. package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
  50. package/dist/cjs/shared/validate-type.js +7 -7
  51. package/dist/cjs/types/Block.types.js +1 -2
  52. package/dist/cjs/types/Contract.types.js +1 -2
  53. package/dist/cjs/types/Filter.types.js +1 -2
  54. package/dist/cjs/types/Network.types.js +3 -2
  55. package/dist/cjs/types/Transaction.types.js +1 -2
  56. package/dist/cjs/utils/bytes.js +286 -318
  57. package/dist/cjs/utils/compute-address.js +8 -14
  58. package/dist/cjs/utils/compute-public-key.js +5 -10
  59. package/dist/cjs/utils/ether-to-gwei.js +10 -11
  60. package/dist/cjs/utils/ether-to-wei.js +10 -11
  61. package/dist/cjs/utils/gwei-to-ether.js +10 -11
  62. package/dist/cjs/utils/hash-message.d.ts +1 -1
  63. package/dist/cjs/utils/hash-message.js +11 -14
  64. package/dist/cjs/utils/is-address.js +8 -12
  65. package/dist/cjs/utils/keccak256.js +8 -14
  66. package/dist/cjs/utils/solidity-keccak256.js +49 -60
  67. package/dist/cjs/utils/split-signature.js +55 -73
  68. package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
  69. package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
  70. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
  71. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
  72. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
  73. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
  74. package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
  75. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
  76. package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
  77. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
  78. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
  79. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
  80. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
  81. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
  82. package/dist/cjs/utils/tests/compute-address.test.js +27 -0
  83. package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
  84. package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
  85. package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
  86. package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
  87. package/dist/cjs/utils/tests/hash-message.test.js +21 -0
  88. package/dist/cjs/utils/tests/is-address.test.js +55 -0
  89. package/dist/cjs/utils/tests/keccak256.test.js +97 -0
  90. package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
  91. package/dist/cjs/utils/tests/split-signature.test.js +25 -0
  92. package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
  93. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
  94. package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
  95. package/dist/cjs/utils/to-checksum-address.js +15 -20
  96. package/dist/cjs/utils/to-utf8-bytes.js +1 -6
  97. package/dist/cjs/utils/wei-to-ether.js +13 -15
  98. package/dist/esm/classes/utils/clean-block.d.ts +1 -2
  99. package/dist/esm/classes/utils/clean-block.js +1 -1
  100. package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
  101. package/dist/esm/classes/utils/clean-transaction.js +2 -1
  102. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
  103. package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
  104. package/dist/esm/logger/package-version.d.ts +1 -1
  105. package/dist/esm/logger/package-version.js +1 -1
  106. package/dist/esm/utils/compute-address.js +2 -1
  107. package/dist/esm/utils/hash-message.d.ts +1 -1
  108. package/dist/esm/utils/hash-message.js +3 -1
  109. package/dist/esm/utils/is-address.js +1 -1
  110. package/package.json +8 -6
  111. package/readme.md +34 -3
@@ -1,32 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanLog = void 0;
4
- const to_checksum_address_1 = require("../../utils/to-checksum-address");
5
- const hex_to_decimal_1 = require("./hex-to-decimal");
1
+ function _defineProperty(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 _objectSpread(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
+ _defineProperty(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ import { toChecksumAddress } from "../../utils/to-checksum-address";
30
+ import { hexToDecimal } from "./hex-to-decimal";
6
31
  /**
7
32
  * Converts RPC log receipt response to more JS-friendly format
8
33
  *
9
34
  * @param log the log to clean
10
35
  * @param receiptLog if the log is part of a transaction receipt. Used to remove certain keys from log
11
36
  * @example
12
- */
13
- function cleanLog(log, receiptLog) {
14
- const cleanedLog = Object.assign({}, log);
15
- Object.keys(log).forEach((key) => {
16
- switch (key) {
17
- case 'address':
18
- cleanedLog[key] = (0, to_checksum_address_1.toChecksumAddress)(log[key]);
37
+ */ export function cleanLog(log, receiptLog) {
38
+ var cleanedLog = _objectSpread({}, log);
39
+ Object.keys(log).forEach(function(key) {
40
+ switch(key){
41
+ case "address":
42
+ cleanedLog[key] = toChecksumAddress(log[key]);
19
43
  break;
20
- case 'blockNumber':
21
- case 'logIndex':
22
- case 'transactionIndex':
23
- cleanedLog[key] = Number((0, hex_to_decimal_1.hexToDecimal)(log[key]));
44
+ case "blockNumber":
45
+ case "logIndex":
46
+ case "transactionIndex":
47
+ cleanedLog[key] = Number(hexToDecimal(log[key]));
24
48
  break;
25
- case 'removed':
49
+ case "removed":
26
50
  if (receiptLog) {
27
51
  delete cleanedLog[key];
28
- }
29
- else if (log[key] == null) {
52
+ } else if (log[key] == null) {
30
53
  cleanedLog[key] === false;
31
54
  }
32
55
  break;
@@ -34,4 +57,3 @@ function cleanLog(log, receiptLog) {
34
57
  });
35
58
  return cleanedLog;
36
59
  }
37
- exports.cleanLog = cleanLog;
@@ -1,10 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanTransactionReceipt = void 0;
4
- const __1 = require("../..");
5
- const clean_log_1 = require("./clean-log");
6
- const clean_transaction_1 = require("./clean-transaction");
7
- const hex_to_decimal_1 = require("./hex-to-decimal");
1
+ function _defineProperty(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 _objectSpread(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
+ _defineProperty(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 { cleanLog } from "./clean-log";
32
+ import { cleanTransaction } from "./clean-transaction";
33
+ import { hexToDecimal } from "./hex-to-decimal";
8
34
  /**
9
35
  * Converts RPC transaction receipt response to more JS-friendly format
10
36
  *
@@ -16,35 +42,31 @@ const hex_to_decimal_1 = require("./hex-to-decimal");
16
42
  * cleanTransactionReceipt(RPCTransactionReceipt);
17
43
  * // { blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, contractAddress: null, cumulativeGasUsed: Big { s: 1, e: 6, c: [ 3, 6, 4, 6, 1, 3, 7 ], 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: [λ] }, effectiveGasPrice: 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: [λ] }, from: '0x642824FaB1D0141073ed74326332950bEc4701e3', gasUsed: Big { s: 1, e: 5, c: [ 1, 0, 7, 3, 0, 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: [λ] }, logs: [ { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 84, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x000000000000000000000000000000000000000000000000000000000000074d' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 85, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x000000000000000000000000000000000000000000000000000000000000074e' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 86, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x000000000000000000000000000000000000000000000000000000000000074f' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 87, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000750' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 88, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000751' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 89, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000752' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 90, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000753' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 91, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000754' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 92, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000755' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 }, { address: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, data: '0x', logIndex: 93, topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000642824fab1d0141073ed74326332950bec4701e3', '0x0000000000000000000000000000000000000000000000000000000000000756' ], transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41 } ], logsBloom: '0x20000080004000000000000400000000000001000000000400000000000000000000000000000000000000000008000000000000000000000000000000004000000000000008000000000008000000010080000014000004000000000000000000100000020800000000000000001800000080000000002000000010000000000000000000000200000200000000002000000000000400000000000000000000000000000000000000000040000000000000000100000000000000000000040002100002000000000000080000000000000100000002000000040000001220000000000000000000000000000000000000000000000000000000000000004000', status: 1, to: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: 41, type: 2, byzantium: true, confirmations: 40 }
18
44
  * ```
19
- */
20
- function cleanTransactionReceipt(transactionReceipt) {
21
- const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(transactionReceipt);
22
- const cleanedTransactionReceipt = Object.assign({}, cleanedTransaction);
23
- Object.keys(transactionReceipt).forEach((key) => {
24
- if (!transactionReceipt[key])
25
- return;
26
- switch (key) {
27
- case 'status':
28
- cleanedTransactionReceipt[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
45
+ */ export function cleanTransactionReceipt(transactionReceipt) {
46
+ var cleanedTransaction = cleanTransaction(transactionReceipt);
47
+ var cleanedTransactionReceipt = _objectSpread({}, cleanedTransaction);
48
+ Object.keys(transactionReceipt).forEach(function(key) {
49
+ if (!transactionReceipt[key]) return;
50
+ switch(key){
51
+ case "status":
52
+ cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
29
53
  break;
30
- case 'contractAddress':
54
+ case "contractAddress":
31
55
  if (transactionReceipt[key]) {
32
- cleanedTransactionReceipt[key] = (0, __1.toChecksumAddress)(transactionReceipt[key]);
56
+ cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
33
57
  }
34
58
  break;
35
- case 'cumulativeGasUsed':
36
- case 'effectiveGasPrice':
37
- case 'gasUsed':
38
- cleanedTransactionReceipt[key] = (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
59
+ case "cumulativeGasUsed":
60
+ case "effectiveGasPrice":
61
+ case "gasUsed":
62
+ cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
39
63
  break;
40
- case 'logs':
41
- transactionReceipt[key].forEach((log, index) => {
42
- cleanedTransactionReceipt[key][index] = (0, clean_log_1.cleanLog)(log, true);
64
+ case "logs":
65
+ transactionReceipt[key].forEach(function(log, index) {
66
+ cleanedTransactionReceipt[key][index] = cleanLog(log, true);
43
67
  });
44
68
  }
45
69
  });
46
- cleanedTransactionReceipt.byzantium =
47
- cleanedTransactionReceipt.blockNumber >= 4370000;
70
+ cleanedTransactionReceipt.byzantium = cleanedTransactionReceipt.blockNumber >= 4370000;
48
71
  return cleanedTransactionReceipt;
49
72
  }
50
- exports.cleanTransactionReceipt = cleanTransactionReceipt;
@@ -1,8 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanTransaction = void 0;
4
- const __1 = require("../..");
5
- const hex_to_decimal_1 = require("./hex-to-decimal");
1
+ function _defineProperty(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 _objectSpread(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
+ _defineProperty(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";
6
32
  /**
7
33
  * Converts RPC transaction response to more JS-friendly format
8
34
  *
@@ -14,38 +40,35 @@ const hex_to_decimal_1 = require("./hex-to-decimal");
14
40
  * cleanTransaction(RPCTransaction);
15
41
  * // { 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 }
16
42
  * ```
17
- */
18
- function cleanTransaction(transaction) {
19
- const cleanedTransaction = Object.assign({}, transaction);
20
- Object.keys(transaction).forEach((key) => {
43
+ */ export function cleanTransaction(transaction) {
44
+ var cleanedTransaction = _objectSpread({}, transaction);
45
+ Object.keys(transaction).forEach(function(key) {
21
46
  // pending blocks have null instead of a difficulty
22
47
  // pending blocks have null instead of a miner address
23
- if (!transaction[key])
24
- return;
25
- switch (key) {
26
- case 'blockNumber':
27
- case 'chainId':
28
- case 'transactionIndex':
29
- case 'type':
30
- case 'v':
31
- cleanedTransaction[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
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]));
32
56
  break;
33
- case 'from':
34
- case 'to':
57
+ case "from":
58
+ case "to":
35
59
  if (transaction[key]) {
36
- cleanedTransaction[key] = (0, __1.toChecksumAddress)(transaction[key]);
60
+ cleanedTransaction[key] = toChecksumAddress(transaction[key]);
37
61
  }
38
62
  break;
39
- case 'value':
40
- case 'gas':
41
- case 'gasPrice':
42
- case 'maxFeePerGas':
43
- case 'maxPriorityFeePerGas':
44
- case 'nonce':
45
- cleanedTransaction[key] = (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
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]));
46
70
  break;
47
71
  }
48
72
  });
49
73
  return cleanedTransaction;
50
74
  }
51
- exports.cleanTransaction = cleanTransaction;
@@ -1,4 +1,4 @@
1
1
  import type { JSONABIArgument } from '../../types/Contract.types';
2
2
  export declare const hexFalse: string;
3
3
  export declare function encodeData(jsonABIArgument: JSONABIArgument, args: any[]): string;
4
- export declare function decodeRPCResponse(jsonABIArgument: JSONABIArgument, nodeResponse: string): string | number | boolean | import("../..").TinyBig | (string | number | boolean | import("../..").TinyBig)[];
4
+ export declare function decodeRPCResponse(jsonABIArgument: JSONABIArgument, nodeResponse: string): string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig | (string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig)[];
@@ -1,11 +1,76 @@
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 __1 = require("../..");
6
- const hex_to_decimal_1 = require("./hex-to-decimal");
7
- exports.hexFalse = '0'.repeat(64);
8
- const hexTrue = '0'.repeat(63) + '1';
1
+ function _arrayLikeToArray(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 _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterableToArrayLimit(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 _nonIterableRest() {
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 _slicedToArray(arr, i) {
37
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
38
+ }
39
+ function _unsupportedIterableToArray(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _arrayLikeToArray(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 _arrayLikeToArray(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";
53
+ /**
54
+ * @param hex
55
+ * @example
56
+ */ function hexToUtf8(hex) {
57
+ var str = "";
58
+ var i = 0;
59
+ var l = hex.length;
60
+ if (hex.substring(0, 2) === "0x") {
61
+ i = 2;
62
+ }
63
+ for(; i < l; i += 2){
64
+ var code = parseInt(hex.substr(i, 2), 16);
65
+ if (code === 0) continue; // Skip null bytes
66
+ str += String.fromCharCode(code);
67
+ }
68
+ try {
69
+ return decodeURIComponent(escape(str)); // Convert UTF-8 to Unicode
70
+ } catch (e) {
71
+ return str; // Return original string if conversion fails
72
+ }
73
+ }
9
74
  /**
10
75
  * Expands an integer type to use a default of 256 bits. Used for consistency; not required in Solidity
11
76
  *
@@ -17,14 +82,12 @@ const hexTrue = '0'.repeat(63) + '1';
17
82
  * expandType('uint[]');
18
83
  * // 'uint256[]'
19
84
  * ```
20
- */
21
- function expandType(type) {
85
+ */ function expandType(type) {
22
86
  // https://docs.soliditylang.org/en/v0.8.7/types.html#integers
23
- if (type === 'uint[]') {
24
- return 'uint256[]';
25
- }
26
- else if (type === 'int[]') {
27
- return 'int256[]';
87
+ if (type === "uint[]") {
88
+ return "uint256[]";
89
+ } else if (type === "int[]") {
90
+ return "int256[]";
28
91
  }
29
92
  return type;
30
93
  }
@@ -33,106 +96,123 @@ function expandType(type) {
33
96
  * @param jsonABIArgument
34
97
  * @param args
35
98
  * @example
36
- */
37
- function encodeData(jsonABIArgument, args) {
38
- const hash = new sha3_1.Keccak(256);
39
- /* first 4 bytes will create the data parameter */
40
- const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
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
+ }), ")");
41
104
  // encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
42
- const functionHash = hash.update(functionString).digest('hex');
105
+ var functionHash = hash.update(functionString).digest("hex");
43
106
  // no arrays
44
- const jsonABIInputsLength = jsonABIArgument.inputs.length;
45
- let shouldValidateInputLength = true;
107
+ var jsonABIInputsLength = jsonABIArgument.inputs.length;
108
+ var shouldValidateInputLength = true;
46
109
  // inputs contains 1 or more arrays
47
- if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
110
+ if (jsonABIArgument.inputs.find(function(input) {
111
+ return input.type.includes("[");
112
+ })) {
48
113
  shouldValidateInputLength = false;
49
114
  }
50
115
  if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
51
- throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
116
+ throw new Error('args inputs of "'.concat(args.length, '" does not match expected length of "').concat(jsonABIArgument.inputs.length, '"'));
52
117
  }
53
- const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
54
- var _a;
55
- if (input.type.includes('[')) {
118
+ var argsWithTypes = (jsonABIArgument.inputs || []).reduce(function(acc, input, i) {
119
+ if (input.type.includes("[")) {
120
+ var _exec;
56
121
  // strip array and length like "[2]" from type
57
- const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
58
- args.forEach((arg) => {
59
- acc = acc.concat([[arg, basicType]]);
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
+ ]);
60
130
  });
61
131
  return acc;
62
- }
63
- else {
64
- return acc.concat([[args[i], input.type]]);
132
+ } else {
133
+ return acc.concat([
134
+ [
135
+ args[i],
136
+ input.type
137
+ ]
138
+ ]);
65
139
  }
66
140
  }, []);
67
- const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
68
- let rawArg = arg;
69
- switch (inputType) {
70
- case 'bool':
71
- return arg ? hexTrue : exports.hexFalse;
72
- case 'address':
141
+ var encodedArgs = argsWithTypes.map(function(param) {
142
+ var _param = _slicedToArray(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":
73
148
  // remove leading "0x"
74
- rawArg = arg.replace(/^0x/g, '').toLowerCase();
149
+ rawArg = arg.replace(/^0x/g, "").toLowerCase();
75
150
  break;
76
151
  default:
77
- if (inputType.startsWith('bytes')) {
152
+ if (inputType.startsWith("bytes")) {
78
153
  // encode each character to hex
79
- const argEncoded = rawArg
80
- .split('')
81
- .map((character) => character.charCodeAt(0).toString(16))
82
- .join('');
83
- const paddedEncodedArg = argEncoded.padEnd(64, '0');
154
+ var argEncoded = rawArg.split("").map(function(character) {
155
+ return character.charCodeAt(0).toString(16);
156
+ }).join("");
157
+ var paddedEncodedArg = argEncoded.padEnd(64, "0");
84
158
  return paddedEncodedArg;
85
- }
86
- else if (inputType === 'uint256') {
87
- const argEncoded = BigInt(arg).toString(16);
88
- const paddedEncodedArg = argEncoded.padStart(64, '0');
89
- return paddedEncodedArg;
90
- }
91
- else if (inputType.startsWith('uint')) {
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")) {
92
164
  break;
93
- }
94
- else {
95
- throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
165
+ } else {
166
+ throw new Error('essential-eth does not yet support "'.concat(inputType, '" inputs. Make a PR today!"'));
96
167
  }
97
168
  }
98
- const argEncoded = rawArg.toString(16);
99
- const paddedEncodedArg = argEncoded.padStart(64, '0');
100
- return paddedEncodedArg;
169
+ var argEncoded2 = rawArg.toString(16);
170
+ var paddedEncodedArg2 = argEncoded2.padStart(64, "0");
171
+ return paddedEncodedArg2;
101
172
  });
102
- const functionEncoded = functionHash.slice(0, 8);
103
- const data = `0x${functionEncoded}${encodedArgs.join('')}`;
173
+ var functionEncoded = functionHash.slice(0, 8);
174
+ var data = "0x".concat(functionEncoded).concat(encodedArgs.join(""));
104
175
  return data;
105
176
  }
106
- exports.encodeData = encodeData;
107
177
  /**
108
178
  * @internal
109
179
  * @param jsonABIArgument
110
180
  * @param nodeResponse
111
181
  * @example
112
- */
113
- function decodeRPCResponse(jsonABIArgument, nodeResponse) {
114
- const rawOutputs = jsonABIArgument.outputs;
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 = [
188
+ 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);
195
+ return hexToUtf8(hexToDecode);
196
+ }
115
197
  // chunk response every 64 characters
116
- const encodedOutputs = nodeResponse.slice(2).match(/.{1,64}/g);
117
- const outputs = (encodedOutputs || []).map((output, i) => {
118
- const outputType = (rawOutputs || [])[i].type;
119
- switch (outputType) {
120
- case 'bool':
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":
121
203
  return output === hexTrue;
122
- case 'address':
123
- /* address types have 26 leading zeroes to remove */
124
- return (0, __1.toChecksumAddress)(`0x${output.slice(24)}`);
125
- case 'uint256':
126
- case 'uint120':
127
- return (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
128
- case 'bytes32':
129
- return `0x${output}`;
130
- case 'uint8':
131
- return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
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)));
132
213
  default:
133
- throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
214
+ throw new Error('essential-eth does not yet support "'.concat(outputType, '" outputs. Make a PR today!"'));
134
215
  }
135
216
  });
136
217
  return outputs.length === 1 ? outputs[0] : outputs;
137
218
  }
138
- exports.decodeRPCResponse = decodeRPCResponse;