@exodus/ethereum-api 0.2.5 → 0.2.7
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 +2 -2
- package/src/with-fallback.js +44 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"url-join": "4.0.0",
|
|
20
20
|
"ws": "6.1.0"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "7b2e88a73e28ff83bafb6ba4695f3c24ecd20d21"
|
|
23
23
|
}
|
package/src/with-fallback.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { get } from 'lodash'
|
|
2
|
-
import { _isEthereumToken } from '@exodus/ethereum-lib'
|
|
3
2
|
import { eth as ethServer, etc as etcServer } from './exodus-eth-server'
|
|
4
3
|
import * as etherscan from './etherscan'
|
|
5
4
|
|
|
@@ -18,52 +17,71 @@ export function withFallback(fn, fn2) {
|
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
export async function isContract(assetName, address) {
|
|
21
|
+
const _getCode =
|
|
22
|
+
assetName === 'ethereumclassic'
|
|
23
|
+
? withFallback(etcServer.getCode, etcServer.getCode)
|
|
24
|
+
: withFallback(ethServer.getCode, etherscan.getCode)
|
|
25
|
+
|
|
26
|
+
const code = await _getCode(address)
|
|
27
|
+
return code.length > 2
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
export async function getNonce({ asset, address }) {
|
|
22
31
|
if (!['ethereum', 'ethereumclassic'].includes(asset.name)) return
|
|
23
32
|
|
|
24
33
|
const _getNonce =
|
|
25
|
-
asset.name === '
|
|
26
|
-
? withFallback(
|
|
27
|
-
:
|
|
34
|
+
asset.name === 'ethereumclassic'
|
|
35
|
+
? withFallback(etcServer.getTransactionCount, etcServer.getTransactionCount)
|
|
36
|
+
: withFallback(ethServer.getTransactionCount, etherscan.getTransactionCount)
|
|
28
37
|
|
|
29
38
|
const nonce = await _getNonce(address)
|
|
30
39
|
return parseInt(nonce, 16)
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
export async function estimateGas({ asset, ...args }) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
const _estimateGas =
|
|
44
|
+
asset.name === 'ethereumclassic'
|
|
45
|
+
? withFallback(etcServer.estimateGas, etcServer.estimateGas)
|
|
46
|
+
: withFallback(ethServer.estimateGas, etherscan.estimateGas)
|
|
47
|
+
|
|
48
|
+
return _estimateGas(args)
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}, etherscan.fetchBalance)
|
|
51
|
+
const fetchEthereumBalance = async (address, contractAddress = 'value') => {
|
|
52
|
+
const balances = await ethServer.getBalance(address)
|
|
53
|
+
return get(balances, ['confirmed', contractAddress], '0')
|
|
54
|
+
}
|
|
45
55
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
const fetchEthereumClassicBalance = async (address) => {
|
|
57
|
+
const balances = await etcServer.getBalance(address)
|
|
58
|
+
return get(balances, 'confirmed.value', '0')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Only Ethereum and Ethereumclassic, not ERC20
|
|
62
|
+
export async function getBalance({ asset, address }) {
|
|
63
|
+
const _getBalance =
|
|
64
|
+
asset.name === 'ethereumclassic'
|
|
65
|
+
? withFallback(fetchEthereumClassicBalance, fetchEthereumClassicBalance)
|
|
66
|
+
: withFallback(fetchEthereumBalance, etherscan.fetchBalance)
|
|
50
67
|
|
|
51
|
-
return (
|
|
68
|
+
return _getBalance(address)
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
// Only Ethereum ERC20, not Ethereumclassic
|
|
55
72
|
export async function getTokenBalance({ asset, address }) {
|
|
56
|
-
const
|
|
73
|
+
const _getTokenBalance = withFallback(
|
|
74
|
+
async (contractAddress, address) => fetchEthereumBalance(address, contractAddress),
|
|
75
|
+
etherscan.tokenBalance
|
|
76
|
+
)
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return get(balances, ['confirmed', contractAddress], '0')
|
|
61
|
-
}, etherscan.tokenBalance)(contractAddress, address)
|
|
78
|
+
const contractAddress = asset.contract.addresses.current.toLowerCase()
|
|
79
|
+
return _getTokenBalance(contractAddress, address)
|
|
62
80
|
}
|
|
63
81
|
|
|
64
82
|
// Returns function for supplied asset
|
|
65
83
|
export function sendRawTransaction(asset) {
|
|
66
|
-
return asset.name === '
|
|
67
|
-
? withFallback(
|
|
68
|
-
:
|
|
84
|
+
return asset.name === 'ethereumclassic'
|
|
85
|
+
? withFallback(etcServer.sendRawTransaction, etcServer.sendRawTransaction)
|
|
86
|
+
: withFallback(ethServer.sendRawTransaction, etherscan.sendRawTransaction)
|
|
69
87
|
}
|