@exodus/ethereum-api 4.0.3-alpha1 → 4.0.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": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
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",
|
|
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",
|
package/src/get-balances.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isRpcBalanceAsset } from '@exodus/ethereum-lib'
|
|
2
2
|
|
|
3
3
|
const fixBalance = ({ txLog, balance }) => {
|
|
4
4
|
for (const tx of txLog) {
|
|
@@ -23,10 +23,7 @@ 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 (
|
|
27
|
-
isRpcBalanceAsset(asset) ||
|
|
28
|
-
ETHEREUM_LIKE_MONITOR_TYPES[asset.baseAsset.name] === 'no-history'
|
|
29
|
-
) {
|
|
26
|
+
if (isRpcBalanceAsset(asset)) {
|
|
30
27
|
const balance =
|
|
31
28
|
asset.baseAsset.name === asset.name
|
|
32
29
|
? accountState?.balance
|
|
@@ -76,24 +76,24 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
76
76
|
async deriveData({ assetSource, tokens }) {
|
|
77
77
|
const { assetName, walletAccount } = assetSource
|
|
78
78
|
|
|
79
|
+
const { ourWalletAddress } = await this.deriveDataNeededForTick({ assetName, walletAccount })
|
|
79
80
|
const {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} = await this.deriveDataNeededForTick({ assetName, walletAccount })
|
|
84
|
-
const transactionsToCheck = await this.deriveTransactionsToCheck({
|
|
81
|
+
pendingTransactionsGroupedByAddressAndNonce,
|
|
82
|
+
pendingTransactionsToCheck,
|
|
83
|
+
} = await this.deriveTransactionsToCheck({
|
|
85
84
|
assetName,
|
|
86
85
|
walletAccount,
|
|
87
86
|
tokens,
|
|
88
87
|
ourWalletAddress,
|
|
89
88
|
})
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
const pendingTransactions = unionBy(
|
|
91
|
+
Object.values(pendingTransactionsGroupedByAddressAndNonce),
|
|
92
|
+
Object.values(pendingTransactionsToCheck),
|
|
93
|
+
'tx.txId'
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
return { ourWalletAddress, pendingTransactions }
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
async getTransactionsFromNode(transactions) {
|
|
@@ -107,37 +107,25 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
107
107
|
return zipObject(txIds, responses)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
async checkPendingTransactions({
|
|
111
|
-
pendingTransactionsGroupedByAddressAndNonce,
|
|
112
|
-
pendingTransactionsToCheck,
|
|
113
|
-
walletAccount,
|
|
114
|
-
}) {
|
|
110
|
+
async checkPendingTransactions({ pendingTransactions, pendingTxsFromNode, walletAccount }) {
|
|
115
111
|
const txsToUpdate = []
|
|
116
112
|
const txsToRemove = []
|
|
117
113
|
const now = Date.now()
|
|
118
114
|
|
|
119
|
-
const pendingTransactions = unionBy(
|
|
120
|
-
Object.values(pendingTransactionsGroupedByAddressAndNonce),
|
|
121
|
-
Object.values(pendingTransactionsToCheck),
|
|
122
|
-
'tx.txId'
|
|
123
|
-
)
|
|
124
|
-
|
|
125
115
|
if (isEmpty(pendingTransactions))
|
|
126
116
|
return {
|
|
127
117
|
txsToUpdate,
|
|
128
118
|
txsToRemove,
|
|
129
119
|
}
|
|
130
120
|
|
|
131
|
-
const txsFromNode = await this.getTransactionsFromNode(pendingTransactions)
|
|
132
|
-
|
|
133
121
|
for (const { tx, assetName } of pendingTransactions) {
|
|
134
|
-
const txFromNode =
|
|
135
|
-
if (now - tx.date.getTime() > UNCONFIRMED_TX_LIMIT) {
|
|
122
|
+
const txFromNode = pendingTxsFromNode[tx.txId]
|
|
123
|
+
if (now - tx.date.getTime() > UNCONFIRMED_TX_LIMIT && txFromNode?.blockHash == null) {
|
|
136
124
|
txsToRemove.push({
|
|
137
125
|
tx,
|
|
138
126
|
assetSource: { asset: assetName, walletAccount },
|
|
139
127
|
})
|
|
140
|
-
} else if (txFromNode
|
|
128
|
+
} else if (txFromNode?.blockHash !== null) {
|
|
141
129
|
txsToUpdate.push({
|
|
142
130
|
tx: { ...tx, confirmations: 1 },
|
|
143
131
|
assetSource: { asset: assetName, walletAccount },
|
|
@@ -157,32 +145,30 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
157
145
|
|
|
158
146
|
const assetSource = { assetName: this.asset.name, walletAccount }
|
|
159
147
|
|
|
160
|
-
const {
|
|
161
|
-
ourWalletAddress,
|
|
162
|
-
pendingTransactionsGroupedByAddressAndNonce,
|
|
163
|
-
pendingTransactionsToCheck,
|
|
164
|
-
} = await this.deriveData({
|
|
148
|
+
const { ourWalletAddress, pendingTransactions } = await this.deriveData({
|
|
165
149
|
assetSource,
|
|
166
150
|
tokens,
|
|
167
151
|
})
|
|
168
152
|
|
|
169
|
-
const
|
|
170
|
-
tokens,
|
|
171
|
-
ourWalletAddress,
|
|
172
|
-
})
|
|
153
|
+
const pendingTxsFromNode = await this.getTransactionsFromNode(pendingTransactions)
|
|
173
154
|
|
|
174
155
|
const { txsToUpdate, txsToRemove } = await this.checkPendingTransactions({
|
|
175
|
-
|
|
176
|
-
|
|
156
|
+
pendingTransactions,
|
|
157
|
+
pendingTxsFromNode,
|
|
177
158
|
walletAccount,
|
|
178
159
|
})
|
|
179
160
|
|
|
180
161
|
const logItemsByAsset = {}
|
|
181
162
|
|
|
182
163
|
txsToUpdate.forEach((txToUpdate) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
logItemsByAsset[
|
|
164
|
+
const assetName = txToUpdate.assetSource.asset
|
|
165
|
+
logItemsByAsset[assetName] = logItemsByAsset[assetName] || []
|
|
166
|
+
logItemsByAsset[assetName].push(Tx.fromJSON(txToUpdate.tx))
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const accountState = await this.getNewAccountState({
|
|
170
|
+
tokens,
|
|
171
|
+
ourWalletAddress,
|
|
186
172
|
})
|
|
187
173
|
|
|
188
174
|
await this.updateAccountState({ newData: { ...accountState }, walletAccount })
|