essential-eth 0.5.11-next.1 → 0.5.13-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/{classes → cjs/classes}/Contract.d.ts +0 -0
  2. package/dist/cjs/classes/Contract.js +140 -0
  3. package/dist/{classes → cjs/classes}/test/Contract/crv-abi.d.ts +0 -0
  4. package/dist/cjs/classes/test/Contract/crv-abi.js +488 -0
  5. package/dist/{classes → cjs/classes}/test/Contract/ens-abi.d.ts +0 -0
  6. package/dist/cjs/classes/test/Contract/ens-abi.js +453 -0
  7. package/dist/{classes → cjs/classes}/test/Contract/fei-abi.d.ts +0 -0
  8. package/dist/cjs/classes/test/Contract/fei-abi.js +526 -0
  9. package/dist/{classes → cjs/classes}/test/Contract/foo-abi.d.ts +0 -0
  10. package/dist/cjs/classes/test/Contract/foo-abi.js +42 -0
  11. package/dist/{classes → cjs/classes}/test/Contract/uniswap-abi.d.ts +0 -0
  12. package/dist/cjs/classes/test/Contract/uniswap-abi.js +121 -0
  13. package/dist/{classes → cjs/classes}/utils/clean-block.d.ts +0 -0
  14. package/dist/cjs/classes/utils/clean-block.js +160 -0
  15. package/dist/{classes → cjs/classes}/utils/clean-log.d.ts +0 -0
  16. package/dist/cjs/classes/utils/clean-log.js +37 -0
  17. package/dist/{classes → cjs/classes}/utils/clean-transaction-receipt.d.ts +0 -0
  18. package/dist/cjs/classes/utils/clean-transaction-receipt.js +50 -0
  19. package/dist/{classes → cjs/classes}/utils/clean-transaction.d.ts +0 -0
  20. package/dist/cjs/classes/utils/clean-transaction.js +51 -0
  21. package/dist/{classes → cjs/classes}/utils/encode-decode-transaction.d.ts +0 -0
  22. package/dist/cjs/classes/utils/encode-decode-transaction.js +137 -0
  23. package/dist/{classes → cjs/classes}/utils/fetchers.d.ts +0 -0
  24. package/dist/cjs/classes/utils/fetchers.js +81 -0
  25. package/dist/{classes → cjs/classes}/utils/hex-to-decimal.d.ts +0 -0
  26. package/dist/cjs/classes/utils/hex-to-decimal.js +24 -0
  27. package/dist/{classes → cjs/classes}/utils/prepare-transaction.d.ts +0 -0
  28. package/dist/cjs/classes/utils/prepare-transaction.js +45 -0
  29. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  30. package/dist/cjs/index.js +54 -0
  31. package/dist/cjs/index.umd.js +2 -0
  32. package/dist/cjs/index.umd.js.map +1 -0
  33. package/dist/{logger → cjs/logger}/logger.d.ts +0 -0
  34. package/dist/cjs/logger/logger.js +36 -0
  35. package/dist/cjs/logger/package-version.d.ts +1 -0
  36. package/dist/cjs/logger/package-version.js +5 -0
  37. package/dist/{providers → cjs/providers}/BaseProvider.d.ts +0 -0
  38. package/dist/cjs/providers/BaseProvider.js +512 -0
  39. package/dist/{providers → cjs/providers}/FallthroughProvider.d.ts +0 -0
  40. package/dist/cjs/providers/FallthroughProvider.js +65 -0
  41. package/dist/{providers → cjs/providers}/JsonRpcProvider.d.ts +0 -0
  42. package/dist/cjs/providers/JsonRpcProvider.js +46 -0
  43. package/dist/{providers → cjs/providers}/test/rpc-urls.d.ts +0 -0
  44. package/dist/cjs/providers/test/rpc-urls.js +14 -0
  45. package/dist/{providers → cjs/providers}/utils/chains-info.d.ts +0 -0
  46. package/dist/cjs/providers/utils/chains-info.js +1402 -0
  47. package/dist/{shared → cjs/shared}/tiny-big/helpers.d.ts +0 -0
  48. package/dist/cjs/shared/tiny-big/helpers.js +97 -0
  49. package/dist/{shared → cjs/shared}/tiny-big/tiny-big.d.ts +0 -0
  50. package/dist/cjs/shared/tiny-big/tiny-big.js +101 -0
  51. package/dist/{shared → cjs/shared}/validate-type.d.ts +0 -0
  52. package/dist/cjs/shared/validate-type.js +9 -0
  53. package/dist/{types → cjs/types}/Block.types.d.ts +0 -0
  54. package/dist/cjs/types/Block.types.js +2 -0
  55. package/dist/{types → cjs/types}/Contract.types.d.ts +0 -0
  56. package/dist/cjs/types/Contract.types.js +2 -0
  57. package/dist/{types → cjs/types}/Filter.types.d.ts +0 -0
  58. package/dist/cjs/types/Filter.types.js +2 -0
  59. package/dist/{types → cjs/types}/Network.types.d.ts +0 -0
  60. package/dist/cjs/types/Network.types.js +2 -0
  61. package/dist/{types → cjs/types}/Transaction.types.d.ts +0 -0
  62. package/dist/cjs/types/Transaction.types.js +2 -0
  63. package/dist/{utils → cjs/utils}/bytes.d.ts +0 -0
  64. package/dist/cjs/utils/bytes.js +711 -0
  65. package/dist/{utils → cjs/utils}/compute-address.d.ts +0 -0
  66. package/dist/cjs/utils/compute-address.js +33 -0
  67. package/dist/{utils → cjs/utils}/compute-public-key.d.ts +0 -0
  68. package/dist/cjs/utils/compute-public-key.js +26 -0
  69. package/dist/{utils → cjs/utils}/ether-to-gwei.d.ts +0 -0
  70. package/dist/cjs/utils/ether-to-gwei.js +35 -0
  71. package/dist/{utils → cjs/utils}/ether-to-wei.d.ts +0 -0
  72. package/dist/cjs/utils/ether-to-wei.js +35 -0
  73. package/dist/{utils → cjs/utils}/gwei-to-ether.d.ts +0 -0
  74. package/dist/cjs/utils/gwei-to-ether.js +35 -0
  75. package/dist/{utils → cjs/utils}/hash-message.d.ts +0 -0
  76. package/dist/cjs/utils/hash-message.js +28 -0
  77. package/dist/{utils → cjs/utils}/is-address.d.ts +0 -0
  78. package/dist/cjs/utils/is-address.js +39 -0
  79. package/dist/{utils → cjs/utils}/keccak256.d.ts +0 -0
  80. package/dist/cjs/utils/keccak256.js +31 -0
  81. package/dist/{utils → cjs/utils}/solidity-keccak256.d.ts +0 -0
  82. package/dist/cjs/utils/solidity-keccak256.js +138 -0
  83. package/dist/{utils → cjs/utils}/split-signature.d.ts +0 -0
  84. package/dist/cjs/utils/split-signature.js +163 -0
  85. package/dist/{utils → cjs/utils}/to-checksum-address.d.ts +0 -0
  86. package/dist/cjs/utils/to-checksum-address.js +46 -0
  87. package/dist/{utils → cjs/utils}/to-utf8-bytes.d.ts +0 -0
  88. package/dist/cjs/utils/to-utf8-bytes.js +21 -0
  89. package/dist/{utils → cjs/utils}/wei-to-ether.d.ts +0 -0
  90. package/dist/cjs/utils/wei-to-ether.js +45 -0
  91. package/dist/esm/classes/Contract.d.ts +11 -0
  92. package/dist/esm/classes/Contract.js +65 -0
  93. package/dist/esm/classes/test/Contract/crv-abi.d.ts +2 -0
  94. package/dist/esm/classes/test/Contract/crv-abi.js +470 -0
  95. package/dist/esm/classes/test/Contract/ens-abi.d.ts +2 -0
  96. package/dist/esm/classes/test/Contract/ens-abi.js +435 -0
  97. package/dist/esm/classes/test/Contract/fei-abi.d.ts +2 -0
  98. package/dist/esm/classes/test/Contract/fei-abi.js +521 -0
  99. package/dist/esm/classes/test/Contract/foo-abi.d.ts +2 -0
  100. package/dist/esm/classes/test/Contract/foo-abi.js +33 -0
  101. package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
  102. package/dist/esm/classes/test/Contract/uniswap-abi.js +116 -0
  103. package/dist/esm/classes/utils/clean-block.d.ts +3 -0
  104. package/dist/esm/classes/utils/clean-block.js +35 -0
  105. package/dist/esm/classes/utils/clean-log.d.ts +2 -0
  106. package/dist/esm/classes/utils/clean-log.js +26 -0
  107. package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
  108. package/dist/esm/classes/utils/clean-transaction-receipt.js +34 -0
  109. package/dist/esm/classes/utils/clean-transaction.d.ts +2 -0
  110. package/dist/esm/classes/utils/clean-transaction.js +33 -0
  111. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +4 -0
  112. package/dist/esm/classes/utils/encode-decode-transaction.js +98 -0
  113. package/dist/esm/classes/utils/fetchers.d.ts +9 -0
  114. package/dist/esm/classes/utils/fetchers.js +43 -0
  115. package/dist/esm/classes/utils/hex-to-decimal.d.ts +1 -0
  116. package/dist/esm/classes/utils/hex-to-decimal.js +3 -0
  117. package/dist/esm/classes/utils/prepare-transaction.d.ts +2 -0
  118. package/dist/esm/classes/utils/prepare-transaction.js +34 -0
  119. package/dist/esm/index.d.ts +25 -0
  120. package/dist/esm/index.js +20 -0
  121. package/dist/esm/logger/logger.d.ts +11 -0
  122. package/dist/esm/logger/logger.js +33 -0
  123. package/dist/esm/logger/package-version.d.ts +1 -0
  124. package/dist/esm/logger/package-version.js +1 -0
  125. package/dist/esm/providers/BaseProvider.d.ts +24 -0
  126. package/dist/esm/providers/BaseProvider.js +157 -0
  127. package/dist/esm/providers/FallthroughProvider.d.ts +11 -0
  128. package/dist/esm/providers/FallthroughProvider.js +41 -0
  129. package/dist/esm/providers/JsonRpcProvider.d.ts +7 -0
  130. package/dist/esm/providers/JsonRpcProvider.js +15 -0
  131. package/dist/esm/providers/test/rpc-urls.d.ts +11 -0
  132. package/dist/esm/providers/test/rpc-urls.js +11 -0
  133. package/dist/esm/providers/utils/chains-info.d.ts +467 -0
  134. package/dist/esm/providers/utils/chains-info.js +1398 -0
  135. package/dist/esm/shared/tiny-big/helpers.d.ts +1 -0
  136. package/dist/esm/shared/tiny-big/helpers.js +58 -0
  137. package/dist/esm/shared/tiny-big/tiny-big.d.ts +10 -0
  138. package/dist/esm/shared/tiny-big/tiny-big.js +45 -0
  139. package/dist/esm/shared/validate-type.d.ts +3 -0
  140. package/dist/esm/shared/validate-type.js +5 -0
  141. package/dist/esm/types/Block.types.d.ts +40 -0
  142. package/dist/esm/types/Block.types.js +1 -0
  143. package/dist/esm/types/Contract.types.d.ts +24 -0
  144. package/dist/esm/types/Contract.types.js +1 -0
  145. package/dist/esm/types/Filter.types.d.ts +12 -0
  146. package/dist/esm/types/Filter.types.js +1 -0
  147. package/dist/esm/types/Network.types.d.ts +5 -0
  148. package/dist/esm/types/Network.types.js +1 -0
  149. package/dist/esm/types/Transaction.types.d.ts +113 -0
  150. package/dist/esm/types/Transaction.types.js +1 -0
  151. package/dist/esm/utils/bytes.d.ts +40 -0
  152. package/dist/esm/utils/bytes.js +245 -0
  153. package/dist/esm/utils/compute-address.d.ts +1 -0
  154. package/dist/esm/utils/compute-address.js +11 -0
  155. package/dist/esm/utils/compute-public-key.d.ts +2 -0
  156. package/dist/esm/utils/compute-public-key.js +6 -0
  157. package/dist/esm/utils/ether-to-gwei.d.ts +3 -0
  158. package/dist/esm/utils/ether-to-gwei.js +7 -0
  159. package/dist/esm/utils/ether-to-wei.d.ts +3 -0
  160. package/dist/esm/utils/ether-to-wei.js +7 -0
  161. package/dist/esm/utils/gwei-to-ether.d.ts +3 -0
  162. package/dist/esm/utils/gwei-to-ether.js +7 -0
  163. package/dist/esm/utils/hash-message.d.ts +2 -0
  164. package/dist/esm/utils/hash-message.js +12 -0
  165. package/dist/esm/utils/is-address.d.ts +1 -0
  166. package/dist/esm/utils/is-address.js +12 -0
  167. package/dist/esm/utils/keccak256.d.ts +2 -0
  168. package/dist/esm/utils/keccak256.js +13 -0
  169. package/dist/esm/utils/solidity-keccak256.d.ts +2 -0
  170. package/dist/esm/utils/solidity-keccak256.js +85 -0
  171. package/dist/esm/utils/split-signature.d.ts +2 -0
  172. package/dist/esm/utils/split-signature.js +126 -0
  173. package/dist/esm/utils/to-checksum-address.d.ts +1 -0
  174. package/dist/esm/utils/to-checksum-address.js +25 -0
  175. package/dist/esm/utils/to-utf8-bytes.d.ts +1 -0
  176. package/dist/esm/utils/to-utf8-bytes.js +3 -0
  177. package/dist/esm/utils/wei-to-ether.d.ts +3 -0
  178. package/dist/esm/utils/wei-to-ether.js +16 -0
  179. package/package.json +10 -10
  180. package/readme.md +5 -1
  181. package/dist/index.js +0 -1904
  182. package/dist/index.js.map +0 -1
  183. package/dist/index.module.js +0 -1865
  184. package/dist/index.module.js.map +0 -1
  185. package/dist/index.umd.js +0 -2
  186. package/dist/index.umd.js.map +0 -1
  187. package/dist/logger/package-version.d.ts +0 -1
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanBlock = void 0;
4
+ const __1 = require("../..");
5
+ const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
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 = Object.assign({}, 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, __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,37 @@
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 = 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]);
19
+ break;
20
+ case 'blockNumber':
21
+ case 'logIndex':
22
+ case 'transactionIndex':
23
+ cleanedLog[key] = Number((0, hex_to_decimal_1.hexToDecimal)(log[key]));
24
+ break;
25
+ case 'removed':
26
+ if (receiptLog) {
27
+ delete cleanedLog[key];
28
+ }
29
+ else if (log[key] == null) {
30
+ cleanedLog[key] === false;
31
+ }
32
+ break;
33
+ }
34
+ });
35
+ return cleanedLog;
36
+ }
37
+ exports.cleanLog = cleanLog;
@@ -0,0 +1,50 @@
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");
8
+ /**
9
+ * Converts RPC transaction receipt response to more JS-friendly format
10
+ *
11
+ * @param transactionReceipt the transaction receipt to clean
12
+ * @returns a cleaned transaction receipt
13
+ * @example
14
+ * ```javascript
15
+ * 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' }
16
+ * cleanTransactionReceipt(RPCTransactionReceipt);
17
+ * // { 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
+ * ```
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]));
29
+ break;
30
+ case 'contractAddress':
31
+ if (transactionReceipt[key]) {
32
+ cleanedTransactionReceipt[key] = (0, __1.toChecksumAddress)(transactionReceipt[key]);
33
+ }
34
+ break;
35
+ case 'cumulativeGasUsed':
36
+ case 'effectiveGasPrice':
37
+ case 'gasUsed':
38
+ cleanedTransactionReceipt[key] = (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
39
+ break;
40
+ case 'logs':
41
+ transactionReceipt[key].forEach((log, index) => {
42
+ cleanedTransactionReceipt[key][index] = (0, clean_log_1.cleanLog)(log, true);
43
+ });
44
+ }
45
+ });
46
+ cleanedTransactionReceipt.byzantium =
47
+ cleanedTransactionReceipt.blockNumber >= 4370000;
48
+ return cleanedTransactionReceipt;
49
+ }
50
+ exports.cleanTransactionReceipt = cleanTransactionReceipt;
@@ -0,0 +1,51 @@
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");
6
+ /**
7
+ * Converts RPC transaction response to more JS-friendly format
8
+ *
9
+ * @param transaction the transaction to clean
10
+ * @returns a cleaned transaction
11
+ * @example
12
+ * ```javascript
13
+ * 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' }
14
+ * cleanTransaction(RPCTransaction);
15
+ * // { 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
+ * ```
17
+ */
18
+ function cleanTransaction(transaction) {
19
+ const cleanedTransaction = Object.assign({}, transaction);
20
+ Object.keys(transaction).forEach((key) => {
21
+ // pending blocks have null instead of a difficulty
22
+ // 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]));
32
+ break;
33
+ case 'from':
34
+ case 'to':
35
+ if (transaction[key]) {
36
+ cleanedTransaction[key] = (0, __1.toChecksumAddress)(transaction[key]);
37
+ }
38
+ 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]));
46
+ break;
47
+ }
48
+ });
49
+ return cleanedTransaction;
50
+ }
51
+ exports.cleanTransaction = cleanTransaction;
@@ -0,0 +1,137 @@
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';
9
+ /**
10
+ * Expands an integer type to use a default of 256 bits. Used for consistency; not required in Solidity
11
+ *
12
+ * @see https://ethereum.stackexchange.com/questions/43241/why-write-uint256-instead-of-uint-if-theyre-the-same-thing
13
+ * @param type the type to explicitly define as 256 bits
14
+ * @returns the integer type expanded to explicitly be 256 bits when possible
15
+ * @example
16
+ * ```javascript
17
+ * expandType('uint[]');
18
+ * // 'uint256[]'
19
+ * ```
20
+ */
21
+ function expandType(type) {
22
+ // 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[]';
28
+ }
29
+ return type;
30
+ }
31
+ /**
32
+ *
33
+ * @param jsonABIArgument
34
+ * @param args
35
+ * @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))})`;
41
+ // 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');
43
+ // no arrays
44
+ const jsonABIInputsLength = jsonABIArgument.inputs.length;
45
+ let shouldValidateInputLength = true;
46
+ // inputs contains 1 or more arrays
47
+ if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
48
+ shouldValidateInputLength = false;
49
+ }
50
+ if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
51
+ throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
52
+ }
53
+ const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
54
+ var _a;
55
+ if (input.type.includes('[')) {
56
+ // 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]]);
60
+ });
61
+ return acc;
62
+ }
63
+ else {
64
+ return acc.concat([[args[i], input.type]]);
65
+ }
66
+ }, []);
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':
73
+ // remove leading "0x"
74
+ rawArg = arg.replace(/^0x/g, '').toLowerCase();
75
+ break;
76
+ default:
77
+ if (inputType.startsWith('bytes')) {
78
+ // 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');
84
+ 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')) {
92
+ break;
93
+ }
94
+ else {
95
+ throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
96
+ }
97
+ }
98
+ const argEncoded = rawArg.toString(16);
99
+ const paddedEncodedArg = argEncoded.padStart(64, '0');
100
+ return paddedEncodedArg;
101
+ });
102
+ const functionEncoded = functionHash.slice(0, 8);
103
+ const data = `0x${functionEncoded}${encodedArgs.join('')}`;
104
+ return data;
105
+ }
106
+ exports.encodeData = encodeData;
107
+ /**
108
+ *
109
+ * @param jsonABIArgument
110
+ * @param nodeResponse
111
+ * @example
112
+ */
113
+ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
114
+ const rawOutputs = jsonABIArgument.outputs;
115
+ // 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':
121
+ 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
+ return (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
127
+ case 'bytes32':
128
+ return `0x${output}`;
129
+ case 'uint8':
130
+ return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
131
+ default:
132
+ throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
133
+ }
134
+ });
135
+ return outputs.length === 1 ? outputs[0] : outputs;
136
+ }
137
+ exports.decodeRPCResponse = decodeRPCResponse;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.buildRPCPostBody = exports.post = void 0;
16
+ const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
17
+ /**
18
+ * Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
19
+ *
20
+ * @param url the URL to send the request to
21
+ * @param body the body data (JSON) to send with the request
22
+ * @returns the JSON response from the server
23
+ * @example
24
+ * ```javascript
25
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
26
+ * // '0x66fa8dbfd'
27
+ *
28
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
29
+ * // '0x312faeb995df61d4'
30
+ * ```
31
+ */
32
+ function post(url, body) {
33
+ return (0, isomorphic_unfetch_1.default)(url, {
34
+ method: 'POST',
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ },
38
+ body: JSON.stringify(body),
39
+ })
40
+ .then((r) => __awaiter(this, void 0, void 0, function* () {
41
+ const t = yield r.text();
42
+ try {
43
+ return JSON.parse(t);
44
+ }
45
+ catch (_a) {
46
+ throw new Error(`Invalid JSON RPC response: "${t}"`);
47
+ }
48
+ }))
49
+ .then((response) => {
50
+ const result = response === null || response === void 0 ? void 0 : response.result;
51
+ if (!result) {
52
+ throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
53
+ }
54
+ return response.result;
55
+ });
56
+ }
57
+ exports.post = post;
58
+ /**
59
+ * 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}
60
+ *
61
+ * @param method the RPC method to be invoked
62
+ * @param params the parameters to be passed to the defined method
63
+ * @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
64
+ * @example
65
+ * ```javascript
66
+ * buildRPCPostBody('eth_gasPrice', []);
67
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
68
+ *
69
+ * buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
70
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
71
+ * ```
72
+ */
73
+ function buildRPCPostBody(method, params) {
74
+ return {
75
+ jsonrpc: '2.0',
76
+ id: 1,
77
+ method,
78
+ params,
79
+ };
80
+ }
81
+ 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;
@@ -0,0 +1,45 @@
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.prepareTransaction = void 0;
7
+ const big_js_1 = __importDefault(require("big.js"));
8
+ const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
9
+ const bytes_1 = require("../../utils/bytes");
10
+ /**
11
+ * @param transaction
12
+ * @example
13
+ */
14
+ function prepareTransaction(transaction) {
15
+ const preparedTransaction = Object.assign({}, transaction);
16
+ Object.keys(transaction).forEach((key) => {
17
+ switch (key) {
18
+ case 'gas':
19
+ case 'gasPrice':
20
+ case 'nonce':
21
+ case 'maxFeePerGas':
22
+ case 'maxPriorityFeePerGas':
23
+ case 'value': {
24
+ const value = transaction[key];
25
+ if (value instanceof tiny_big_1.TinyBig) {
26
+ preparedTransaction[key] = value.toHexString();
27
+ }
28
+ else if (value instanceof big_js_1.default) {
29
+ preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
30
+ }
31
+ else if (typeof transaction[key] === 'number')
32
+ preparedTransaction[key] =
33
+ '0x' + transaction[key].toString(16);
34
+ else
35
+ preparedTransaction[key] = transaction[key].toString();
36
+ break;
37
+ }
38
+ case 'data':
39
+ preparedTransaction[key] = (0, bytes_1.hexlify)(transaction[key]);
40
+ break;
41
+ }
42
+ });
43
+ return preparedTransaction;
44
+ }
45
+ exports.prepareTransaction = prepareTransaction;
File without changes