@exodus/ethereum-api 4.0.2-alpha1 → 4.0.3-alpha1
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": "4.0.
|
|
3
|
+
"version": "4.0.3-alpha1",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@exodus/asset-lib": "^3.7.1",
|
|
18
18
|
"@exodus/crypto": "^1.0.0-rc.0",
|
|
19
|
-
"@exodus/ethereum-lib": "^2.26.1-
|
|
19
|
+
"@exodus/ethereum-lib": "^2.26.1-alpha2",
|
|
20
20
|
"@exodus/ethereumjs-util": "^7.1.0-exodus.6",
|
|
21
21
|
"@exodus/fetch": "^1.2.1",
|
|
22
22
|
"@exodus/simple-retry": "^0.0.6",
|
|
@@ -152,10 +152,13 @@ export default class ClarityServer extends EventEmitter {
|
|
|
152
152
|
|
|
153
153
|
async sendRequest(request) {
|
|
154
154
|
const response = await this.sendRpcRequest(request)
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
const result = response?.result
|
|
156
|
+
const error = response?.error
|
|
157
|
+
if (error || !result) {
|
|
158
|
+
const message = error?.message || error?.code || 'no result'
|
|
159
|
+
throw new Error(`Bad rpc response: ${message}`)
|
|
157
160
|
}
|
|
158
|
-
return
|
|
161
|
+
return result
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
async isContract(address) {
|
package/src/gas-estimation.js
CHANGED
|
@@ -61,7 +61,10 @@ export async function fetchGasLimit({
|
|
|
61
61
|
|
|
62
62
|
const _isToken = isToken(asset)
|
|
63
63
|
if (_isToken) {
|
|
64
|
-
|
|
64
|
+
// only create tx-input only if not pass tx-input to a token asset
|
|
65
|
+
if (txInput === '0x') {
|
|
66
|
+
txInput = ethUtil.bufferToHex(asset.contract.transfer.build(toAddress, amount.toBaseString()))
|
|
67
|
+
}
|
|
65
68
|
amount = asset.baseAsset.currency.ZERO
|
|
66
69
|
toAddress = asset.contract.address
|
|
67
70
|
} else if (!isContract && !['ethereumarbone', 'ethereumarbnova'].includes(asset.name)) {
|
package/src/get-balances.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRpcBalanceAsset } from '@exodus/ethereum-lib'
|
|
1
|
+
import { ETHEREUM_LIKE_MONITOR_TYPES, isRpcBalanceAsset } from '@exodus/ethereum-lib'
|
|
2
2
|
|
|
3
3
|
const fixBalance = ({ txLog, balance }) => {
|
|
4
4
|
for (const tx of txLog) {
|
|
@@ -23,7 +23,10 @@ const fixBalance = ({ txLog, balance }) => {
|
|
|
23
23
|
* @returns {{balance}|null} an object with the balance or null if the balance is unknown/zero
|
|
24
24
|
*/
|
|
25
25
|
export const getBalances = ({ asset, txLog, accountState }) => {
|
|
26
|
-
if (
|
|
26
|
+
if (
|
|
27
|
+
isRpcBalanceAsset(asset) ||
|
|
28
|
+
ETHEREUM_LIKE_MONITOR_TYPES[asset.baseAsset.name] === 'no-history'
|
|
29
|
+
) {
|
|
27
30
|
const balance =
|
|
28
31
|
asset.baseAsset.name === asset.name
|
|
29
32
|
? accountState?.balance
|
|
@@ -20,8 +20,8 @@ export default function getLogItemsFromServerTx({
|
|
|
20
20
|
const confirmations = isConfirmedServerTx(serverTx) ? 1 : 0
|
|
21
21
|
const date = parseServerTxDate(serverTx.timestamp) // included even for unconfirmed txs
|
|
22
22
|
const txId = serverTx.hash
|
|
23
|
-
const nonce = parseInt(serverTx.nonce,
|
|
24
|
-
const gasLimit = parseInt(serverTx.gas,
|
|
23
|
+
const nonce = parseInt(serverTx.nonce, 10)
|
|
24
|
+
const gasLimit = parseInt(serverTx.gas, 10)
|
|
25
25
|
const error = serverTx.error || (serverTx.status === '0' ? 'Failed' : null)
|
|
26
26
|
const feeAmount = getFeeAmount(asset, serverTx)
|
|
27
27
|
const internalTransfers = filterEffects(serverTx.effects, 'internal') || []
|
|
@@ -4,10 +4,9 @@ import { Tx } from '@exodus/models'
|
|
|
4
4
|
|
|
5
5
|
import { getDeriveDataNeededForTick, getDeriveTransactionsToCheck } from './monitor-utils'
|
|
6
6
|
|
|
7
|
-
import { isEmpty, unionBy } from 'lodash'
|
|
7
|
+
import { isEmpty, unionBy, zipObject } from 'lodash'
|
|
8
8
|
|
|
9
9
|
import { BaseMonitor } from '@exodus/asset-lib'
|
|
10
|
-
import { getAssetAddresses } from '@exodus/ethereum-lib'
|
|
11
10
|
|
|
12
11
|
import { UNCONFIRMED_TX_LIMIT } from './monitor-utils/get-derive-transactions-to-check'
|
|
13
12
|
|
|
@@ -97,6 +96,17 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
async getTransactionsFromNode(transactions) {
|
|
100
|
+
const batch = []
|
|
101
|
+
for (const { tx } of transactions) {
|
|
102
|
+
const request = this.server.getTransactionByHashRequest(tx.txId)
|
|
103
|
+
batch.push(request)
|
|
104
|
+
}
|
|
105
|
+
const responses = await this.server.sendBatchRequest(batch)
|
|
106
|
+
const txIds = transactions.map(({ tx }) => tx.txId)
|
|
107
|
+
return zipObject(txIds, responses)
|
|
108
|
+
}
|
|
109
|
+
|
|
100
110
|
async checkPendingTransactions({
|
|
101
111
|
pendingTransactionsGroupedByAddressAndNonce,
|
|
102
112
|
pendingTransactionsToCheck,
|
|
@@ -118,16 +128,7 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
118
128
|
txsToRemove,
|
|
119
129
|
}
|
|
120
130
|
|
|
121
|
-
const
|
|
122
|
-
for (const { tx } of pendingTransactions) {
|
|
123
|
-
const request = this.server.getTransactionByHashRequest(tx.txId)
|
|
124
|
-
batch.push(request)
|
|
125
|
-
}
|
|
126
|
-
const responses = await this.server.sendBatchRequest(batch)
|
|
127
|
-
const txsFromNode = {}
|
|
128
|
-
responses.forEach(
|
|
129
|
-
(response, index) => (txsFromNode[pendingTransactions[index].tx.txId] = response)
|
|
130
|
-
)
|
|
131
|
+
const txsFromNode = await this.getTransactionsFromNode(pendingTransactions)
|
|
131
132
|
|
|
132
133
|
for (const { tx, assetName } of pendingTransactions) {
|
|
133
134
|
const txFromNode = txsFromNode[tx.txId]
|
|
@@ -138,7 +139,7 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
138
139
|
})
|
|
139
140
|
} else if (txFromNode.blockHash !== null) {
|
|
140
141
|
txsToUpdate.push({
|
|
141
|
-
tx,
|
|
142
|
+
tx: { ...tx, confirmations: 1 },
|
|
142
143
|
assetSource: { asset: assetName, walletAccount },
|
|
143
144
|
})
|
|
144
145
|
}
|
|
@@ -153,11 +154,6 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
153
154
|
async tick({ refresh, walletAccount }) {
|
|
154
155
|
const assets = await this.aci.getAssetsForNetwork({ baseAssetName: this.asset.name })
|
|
155
156
|
const tokens = Object.values(assets).filter((asset) => asset.baseAsset.name !== asset.name)
|
|
156
|
-
const tokensByAddress = tokens.reduce((map, token) => {
|
|
157
|
-
const addresses = getAssetAddresses(token)
|
|
158
|
-
for (const address of addresses) map.set(address.toLowerCase(), token)
|
|
159
|
-
return map
|
|
160
|
-
}, new Map())
|
|
161
157
|
|
|
162
158
|
const assetSource = { assetName: this.asset.name, walletAccount }
|
|
163
159
|
|
|
@@ -181,12 +177,12 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
181
177
|
walletAccount,
|
|
182
178
|
})
|
|
183
179
|
|
|
184
|
-
const
|
|
185
|
-
const logItemsByAsset = Object.fromEntries(allAssets.map((asset) => [asset.name, []]))
|
|
180
|
+
const logItemsByAsset = {}
|
|
186
181
|
|
|
187
182
|
txsToUpdate.forEach((txToUpdate) => {
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
logItemsByAsset[txToUpdate.assetSource.asset] =
|
|
184
|
+
logItemsByAsset[txToUpdate.assetSource.asset] || []
|
|
185
|
+
logItemsByAsset[txToUpdate.assetSource.asset].push(Tx.fromJSON(txToUpdate.tx))
|
|
190
186
|
})
|
|
191
187
|
|
|
192
188
|
await this.updateAccountState({ newData: { ...accountState }, walletAccount })
|