@exodus/ethereum-api 2.11.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "2.11.0",
3
+ "version": "2.13.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@exodus/asset-lib": "^3.5.4",
14
+ "@exodus/crypto": "^1.0.0-rc.0",
14
15
  "@exodus/ethereum-lib": "^2.13.4",
15
16
  "@exodus/ethereumjs-util": "^7.1.0-exodus.6",
16
17
  "@exodus/simple-retry": "^0.0.6",
@@ -27,5 +28,5 @@
27
28
  "@exodus/assets-base": "^8.0.136",
28
29
  "@exodus/models": "^8.7.2"
29
30
  },
30
- "gitHead": "5fc7dbd1598091cb3a3df33b6b20a2a5e9bfbb7e"
31
+ "gitHead": "4fddf195ead826e4f407841a06e00c794cc41952"
31
32
  }
@@ -6,6 +6,7 @@ import createWebSocket from './ws'
6
6
  import { retry } from '@exodus/simple-retry'
7
7
  import { simpleErc20 } from '@exodus/solidity-contract'
8
8
  import { bufferToHex } from '@exodus/ethereumjs-util'
9
+ import { randomUUID } from '@exodus/crypto/randomUUID'
9
10
 
10
11
  const RETRY_DELAYS = ['10s']
11
12
 
@@ -18,10 +19,10 @@ export function create(defaultURL) {
18
19
  return url.format(obj)
19
20
  })
20
21
 
21
- async function request(module, params = {}, version = 'v1') {
22
+ async function request(module, params = {}, { version = 'v1', method = 'get' } = {}) {
22
23
  const url = urlJoin(version === 'v1' ? API_URL : API_URL.replace('v1', version), module)
23
24
  try {
24
- return await fetchival(url, { timeout: ms('15s') }).get(params)
25
+ return await fetchival(url, { timeout: ms('15s') })[method](params)
25
26
  } catch (err) {
26
27
  let nerr = err
27
28
  if (err.response && err.response.status === 500) {
@@ -69,6 +70,10 @@ export function create(defaultURL) {
69
70
  return requestWithRetry('balance', { address, from: opts.startblock, to: opts.endblock })
70
71
  },
71
72
 
73
+ async getBalanceProxied(address, tag = 'latest') {
74
+ return requestWithRetry('proxy', { method: 'eth_getBalance', address, tag })
75
+ },
76
+
72
77
  async balanceOf(address, tokenAddress, tag = 'latest') {
73
78
  const contract = simpleErc20(tokenAddress)
74
79
  const callData = contract.balanceOf.build(address)
@@ -102,7 +107,7 @@ export function create(defaultURL) {
102
107
  address,
103
108
  ...opts,
104
109
  },
105
- 'v2'
110
+ { version: 'v2' }
106
111
  )
107
112
  },
108
113
 
@@ -225,5 +230,13 @@ export function create(defaultURL) {
225
230
  method: 'net_version',
226
231
  })
227
232
  },
233
+
234
+ async proxyToCoinNode(requestData) {
235
+ if (!requestData.jsonrpc) requestData.jsonrpc = '2.0'
236
+ if (!requestData.id) requestData.id = randomUUID()
237
+ if (!requestData.params) requestData.params = []
238
+
239
+ return request('proxy', requestData, { version: 'v2', method: 'post' })
240
+ },
228
241
  }
229
242
  }