@exodus/ethereum-api 0.2.1 → 0.2.4
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": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"access": "restricted"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@exodus/ethereum-lib": "^0.2.
|
|
13
|
+
"@exodus/ethereum-lib": "^0.2.4",
|
|
14
14
|
"fetchival": "0.3.3",
|
|
15
15
|
"make-concurrent": "4.0.0",
|
|
16
16
|
"ms": "^2.1.1",
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"url-join": "4.0.0",
|
|
19
19
|
"ws": "6.1.0"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "bcaf797f81e5f31a8b15cd2c2efdf6a1ee4c8e65"
|
|
22
22
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { etc as etcServer } from './exodus-eth-server'
|
|
2
|
+
import { withFallback } from './with-fallback'
|
|
3
|
+
|
|
4
|
+
export const isContract = async (address) => {
|
|
5
|
+
const code = await withFallback(etcServer.getCode, etcServer.getCode)(address)
|
|
6
|
+
return code.length > 2
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const sendRawTransaction = withFallback(
|
|
10
|
+
etcServer.sendRawTransaction,
|
|
11
|
+
etcServer.sendRawTransaction
|
|
12
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { eth as ethServer } from './exodus-eth-server'
|
|
2
|
+
import { withFallback } from './with-fallback'
|
|
3
|
+
import * as etherscan from './etherscan'
|
|
4
|
+
|
|
5
|
+
export const isContract = async (address) => {
|
|
6
|
+
const code = await withFallback(ethServer.getCode, etherscan.getCode)(address)
|
|
7
|
+
return code.length > 2
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const sendRawTransaction = withFallback(
|
|
11
|
+
ethServer.sendRawTransaction,
|
|
12
|
+
etherscan.sendRawTransaction
|
|
13
|
+
)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
|
|
2
|
-
import { eth as ethServer
|
|
2
|
+
import { eth as ethServer } from '../exodus-eth-server'
|
|
3
|
+
import { withFallback } from '../with-fallback'
|
|
4
|
+
import * as etherscan from '../etherscan'
|
|
3
5
|
|
|
4
|
-
export class
|
|
6
|
+
export class EthereumFeeMonitor extends EthereumLikeFeeMonitor {
|
|
5
7
|
constructor({ updateFee }) {
|
|
6
8
|
super({
|
|
7
9
|
updateFee,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EthereumLikeFeeMonitor } from '@exodus/ethereum-lib'
|
|
2
|
-
import { etc as etcServer } from '
|
|
2
|
+
import { etc as etcServer } from '../exodus-eth-server'
|
|
3
3
|
|
|
4
|
-
export class
|
|
4
|
+
export class EthereumClassicFeeMonitor extends EthereumLikeFeeMonitor {
|
|
5
5
|
constructor({ updateFee }) {
|
|
6
6
|
super({
|
|
7
7
|
updateFee,
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as etherscan from './etherscan'
|
|
2
|
+
import * as ethWithFallback from './eth-with-fallback'
|
|
3
|
+
import * as etcWithFallback from './etc-with-fallback'
|
|
2
4
|
|
|
3
5
|
export * from './with-fallback'
|
|
4
6
|
export * from './fee-monitor'
|
|
5
7
|
export * from './exodus-eth-server'
|
|
6
|
-
export { etherscan }
|
|
8
|
+
export { etherscan, ethWithFallback, etcWithFallback }
|
package/src/with-fallback.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { _isEthereumToken } from '@exodus/ethereum-lib'
|
|
2
|
+
import { eth as ethServer, etc as etcServer } from './exodus-eth-server'
|
|
3
|
+
import * as etherscan from './etherscan'
|
|
4
|
+
|
|
1
5
|
export function withFallback(fn, fn2) {
|
|
2
6
|
return async (...args) => {
|
|
3
7
|
try {
|
|
@@ -12,3 +16,53 @@ export function withFallback(fn, fn2) {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
}
|
|
19
|
+
|
|
20
|
+
export async function getNonce({ asset, address }) {
|
|
21
|
+
if (!['ethereum', 'ethereumclassic'].includes(asset.name)) return
|
|
22
|
+
|
|
23
|
+
const _getNonce =
|
|
24
|
+
asset.name === 'ethereum'
|
|
25
|
+
? withFallback(ethServer.getTransactionCount, etherscan.getTransactionCount)
|
|
26
|
+
: etcServer.getTransactionCount
|
|
27
|
+
|
|
28
|
+
const nonce = await _getNonce(address)
|
|
29
|
+
return parseInt(nonce, 16)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function estimateGas({ asset, ...args }) {
|
|
33
|
+
const useEthServer: boolean = asset.name === 'ethereum' || _isEthereumToken(asset)
|
|
34
|
+
return (useEthServer
|
|
35
|
+
? withFallback(ethServer.estimateGas, etherscan.estimateGas)
|
|
36
|
+
: etcServer.estimateGas)(args)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function getBalance({ asset, address }) {
|
|
40
|
+
const fetchEthereumBalance = withFallback(async (address) => {
|
|
41
|
+
const balances = await ethServer.getBalance(address)
|
|
42
|
+
return balances?.confirmed?.value || '0'
|
|
43
|
+
}, etherscan.fetchBalance)
|
|
44
|
+
|
|
45
|
+
const fetchEthereumClassicBalance = async (address) => {
|
|
46
|
+
const balances = await etcServer.getBalance(address)
|
|
47
|
+
return balances?.confirmed?.value || '0'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (asset.name === 'ethereum' ? fetchEthereumBalance : fetchEthereumClassicBalance)(address)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Only Ethereum ERC20, not Ethereumclassic
|
|
54
|
+
export async function getTokenBalance({ asset, address }) {
|
|
55
|
+
const contractAddress = asset.contract.addresses.current.toLowerCase()
|
|
56
|
+
|
|
57
|
+
return withFallback(async (contractAddress, address) => {
|
|
58
|
+
const balances = await ethServer.getBalance(address)
|
|
59
|
+
return balances?.confirmed?.[contractAddress] || '0'
|
|
60
|
+
}, etherscan.tokenBalance)(contractAddress, address)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Returns function for supplied asset
|
|
64
|
+
export function sendRawTransaction(asset) {
|
|
65
|
+
return asset.name === 'ethereum' || _isEthereumToken(asset)
|
|
66
|
+
? withFallback(ethServer.sendRawTransaction, etherscan.sendRawTransaction)
|
|
67
|
+
: etcServer.sendRawTransaction
|
|
68
|
+
}
|