essential-eth 0.9.2-beta.1 → 0.9.2-beta.3

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 (205) hide show
  1. package/dist/cjs/classes/Contract.js +139 -0
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +488 -0
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +453 -0
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +526 -0
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +42 -0
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +121 -0
  7. package/dist/cjs/classes/utils/clean-block.js +160 -0
  8. package/dist/cjs/classes/utils/clean-log.js +39 -0
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +53 -0
  10. package/dist/cjs/classes/utils/clean-transaction.js +54 -0
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +175 -0
  12. package/dist/cjs/classes/utils/fetchers.js +85 -0
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +24 -0
  14. package/dist/cjs/classes/utils/prepare-transaction.js +47 -0
  15. package/dist/cjs/index.d.ts +24 -0
  16. package/dist/cjs/index.js +58 -0
  17. package/dist/cjs/index.umd.js +2 -0
  18. package/dist/cjs/index.umd.js.map +1 -0
  19. package/dist/cjs/logger/logger.js +37 -0
  20. package/dist/cjs/logger/package-version.d.ts +1 -0
  21. package/dist/cjs/logger/package-version.js +5 -0
  22. package/dist/cjs/providers/AlchemyProvider.js +11 -0
  23. package/dist/cjs/providers/BaseProvider.js +514 -0
  24. package/dist/cjs/providers/FallthroughProvider.js +74 -0
  25. package/dist/cjs/providers/JsonRpcProvider.js +46 -0
  26. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +152 -0
  27. package/dist/cjs/providers/test/mock-of.js +12 -0
  28. package/dist/cjs/providers/test/rpc-urls.js +25 -0
  29. package/dist/cjs/providers/utils/chains-info.js +71 -0
  30. package/dist/cjs/shared/tiny-big/helpers.js +97 -0
  31. package/dist/cjs/shared/tiny-big/tiny-big.js +101 -0
  32. package/dist/cjs/shared/validate-type.js +9 -0
  33. package/dist/cjs/types/Block.types.js +2 -0
  34. package/dist/cjs/types/Contract.types.js +2 -0
  35. package/dist/cjs/types/FeeData.types.js +2 -0
  36. package/dist/cjs/types/Filter.types.js +2 -0
  37. package/dist/cjs/types/Network.types.js +2 -0
  38. package/dist/cjs/types/Transaction.types.js +2 -0
  39. package/dist/cjs/utils/bytes.js +711 -0
  40. package/dist/cjs/utils/compute-address.js +34 -0
  41. package/dist/cjs/utils/compute-public-key.js +26 -0
  42. package/dist/cjs/utils/ether-to-gwei.js +35 -0
  43. package/dist/cjs/utils/ether-to-wei.js +35 -0
  44. package/dist/cjs/utils/gwei-to-ether.js +35 -0
  45. package/dist/cjs/utils/hash-message.js +30 -0
  46. package/dist/cjs/utils/is-address.js +39 -0
  47. package/dist/cjs/utils/keccak256.js +31 -0
  48. package/dist/cjs/utils/solidity-keccak256.js +138 -0
  49. package/dist/cjs/utils/split-signature.js +163 -0
  50. package/dist/cjs/utils/to-checksum-address.js +46 -0
  51. package/dist/cjs/utils/to-utf8-bytes.js +21 -0
  52. package/dist/cjs/utils/wei-to-ether.js +45 -0
  53. package/dist/esm/classes/Contract.d.ts +11 -0
  54. package/dist/esm/classes/Contract.js +58 -0
  55. package/dist/esm/classes/test/Contract/crv-abi.d.ts +2 -0
  56. package/dist/esm/classes/test/Contract/crv-abi.js +470 -0
  57. package/dist/esm/classes/test/Contract/ens-abi.d.ts +2 -0
  58. package/dist/esm/classes/test/Contract/ens-abi.js +435 -0
  59. package/dist/esm/classes/test/Contract/fei-abi.d.ts +2 -0
  60. package/dist/esm/classes/test/Contract/fei-abi.js +521 -0
  61. package/dist/esm/classes/test/Contract/foo-abi.d.ts +2 -0
  62. package/dist/esm/classes/test/Contract/foo-abi.js +33 -0
  63. package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
  64. package/dist/esm/classes/test/Contract/uniswap-abi.js +116 -0
  65. package/dist/esm/classes/utils/clean-block.d.ts +2 -0
  66. package/dist/esm/classes/utils/clean-block.js +35 -0
  67. package/dist/esm/classes/utils/clean-log.d.ts +2 -0
  68. package/dist/esm/classes/utils/clean-log.js +28 -0
  69. package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
  70. package/dist/esm/classes/utils/clean-transaction-receipt.js +37 -0
  71. package/dist/esm/classes/utils/clean-transaction.d.ts +2 -0
  72. package/dist/esm/classes/utils/clean-transaction.js +36 -0
  73. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +4 -0
  74. package/dist/esm/classes/utils/encode-decode-transaction.js +132 -0
  75. package/dist/esm/classes/utils/fetchers.d.ts +15 -0
  76. package/dist/esm/classes/utils/fetchers.js +37 -0
  77. package/dist/esm/classes/utils/hex-to-decimal.d.ts +1 -0
  78. package/dist/esm/classes/utils/hex-to-decimal.js +3 -0
  79. package/dist/esm/classes/utils/prepare-transaction.d.ts +2 -0
  80. package/dist/esm/classes/utils/prepare-transaction.js +36 -0
  81. package/dist/{index.d.ts → esm/index.d.ts} +24 -25
  82. package/dist/esm/index.js +19 -0
  83. package/dist/esm/logger/logger.d.ts +11 -0
  84. package/dist/esm/logger/logger.js +34 -0
  85. package/dist/esm/logger/package-version.d.ts +1 -0
  86. package/dist/esm/logger/package-version.js +1 -0
  87. package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
  88. package/dist/esm/providers/AlchemyProvider.js +7 -0
  89. package/dist/esm/providers/BaseProvider.d.ts +26 -0
  90. package/dist/esm/providers/BaseProvider.js +137 -0
  91. package/dist/esm/providers/FallthroughProvider.d.ts +11 -0
  92. package/dist/esm/providers/FallthroughProvider.js +50 -0
  93. package/dist/esm/providers/JsonRpcProvider.d.ts +7 -0
  94. package/dist/esm/providers/JsonRpcProvider.js +15 -0
  95. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  96. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  97. package/dist/esm/providers/test/mock-of.d.ts +2 -0
  98. package/dist/esm/providers/test/mock-of.js +1 -0
  99. package/dist/esm/providers/test/rpc-urls.d.ts +12 -0
  100. package/dist/esm/providers/test/rpc-urls.js +19 -0
  101. package/dist/esm/providers/utils/chains-info.d.ts +24 -0
  102. package/dist/esm/providers/utils/chains-info.js +67 -0
  103. package/dist/esm/shared/tiny-big/helpers.d.ts +1 -0
  104. package/dist/esm/shared/tiny-big/helpers.js +58 -0
  105. package/dist/esm/shared/tiny-big/tiny-big.d.ts +10 -0
  106. package/dist/esm/shared/tiny-big/tiny-big.js +45 -0
  107. package/dist/esm/shared/validate-type.d.ts +3 -0
  108. package/dist/esm/shared/validate-type.js +5 -0
  109. package/dist/esm/types/Block.types.d.ts +40 -0
  110. package/dist/esm/types/Block.types.js +1 -0
  111. package/dist/esm/types/Contract.types.d.ts +24 -0
  112. package/dist/esm/types/Contract.types.js +1 -0
  113. package/dist/esm/types/FeeData.types.d.ts +7 -0
  114. package/dist/esm/types/FeeData.types.js +1 -0
  115. package/dist/esm/types/Filter.types.d.ts +12 -0
  116. package/dist/esm/types/Filter.types.js +1 -0
  117. package/dist/esm/types/Network.types.d.ts +5 -0
  118. package/dist/esm/types/Network.types.js +1 -0
  119. package/dist/esm/types/Transaction.types.d.ts +113 -0
  120. package/dist/esm/types/Transaction.types.js +1 -0
  121. package/dist/esm/utils/bytes.d.ts +40 -0
  122. package/dist/esm/utils/bytes.js +245 -0
  123. package/dist/esm/utils/compute-address.d.ts +1 -0
  124. package/dist/esm/utils/compute-address.js +12 -0
  125. package/dist/esm/utils/compute-public-key.d.ts +2 -0
  126. package/dist/esm/utils/compute-public-key.js +6 -0
  127. package/dist/esm/utils/ether-to-gwei.d.ts +3 -0
  128. package/dist/esm/utils/ether-to-gwei.js +7 -0
  129. package/dist/esm/utils/ether-to-wei.d.ts +3 -0
  130. package/dist/esm/utils/ether-to-wei.js +7 -0
  131. package/dist/esm/utils/gwei-to-ether.d.ts +3 -0
  132. package/dist/esm/utils/gwei-to-ether.js +7 -0
  133. package/dist/esm/utils/hash-message.d.ts +2 -0
  134. package/dist/esm/utils/hash-message.js +14 -0
  135. package/dist/esm/utils/is-address.d.ts +1 -0
  136. package/dist/esm/utils/is-address.js +12 -0
  137. package/dist/esm/utils/keccak256.d.ts +2 -0
  138. package/dist/esm/utils/keccak256.js +13 -0
  139. package/dist/esm/utils/solidity-keccak256.d.ts +2 -0
  140. package/dist/esm/utils/solidity-keccak256.js +85 -0
  141. package/dist/esm/utils/split-signature.d.ts +2 -0
  142. package/dist/esm/utils/split-signature.js +126 -0
  143. package/dist/esm/utils/to-checksum-address.d.ts +1 -0
  144. package/dist/esm/utils/to-checksum-address.js +25 -0
  145. package/dist/esm/utils/to-utf8-bytes.d.ts +1 -0
  146. package/dist/esm/utils/to-utf8-bytes.js +3 -0
  147. package/dist/esm/utils/wei-to-ether.d.ts +3 -0
  148. package/dist/esm/utils/wei-to-ether.js +16 -0
  149. package/package.json +16 -14
  150. package/readme.md +2 -2
  151. package/dist/essential-eth.esm.mjs +0 -2
  152. package/dist/essential-eth.esm.mjs.map +0 -1
  153. package/dist/essential-eth.js +0 -2
  154. package/dist/essential-eth.js.map +0 -1
  155. package/dist/essential-eth.modern.mjs +0 -2
  156. package/dist/essential-eth.modern.mjs.map +0 -1
  157. package/dist/essential-eth.umd.js +0 -2
  158. package/dist/essential-eth.umd.js.map +0 -1
  159. package/dist/logger/package-version.d.ts +0 -1
  160. /package/dist/{classes → cjs/classes}/Contract.d.ts +0 -0
  161. /package/dist/{classes → cjs/classes}/test/Contract/crv-abi.d.ts +0 -0
  162. /package/dist/{classes → cjs/classes}/test/Contract/ens-abi.d.ts +0 -0
  163. /package/dist/{classes → cjs/classes}/test/Contract/fei-abi.d.ts +0 -0
  164. /package/dist/{classes → cjs/classes}/test/Contract/foo-abi.d.ts +0 -0
  165. /package/dist/{classes → cjs/classes}/test/Contract/uniswap-abi.d.ts +0 -0
  166. /package/dist/{classes → cjs/classes}/utils/clean-block.d.ts +0 -0
  167. /package/dist/{classes → cjs/classes}/utils/clean-log.d.ts +0 -0
  168. /package/dist/{classes → cjs/classes}/utils/clean-transaction-receipt.d.ts +0 -0
  169. /package/dist/{classes → cjs/classes}/utils/clean-transaction.d.ts +0 -0
  170. /package/dist/{classes → cjs/classes}/utils/encode-decode-transaction.d.ts +0 -0
  171. /package/dist/{classes → cjs/classes}/utils/fetchers.d.ts +0 -0
  172. /package/dist/{classes → cjs/classes}/utils/hex-to-decimal.d.ts +0 -0
  173. /package/dist/{classes → cjs/classes}/utils/prepare-transaction.d.ts +0 -0
  174. /package/dist/{logger → cjs/logger}/logger.d.ts +0 -0
  175. /package/dist/{providers → cjs/providers}/AlchemyProvider.d.ts +0 -0
  176. /package/dist/{providers → cjs/providers}/BaseProvider.d.ts +0 -0
  177. /package/dist/{providers → cjs/providers}/FallthroughProvider.d.ts +0 -0
  178. /package/dist/{providers → cjs/providers}/JsonRpcProvider.d.ts +0 -0
  179. /package/dist/{providers → cjs/providers}/test/json-rpc-provider/get-logs/mocks.d.ts +0 -0
  180. /package/dist/{providers → cjs/providers}/test/mock-of.d.ts +0 -0
  181. /package/dist/{providers → cjs/providers}/test/rpc-urls.d.ts +0 -0
  182. /package/dist/{providers → cjs/providers}/utils/chains-info.d.ts +0 -0
  183. /package/dist/{shared → cjs/shared}/tiny-big/helpers.d.ts +0 -0
  184. /package/dist/{shared → cjs/shared}/tiny-big/tiny-big.d.ts +0 -0
  185. /package/dist/{shared → cjs/shared}/validate-type.d.ts +0 -0
  186. /package/dist/{types → cjs/types}/Block.types.d.ts +0 -0
  187. /package/dist/{types → cjs/types}/Contract.types.d.ts +0 -0
  188. /package/dist/{types → cjs/types}/FeeData.types.d.ts +0 -0
  189. /package/dist/{types → cjs/types}/Filter.types.d.ts +0 -0
  190. /package/dist/{types → cjs/types}/Network.types.d.ts +0 -0
  191. /package/dist/{types → cjs/types}/Transaction.types.d.ts +0 -0
  192. /package/dist/{utils → cjs/utils}/bytes.d.ts +0 -0
  193. /package/dist/{utils → cjs/utils}/compute-address.d.ts +0 -0
  194. /package/dist/{utils → cjs/utils}/compute-public-key.d.ts +0 -0
  195. /package/dist/{utils → cjs/utils}/ether-to-gwei.d.ts +0 -0
  196. /package/dist/{utils → cjs/utils}/ether-to-wei.d.ts +0 -0
  197. /package/dist/{utils → cjs/utils}/gwei-to-ether.d.ts +0 -0
  198. /package/dist/{utils → cjs/utils}/hash-message.d.ts +0 -0
  199. /package/dist/{utils → cjs/utils}/is-address.d.ts +0 -0
  200. /package/dist/{utils → cjs/utils}/keccak256.d.ts +0 -0
  201. /package/dist/{utils → cjs/utils}/solidity-keccak256.d.ts +0 -0
  202. /package/dist/{utils → cjs/utils}/split-signature.d.ts +0 -0
  203. /package/dist/{utils → cjs/utils}/to-checksum-address.d.ts +0 -0
  204. /package/dist/{utils → cjs/utils}/to-utf8-bytes.d.ts +0 -0
  205. /package/dist/{utils → cjs/utils}/wei-to-ether.d.ts +0 -0
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanBlock = 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 clean_transaction_1 = require("./clean-transaction");
7
+ const hex_to_decimal_1 = require("./hex-to-decimal");
8
+ /**
9
+ * Converts RPC block response to more JS-friendly format
10
+ *
11
+ * @param block the RPCBlock to clean
12
+ * @param returnTransactionObjects whether or not to return the transactions specified in this block
13
+ * @returns a cleaned block
14
+ * @example
15
+ * ```js
16
+ * const rpcBlock = {
17
+ * number: '0x40f9de',
18
+ * hash: '0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970',
19
+ * parentHash: '0xc8de1e513f74cbc5cc77e2a39e4cada6504469a5d0e87200b708319c1e9ef154',
20
+ * sha3Uncles: '0x04d250716296c9662314b37c112e5ce8b1c9ad7fd7820a39482a3688a2078f2b',
21
+ * logsBloom: '0x0000400004000000040010100200000000000000000000000000000000000000001000000001000000000000000000000004010000000000000a800000000000040000000001000400000000000000000000000000000000000002000000000000000000000004000040000000800000000001000000000000000000000000000000000000000001000000000004200000000000000000000000000124400000000000000200100020000000000000000080000000000080001000000000000000000081000000000000000000008000000020000100000000200020100800000000000000000008002000000080001000020c00000000000000200000000000',
22
+ * transactionsRoot: '0xfc79f4f620cb69861ac67ceee5e1ddf3e45da95be230d4064be234f1ee491aa5',
23
+ * stateRoot: '0xfa5ef7e368997d70670b0ea3172aabefc2dee285786ce69c7165d8d854f8b292',
24
+ * receiptsRoot: '0x7fa0679e88fef8a8f7f5865dc4e6000ddcc267b14d2904948e3b1576a18a3bbd',
25
+ * miner: '0x1b7a75ef070ff49e6b9491a26403d799f2099ebd',
26
+ * difficulty: '0x47ede14fcbe635706e',
27
+ * totalDifficulty: '0x139e1de9b8404dedc5d30959',
28
+ * extraData: '0xce018c495249532d62613031656132',
29
+ * size: '0xb4f',
30
+ * gasLimit: '0x67c280',
31
+ * gasUsed: '0x56e2d',
32
+ * timestamp: '0x62648dc2',
33
+ * transactions: [
34
+ * '0xd53800afc69e55cc7a64b927803b46a5b4c5ddccbaafb6b32fe0ec883739b825',
35
+ * '0x4b8b07f35a1f911a80a0ffeebe3d3c41cd393b4d5e1ce0a408026705913d6760',
36
+ * '0xa50eac0ea8005cb1e4b95be4e64c24035d9c41adb164c49477c3169870f02fb1',
37
+ * '0x413e5293786f8b63e73adf0b74ab56067da4b564d01936b88b138d48cc414a42',
38
+ * '0xd4e4969365d144b0b987632dca36ba9e272254bdc687245987a57666d6afa148'
39
+ * ],
40
+ * uncles: [
41
+ * '0x36cd3869fd17a285b984dea8b705d34096e1fbdfe48df69ae530fbe921ba83fa'
42
+ * ],
43
+ * minimumGasPrice: '0x387ee40',
44
+ * bitcoinMergedMiningHeader: '0x0040502d717ae205da048b0ffb8e110603564d8677ca8bd3a54601000000000000000000e722e86bfebcae00bffb46c663fa0241b63a27f0c98fa710e421d5cc1afa2448d08d6462d9f809172f5e30aa',
45
+ * bitcoinMergedMiningCoinbaseTransaction: '0x00000000000001003f8757a906f0159f882f0968788a2e396b7bf8090e1b926fb2bb46789ac32d55082aca4e0800000000000000002b6a2952534b424c4f434b3a831a30935da1bd1e8631942fc7fa78f7a7b11d51ca39a1684d91a81f0040f9de00000000',
46
+ * bitcoinMergedMiningMerkleProof: '0xb53111a4e11bc19bf90268485d1b957d908ebc6a4cd9862aca3fc6ed3dcf3240b14c316de8521369d55dbfeb2b0116bcc10f40e999c4885e1bd2a08691bdea1c43862d590390a227a379d5677b958f1a23eecc16ac590ad675b8a4cea0c10da3ef597acb9ca1fe0a21fc408f09e0c7169d83aca8ddd636d8cc155f922e1d36c74b7cc11e9ee98dd1bf2100a55d59630c65da3db1575d58f165c5753c1779df90efcff9017b73cc32f4c87178bd0eae6a6dd0357047be70d6c4af17fcef097e80a9f1751447f4eee3831fc79f2d894934694149bcb99840a525f5128215eca6b54642af452ee7568a9281f40560afffd35725df31b98155d7813dea12e42f2a8052c7d98bcf62c9cdc66c40fb12b729b685a31aec4970ea5316640691ae5eb616808656a2bde4e9f5920ff178bf9d1f84e96a0d0bd048a3a8ca0d60970d02aacf7ecfb6e7feaec5c4a764873531cfd630e9430840cfe8b88154da25d6b94b706fe678d0efc1ecafed5a1f539e34552bea65622513b663e17e121f3c4548942584',
47
+ * hashForMergedMining: '0x831a30935da1bd1e8631942fc7fa78f7a7b11d51ca39a1684d91a81f0040f9de',
48
+ * paidFees: '0x1fb451615b58',
49
+ * cumulativeDifficulty: '0x8fdbe015f7248cf993'
50
+ * };
51
+ * const returnTransactionObjects = false;
52
+ *
53
+ * await cleanBlock(rpcBlock, returnTransactionObjects);
54
+ * // {
55
+ * // number: 4258270,
56
+ * // hash: '0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970',
57
+ * // parentHash: '0xc8de1e513f74cbc5cc77e2a39e4cada6504469a5d0e87200b708319c1e9ef154',
58
+ * // sha3Uncles: '0x04d250716296c9662314b37c112e5ce8b1c9ad7fd7820a39482a3688a2078f2b',
59
+ * // logsBloom: '0x0000400004000000040010100200000000000000000000000000000000000000001000000001000000000000000000000004010000000000000a800000000000040000000001000400000000000000000000000000000000000002000000000000000000000004000040000000800000000001000000000000000000000000000000000000000001000000000004200000000000000000000000000124400000000000000200100020000000000000000080000000000080001000000000000000000081000000000000000000008000000020000100000000200020100800000000000000000008002000000080001000020c00000000000000200000000000',
60
+ * // transactionsRoot: '0xfc79f4f620cb69861ac67ceee5e1ddf3e45da95be230d4064be234f1ee491aa5',
61
+ * // stateRoot: '0xfa5ef7e368997d70670b0ea3172aabefc2dee285786ce69c7165d8d854f8b292',
62
+ * // receiptsRoot: '0x7fa0679e88fef8a8f7f5865dc4e6000ddcc267b14d2904948e3b1576a18a3bbd',
63
+ * // miner: '0x1b7A75Ef070Ff49E6B9491a26403D799f2099EbD',
64
+ * // difficulty: Big {
65
+ * // s: 1,
66
+ * // e: 21,
67
+ * // c: [Array],
68
+ * // constructor: [Function],
69
+ * // padAndChop: [Function (anonymous)]
70
+ * // },
71
+ * // totalDifficulty: Big {
72
+ * // s: 1,
73
+ * // e: 27,
74
+ * // c: [Array],
75
+ * // constructor: [Function],
76
+ * // padAndChop: [Function (anonymous)]
77
+ * // },
78
+ * // extraData: '0xce018c495249532d62613031656132',
79
+ * // size: Big {
80
+ * // s: 1,
81
+ * // e: 3,
82
+ * // c: [Array],
83
+ * // constructor: [Function],
84
+ * // padAndChop: [Function (anonymous)]
85
+ * // },
86
+ * // gasLimit: Big {
87
+ * // s: 1,
88
+ * // e: 6,
89
+ * // c: [Array],
90
+ * // constructor: [Function],
91
+ * // padAndChop: [Function (anonymous)]
92
+ * // },
93
+ * // gasUsed: Big {
94
+ * // s: 1,
95
+ * // e: 5,
96
+ * // c: [Array],
97
+ * // constructor: [Function],
98
+ * // padAndChop: [Function (anonymous)]
99
+ * // },
100
+ * // timestamp: Big {
101
+ * // s: 1,
102
+ * // e: 9,
103
+ * // c: [Array],
104
+ * // constructor: [Function],
105
+ * // padAndChop: [Function (anonymous)]
106
+ * // },
107
+ * // transactions: [
108
+ * // '0xd53800afc69e55cc7a64b927803b46a5b4c5ddccbaafb6b32fe0ec883739b825',
109
+ * // '0x4b8b07f35a1f911a80a0ffeebe3d3c41cd393b4d5e1ce0a408026705913d6760',
110
+ * // '0xa50eac0ea8005cb1e4b95be4e64c24035d9c41adb164c49477c3169870f02fb1',
111
+ * // '0x413e5293786f8b63e73adf0b74ab56067da4b564d01936b88b138d48cc414a42',
112
+ * // '0xd4e4969365d144b0b987632dca36ba9e272254bdc687245987a57666d6afa148'
113
+ * // ],
114
+ * // uncles: [
115
+ * // '0x36cd3869fd17a285b984dea8b705d34096e1fbdfe48df69ae530fbe921ba83fa'
116
+ * // ],
117
+ * // minimumGasPrice: '0x387ee40',
118
+ * // bitcoinMergedMiningHeader: '0x0040502d717ae205da048b0ffb8e110603564d8677ca8bd3a54601000000000000000000e722e86bfebcae00bffb46c663fa0241b63a27f0c98fa710e421d5cc1afa2448d08d6462d9f809172f5e30aa',
119
+ * // bitcoinMergedMiningCoinbaseTransaction: '0x00000000000001003f8757a906f0159f882f0968788a2e396b7bf8090e1b926fb2bb46789ac32d55082aca4e0800000000000000002b6a2952534b424c4f434b3a831a30935da1bd1e8631942fc7fa78f7a7b11d51ca39a1684d91a81f0040f9de00000000',
120
+ * // bitcoinMergedMiningMerkleProof: '0xb53111a4e11bc19bf90268485d1b957d908ebc6a4cd9862aca3fc6ed3dcf3240b14c316de8521369d55dbfeb2b0116bcc10f40e999c4885e1bd2a08691bdea1c43862d590390a227a379d5677b958f1a23eecc16ac590ad675b8a4cea0c10da3ef597acb9ca1fe0a21fc408f09e0c7169d83aca8ddd636d8cc155f922e1d36c74b7cc11e9ee98dd1bf2100a55d59630c65da3db1575d58f165c5753c1779df90efcff9017b73cc32f4c87178bd0eae6a6dd0357047be70d6c4af17fcef097e80a9f1751447f4eee3831fc79f2d894934694149bcb99840a525f5128215eca6b54642af452ee7568a9281f40560afffd35725df31b98155d7813dea12e42f2a8052c7d98bcf62c9cdc66c40fb12b729b685a31aec4970ea5316640691ae5eb616808656a2bde4e9f5920ff178bf9d1f84e96a0d0bd048a3a8ca0d60970d02aacf7ecfb6e7feaec5c4a764873531cfd630e9430840cfe8b88154da25d6b94b706fe678d0efc1ecafed5a1f539e34552bea65622513b663e17e121f3c4548942584',
121
+ * // hashForMergedMining: '0x831a30935da1bd1e8631942fc7fa78f7a7b11d51ca39a1684d91a81f0040f9de',
122
+ * // paidFees: '0x1fb451615b58',
123
+ * // cumulativeDifficulty: '0x8fdbe015f7248cf993'
124
+ * // }
125
+ */
126
+ function cleanBlock(block, returnTransactionObjects) {
127
+ const cleanedBlock = { ...block };
128
+ Object.keys(block).forEach((key) => {
129
+ // pending blocks have null instead of a difficulty
130
+ // pending blocks have null instead of a miner address
131
+ if (!block[key])
132
+ return;
133
+ switch (key) {
134
+ case 'difficulty':
135
+ case 'totalDifficulty':
136
+ case 'gasLimit':
137
+ case 'gasUsed':
138
+ case 'size':
139
+ case 'timestamp':
140
+ case 'baseFeePerGas':
141
+ cleanedBlock[key] = (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(block[key]));
142
+ break;
143
+ case 'number':
144
+ cleanedBlock[key] = Number((0, hex_to_decimal_1.hexToDecimal)(block[key]));
145
+ break;
146
+ case 'miner':
147
+ cleanedBlock[key] = (0, to_checksum_address_1.toChecksumAddress)(block[key]);
148
+ break;
149
+ }
150
+ });
151
+ // for all full transactions
152
+ if (returnTransactionObjects) {
153
+ const txns = block.transactions;
154
+ txns.forEach((transaction, index) => {
155
+ cleanedBlock.transactions[index] = (0, clean_transaction_1.cleanTransaction)(transaction);
156
+ });
157
+ }
158
+ return cleanedBlock;
159
+ }
160
+ exports.cleanBlock = cleanBlock;
@@ -0,0 +1,39 @@
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");
6
+ /**
7
+ * Converts RPC log receipt response to more JS-friendly format
8
+ *
9
+ * @param log the log to clean
10
+ * @param receiptLog if the log is part of a transaction receipt. Used to remove certain keys from log
11
+ * @example
12
+ */
13
+ function cleanLog(log, receiptLog) {
14
+ const cleanedLog = {
15
+ ...log,
16
+ };
17
+ Object.keys(log).forEach((key) => {
18
+ switch (key) {
19
+ case 'address':
20
+ cleanedLog[key] = (0, to_checksum_address_1.toChecksumAddress)(log[key]);
21
+ break;
22
+ case 'blockNumber':
23
+ case 'logIndex':
24
+ case 'transactionIndex':
25
+ cleanedLog[key] = Number((0, hex_to_decimal_1.hexToDecimal)(log[key]));
26
+ break;
27
+ case 'removed':
28
+ if (receiptLog) {
29
+ delete cleanedLog[key];
30
+ }
31
+ else if (log[key] == null) {
32
+ cleanedLog[key] === false;
33
+ }
34
+ break;
35
+ }
36
+ });
37
+ return cleanedLog;
38
+ }
39
+ exports.cleanLog = cleanLog;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanTransactionReceipt = 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 clean_log_1 = require("./clean-log");
7
+ const clean_transaction_1 = require("./clean-transaction");
8
+ const hex_to_decimal_1 = require("./hex-to-decimal");
9
+ /**
10
+ * Converts RPC transaction receipt response to more JS-friendly format
11
+ *
12
+ * @param transactionReceipt the transaction receipt to clean
13
+ * @returns a cleaned transaction receipt
14
+ * @example
15
+ * ```javascript
16
+ * const RPCTransactionReceipt = { blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: '0xe28f62', contractAddress: null, cumulativeGasUsed: '0x37a2b9', effectiveGasPrice: '0x62df1c62c', from: '0x642824fab1d0141073ed74326332950bec4701e3', gasUsed: '0x1a325', 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: '0x1', to: '0x84f80ea01e26b7c11bdd241970982c7eeab6ddcc', transactionHash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', transactionIndex: '0x29', type: '0x2' }
17
+ * cleanTransactionReceipt(RPCTransactionReceipt);
18
+ * // { 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 }
19
+ * ```
20
+ */
21
+ function cleanTransactionReceipt(transactionReceipt) {
22
+ const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(transactionReceipt);
23
+ const cleanedTransactionReceipt = {
24
+ ...cleanedTransaction,
25
+ };
26
+ Object.keys(transactionReceipt).forEach((key) => {
27
+ if (!transactionReceipt[key])
28
+ return;
29
+ switch (key) {
30
+ case 'status':
31
+ cleanedTransactionReceipt[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
32
+ break;
33
+ case 'contractAddress':
34
+ if (transactionReceipt[key]) {
35
+ cleanedTransactionReceipt[key] = (0, to_checksum_address_1.toChecksumAddress)(transactionReceipt[key]);
36
+ }
37
+ break;
38
+ case 'cumulativeGasUsed':
39
+ case 'effectiveGasPrice':
40
+ case 'gasUsed':
41
+ cleanedTransactionReceipt[key] = (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
42
+ break;
43
+ case 'logs':
44
+ transactionReceipt[key].forEach((log, index) => {
45
+ cleanedTransactionReceipt[key][index] = (0, clean_log_1.cleanLog)(log, true);
46
+ });
47
+ }
48
+ });
49
+ cleanedTransactionReceipt.byzantium =
50
+ cleanedTransactionReceipt.blockNumber >= 4370000;
51
+ return cleanedTransactionReceipt;
52
+ }
53
+ exports.cleanTransactionReceipt = cleanTransactionReceipt;
@@ -0,0 +1,54 @@
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");
7
+ /**
8
+ * Converts RPC transaction response to more JS-friendly format
9
+ *
10
+ * @param transaction the transaction to clean
11
+ * @returns a cleaned transaction
12
+ * @example
13
+ * ```javascript
14
+ * const RPCTransaction = { accessList: [], blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: '0xe28f62', chainId: '0x1', from: '0x642824fab1d0141073ed74326332950bec4701e3', gas: '0x274b7', gasPrice: '0x62df1c62c', hash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', input: '0xa0712d68000000000000000000000000000000000000000000000000000000000000000a', maxFeePerGas: '0x98808e3f0', maxPriorityFeePerGas: '0x3b9aca00', nonce: '0x42', r: '0x304682f8b22006dd1347c3722f6e43a5ad8e3a1ae51939cc0d6f07981602f5c0', s: '0x207ad110eb5c014cb628814b92396785fabfbe74542293300eeadf156f50f105', to: '0x84f80ea01e26b7c11bdd241970982c7eeab6ddcc', transactionIndex: '0x29', type: '0x2', v: '0x1', value: '0x470de4df820000' }
15
+ * cleanTransaction(RPCTransaction);
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 }
17
+ * ```
18
+ */
19
+ function cleanTransaction(transaction) {
20
+ const cleanedTransaction = {
21
+ ...transaction,
22
+ };
23
+ Object.keys(transaction).forEach((key) => {
24
+ // pending blocks have null instead of a difficulty
25
+ // pending blocks have null instead of a miner address
26
+ if (!transaction[key])
27
+ return;
28
+ switch (key) {
29
+ case 'blockNumber':
30
+ case 'chainId':
31
+ case 'transactionIndex':
32
+ case 'type':
33
+ case 'v':
34
+ cleanedTransaction[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
35
+ break;
36
+ case 'from':
37
+ case 'to':
38
+ if (transaction[key]) {
39
+ cleanedTransaction[key] = (0, to_checksum_address_1.toChecksumAddress)(transaction[key]);
40
+ }
41
+ break;
42
+ case 'value':
43
+ case 'gas':
44
+ case 'gasPrice':
45
+ case 'maxFeePerGas':
46
+ case 'maxPriorityFeePerGas':
47
+ case 'nonce':
48
+ cleanedTransaction[key] = (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
49
+ break;
50
+ }
51
+ });
52
+ return cleanedTransaction;
53
+ }
54
+ exports.cleanTransaction = cleanTransaction;
@@ -0,0 +1,175 @@
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';
10
+ /**
11
+ * @param hex
12
+ * @example
13
+ */
14
+ function hexToUtf8(hex) {
15
+ let str = '';
16
+ let i = 0;
17
+ const l = hex.length;
18
+ if (hex.substring(0, 2) === '0x') {
19
+ i = 2;
20
+ }
21
+ for (; i < l; i += 2) {
22
+ const code = parseInt(hex.substr(i, 2), 16);
23
+ if (code === 0)
24
+ continue; // Skip null bytes
25
+ str += String.fromCharCode(code);
26
+ }
27
+ try {
28
+ return decodeURIComponent(escape(str)); // Convert UTF-8 to Unicode
29
+ }
30
+ catch (e) {
31
+ return str; // Return original string if conversion fails
32
+ }
33
+ }
34
+ /**
35
+ * Expands an integer type to use a default of 256 bits. Used for consistency; not required in Solidity
36
+ *
37
+ * @see https://ethereum.stackexchange.com/questions/43241/why-write-uint256-instead-of-uint-if-theyre-the-same-thing
38
+ * @param type the type to explicitly define as 256 bits
39
+ * @returns the integer type expanded to explicitly be 256 bits when possible
40
+ * @example
41
+ * ```javascript
42
+ * expandType('uint[]');
43
+ * // 'uint256[]'
44
+ * ```
45
+ */
46
+ function expandType(type) {
47
+ // https://docs.soliditylang.org/en/v0.8.7/types.html#integers
48
+ if (type === 'uint[]') {
49
+ return 'uint256[]';
50
+ }
51
+ else if (type === 'int[]') {
52
+ return 'int256[]';
53
+ }
54
+ return type;
55
+ }
56
+ /**
57
+ *
58
+ * @param jsonABIArgument
59
+ * @param args
60
+ * @example
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))})`;
66
+ // encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
67
+ const functionHash = hash.update(functionString).digest('hex');
68
+ // no arrays
69
+ const jsonABIInputsLength = jsonABIArgument.inputs.length;
70
+ let shouldValidateInputLength = true;
71
+ // inputs contains 1 or more arrays
72
+ if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
73
+ shouldValidateInputLength = false;
74
+ }
75
+ if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
76
+ throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
77
+ }
78
+ const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
79
+ if (input.type.includes('[')) {
80
+ // strip array and length like "[2]" from type
81
+ const basicType = /([^[]*)\[.*$/g.exec(input.type)?.[1];
82
+ args.forEach((arg) => {
83
+ acc = acc.concat([[arg, basicType]]);
84
+ });
85
+ return acc;
86
+ }
87
+ else {
88
+ return acc.concat([[args[i], input.type]]);
89
+ }
90
+ }, []);
91
+ const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
92
+ let rawArg = arg;
93
+ switch (inputType) {
94
+ case 'bool':
95
+ return arg ? hexTrue : exports.hexFalse;
96
+ case 'address':
97
+ // remove leading "0x"
98
+ rawArg = arg.replace(/^0x/g, '').toLowerCase();
99
+ break;
100
+ default:
101
+ if (inputType.startsWith('bytes')) {
102
+ // encode each character to hex
103
+ const argEncoded = rawArg
104
+ .split('')
105
+ .map((character) => character.charCodeAt(0).toString(16))
106
+ .join('');
107
+ const paddedEncodedArg = argEncoded.padEnd(64, '0');
108
+ return paddedEncodedArg;
109
+ }
110
+ else if (inputType === 'uint256') {
111
+ const argEncoded = BigInt(arg).toString(16);
112
+ const paddedEncodedArg = argEncoded.padStart(64, '0');
113
+ return paddedEncodedArg;
114
+ }
115
+ else if (inputType.startsWith('uint')) {
116
+ break;
117
+ }
118
+ else {
119
+ throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
120
+ }
121
+ }
122
+ const argEncoded = rawArg.toString(16);
123
+ const paddedEncodedArg = argEncoded.padStart(64, '0');
124
+ return paddedEncodedArg;
125
+ });
126
+ const functionEncoded = functionHash.slice(0, 8);
127
+ const data = `0x${functionEncoded}${encodedArgs.join('')}`;
128
+ return data;
129
+ }
130
+ exports.encodeData = encodeData;
131
+ /**
132
+ * @internal
133
+ * @param jsonABIArgument
134
+ * @param nodeResponse
135
+ * @example
136
+ */
137
+ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
138
+ const rawOutputs = jsonABIArgument.outputs;
139
+ const slicedResponse = nodeResponse.slice(2);
140
+ if (jsonABIArgument?.outputs?.length === 1 &&
141
+ jsonABIArgument.outputs[0].type === 'string') {
142
+ const [hexOffset, responseData] = [
143
+ slicedResponse.slice(0, 64),
144
+ slicedResponse.slice(64),
145
+ ];
146
+ const decimalOffset = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexOffset}`));
147
+ const hexLength = responseData.slice(0, decimalOffset * 2);
148
+ const decimalLength = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexLength}`));
149
+ const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
150
+ return hexToUtf8(hexToDecode);
151
+ }
152
+ // chunk response every 64 characters
153
+ const encodedOutputs = slicedResponse.match(/.{1,64}/g);
154
+ const outputs = (encodedOutputs || []).map((output, i) => {
155
+ const outputType = (rawOutputs || [])[i].type;
156
+ switch (outputType) {
157
+ case 'bool':
158
+ return output === hexTrue;
159
+ case 'address':
160
+ /* address types have 24 leading zeroes to remove */
161
+ return (0, to_checksum_address_1.toChecksumAddress)(`0x${output.slice(24)}`);
162
+ case 'uint256':
163
+ case 'uint120':
164
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
165
+ case 'bytes32':
166
+ return `0x${output}`;
167
+ case 'uint8':
168
+ return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
169
+ default:
170
+ throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
171
+ }
172
+ });
173
+ return outputs.length === 1 ? outputs[0] : outputs;
174
+ }
175
+ exports.decodeRPCResponse = decodeRPCResponse;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildRPCPostBody = exports.post = exports.buildFetchInit = void 0;
7
+ const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
8
+ /**
9
+ * Forms the init field for http fetching
10
+ *
11
+ * @param body
12
+ * @internal
13
+ */
14
+ function buildFetchInit(body) {
15
+ return {
16
+ method: 'POST',
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ },
20
+ body: JSON.stringify(body),
21
+ };
22
+ }
23
+ exports.buildFetchInit = buildFetchInit;
24
+ /**
25
+ * Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
26
+ *
27
+ * @internal
28
+ * @param url the URL to send the request to
29
+ * @param body JSON POST body
30
+ * @returns the JSON response from the server
31
+ * @example
32
+ * ```javascript
33
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
34
+ * // '0x66fa8dbfd'
35
+ *
36
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
37
+ * // '0x312faeb995df61d4'
38
+ * ```
39
+ */
40
+ function post(url, body) {
41
+ return (0, isomorphic_unfetch_1.default)(url, buildFetchInit(body))
42
+ .then(async (r) => {
43
+ const t = await r.text();
44
+ try {
45
+ return JSON.parse(t);
46
+ }
47
+ catch {
48
+ throw new Error(`Invalid JSON RPC response: "${t}"`);
49
+ }
50
+ })
51
+ .then((response) => {
52
+ const result = response?.result;
53
+ if (!result) {
54
+ throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
55
+ }
56
+ return response.result;
57
+ });
58
+ }
59
+ exports.post = post;
60
+ /**
61
+ * Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
62
+ *
63
+ * @internal
64
+ * @param method the RPC method to be invoked
65
+ * @param params the parameters to be passed to the defined method
66
+ * @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
67
+ * @example
68
+ * ```javascript
69
+ * buildRPCPostBody('eth_gasPrice', []);
70
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
71
+ *
72
+ * buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
73
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
74
+ * ```
75
+ */
76
+ function buildRPCPostBody(method, params) {
77
+ return {
78
+ jsonrpc: '2.0',
79
+ // TODO: Increment ID will be needed when websocket support is added
80
+ id: 1,
81
+ method,
82
+ params,
83
+ };
84
+ }
85
+ exports.buildRPCPostBody = buildRPCPostBody;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hexToDecimal = void 0;
4
+ /**
5
+ * Converts a hexadecimal string it's decimal equivalent.
6
+ * This is needed instead of parseInt because parseInt loses precision.
7
+ *
8
+ * @param hex the hex string to be converted to decimal
9
+ * @returns a decimal value equivalent to the hex string given
10
+ * @example
11
+ * ```javascript
12
+ * hexToDecimal('0x34');
13
+ * // 52
14
+ * ```
15
+ * @example
16
+ * ```javascript
17
+ * hexToDecimal('0x628608');
18
+ * // 6456840
19
+ * ```
20
+ */
21
+ function hexToDecimal(hex) {
22
+ return BigInt(hex).toString();
23
+ }
24
+ exports.hexToDecimal = hexToDecimal;