@exodus/bitcoin-plugin 1.8.2-hotfix → 1.8.2
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 +3 -2
- package/src/compatibility-modes.js +2 -5
- package/src/create-asset.js +261 -259
- package/src/fee-data.js +1 -1
- package/src/fee-monitor.js +7 -3
- package/src/index.js +0 -1
- package/src/ordinals/brc-20-client.js +2 -4
- package/src/ordinals/brc-20-utils.js +1 -1
- package/src/ordinals/create-token-factory.js +1 -2
- package/src/ordinals/inscriptions-service.js +4 -6
- package/src/ordinals/nft-utils.js +1 -3
- package/src/ordinals/nfts.js +32 -37
- package/src/ordinals/ordinals-constants.js +1 -1
- package/src/ordinals/reload-brc20-token-balances.js +27 -25
- package/src/ordinals/tick-inscription-id-indexer.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.8.2
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -47,5 +47,6 @@
|
|
|
47
47
|
"@exodus/nfts-proxy": "^2.10.1",
|
|
48
48
|
"@scure/btc-signer": "^1.1.0",
|
|
49
49
|
"jest-when": "^3.5.1"
|
|
50
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "b282e5087dda77c80fc63947ccc0020e6aa7db93"
|
|
51
52
|
}
|
|
@@ -6,17 +6,16 @@ export const trezor = 'trezor'
|
|
|
6
6
|
export const ledger = 'ledger'
|
|
7
7
|
export const xverse49 = 'xverse49'
|
|
8
8
|
|
|
9
|
-
export const getDefaultAddressPath = ({ compatibilityMode }
|
|
9
|
+
export const getDefaultAddressPath = ({ compatibilityMode }) => {
|
|
10
10
|
if ([ordinals84, ordinals86].includes(compatibilityMode)) {
|
|
11
11
|
return 'm/0'
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
return 'm/0/0'
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export const getSupportedPurposes = ({ compatibilityMode, walletAccount }) => {
|
|
18
17
|
if (walletAccount?.source === WalletAccount.TREZOR_SRC || compatibilityMode === trezor) {
|
|
19
|
-
return [84, 49
|
|
18
|
+
return [84, 49]
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
if (compatibilityMode === ledger) {
|
|
@@ -26,11 +25,9 @@ export const getSupportedPurposes = ({ compatibilityMode, walletAccount }) => {
|
|
|
26
25
|
if (compatibilityMode === ordinals84) {
|
|
27
26
|
return [84, 86, 44]
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
if (compatibilityMode === ordinals86) {
|
|
31
29
|
return [86, 84, 44]
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
if (compatibilityMode === xverse49) {
|
|
35
32
|
return [49, 84, 86, 44]
|
|
36
33
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -35,287 +35,289 @@ import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
|
|
|
35
35
|
import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
|
|
36
36
|
import { getDefaultAddressPath, getSupportedPurposes } from './compatibility-modes'
|
|
37
37
|
|
|
38
|
-
export const createBitcoinAssetFactory =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
38
|
+
export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) => ({
|
|
39
|
+
apiUrl: customApiUrl,
|
|
40
|
+
allowUnconfirmedRbfEnabledUtxos = false,
|
|
41
|
+
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
42
|
+
ordinalsEnabled = false,
|
|
43
|
+
brc20Enabled = false,
|
|
44
|
+
gapLimit = 10,
|
|
45
|
+
refreshGapLimit = 25,
|
|
46
|
+
overrideCallback = ({ asset }) => asset,
|
|
47
|
+
feeDataCustomValues,
|
|
48
|
+
} = {}) => {
|
|
49
|
+
const apiUrl = customApiUrl || defaultApiUrl
|
|
50
|
+
assert(asset, 'asset is required')
|
|
51
|
+
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
52
|
+
assert(apiUrl, 'apiUrl is required')
|
|
53
|
+
assert(
|
|
54
|
+
brc20Enabled ? ordinalsEnabled : true,
|
|
55
|
+
'if brc20Enabled is true then ordinalsEnabled must be true'
|
|
56
|
+
)
|
|
57
|
+
const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
|
|
58
|
+
|
|
59
|
+
const insightClient = new InsightAPIClient(apiUrl)
|
|
60
|
+
|
|
61
|
+
if (customApiUrl) insightClient.setBaseUrl = () => {} // not let the configuration override url when providing a custom one
|
|
62
|
+
|
|
63
|
+
const useBip84 = true
|
|
64
|
+
const useBip86 = true
|
|
65
|
+
|
|
66
|
+
const versions = getBtcVersions(coinInfo)
|
|
67
|
+
const address = createBtcLikeAddress({
|
|
68
|
+
versions,
|
|
69
|
+
coinInfo,
|
|
70
|
+
useBip86,
|
|
71
|
+
bitcoinjsLib,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const keys = createBtcLikeKeys({ coinInfo, versions, useBip86 })
|
|
75
|
+
const bip44 = bip44Constants['BTC']
|
|
76
|
+
|
|
77
|
+
const allowedPurposes = [44, 49, 84, 86]
|
|
78
|
+
|
|
79
|
+
const useMultipleAddresses = true
|
|
80
|
+
|
|
81
|
+
const features = {
|
|
82
|
+
accountState: true,
|
|
83
|
+
feeMonitor: true,
|
|
84
|
+
feesApi: true,
|
|
85
|
+
moveFunds: true,
|
|
86
|
+
multipleAddresses: true,
|
|
87
|
+
nfts: ordinalsEnabled,
|
|
88
|
+
customTokens: brc20Enabled,
|
|
89
|
+
}
|
|
67
90
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
const getFeeEstimator = getFeeEstimatorFactory({
|
|
92
|
+
defaultOutputType: 'P2WSH',
|
|
93
|
+
addressApi: address,
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const baseFeeResolver = new GetFeeResolver({
|
|
97
|
+
getFeeEstimator,
|
|
98
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const feeData = bitcoinFeeDataFactory({
|
|
102
|
+
currency: asset.currency,
|
|
103
|
+
overrideDefaults: feeDataCustomValues,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const baseGetBalances = getBalancesFactory({
|
|
107
|
+
feeData,
|
|
108
|
+
getSpendableBalance: baseFeeResolver.getSpendableBalance,
|
|
109
|
+
ordinalsEnabled,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const brc20Client = brc20Enabled ? brc20ApiClientFactory() : undefined
|
|
113
|
+
const tickInscriptionIdIndexer = brc20Enabled
|
|
114
|
+
? tickInscriptionIdIndexerFactory({ brc20Client })
|
|
115
|
+
: undefined
|
|
116
|
+
|
|
117
|
+
const baseSendTx = createAndBroadcastTXFactory({
|
|
118
|
+
getFeeEstimator,
|
|
119
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
120
|
+
ordinalsEnabled,
|
|
121
|
+
})
|
|
122
|
+
const inscriptionsService = brc20Enabled
|
|
123
|
+
? inscriptionsServiceFactory({
|
|
124
|
+
asset,
|
|
125
|
+
network: coinInfo.toBitcoinJS(),
|
|
126
|
+
ordinalChainIndex,
|
|
127
|
+
})
|
|
128
|
+
: undefined
|
|
129
|
+
|
|
130
|
+
const {
|
|
131
|
+
getFee,
|
|
132
|
+
getBalances,
|
|
133
|
+
getAvailableBalance,
|
|
134
|
+
canBumpTx,
|
|
135
|
+
getSpendableBalance,
|
|
136
|
+
sendTx,
|
|
137
|
+
} = brc20Enabled
|
|
138
|
+
? brc20BalancesAndFeeAdapterFactory({
|
|
139
|
+
inscriptionsService,
|
|
140
|
+
...baseFeeResolver,
|
|
141
|
+
getBalances: baseGetBalances,
|
|
142
|
+
sendTx: baseSendTx,
|
|
143
|
+
tickInscriptionIdIndexer,
|
|
144
|
+
})
|
|
145
|
+
: { ...baseFeeResolver, getBalances: baseGetBalances, sendTx: baseSendTx }
|
|
146
|
+
|
|
147
|
+
const signTx = signTxFactory({
|
|
148
|
+
assetName: asset.name,
|
|
149
|
+
resolvePurpose: address.resolvePurpose,
|
|
150
|
+
keys,
|
|
151
|
+
coinInfo,
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
const signHardware = signHardwareFactory({
|
|
155
|
+
assetName: asset.name,
|
|
156
|
+
resolvePurpose: address.resolvePurpose,
|
|
157
|
+
keys,
|
|
158
|
+
coinInfo,
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const moveFunds = moveFundsFactory({
|
|
162
|
+
asset: asset,
|
|
163
|
+
insightClient,
|
|
164
|
+
getFeeEstimator,
|
|
165
|
+
address,
|
|
166
|
+
signTx,
|
|
167
|
+
getAddressesFromPrivateKey: getAddressesFromPrivateKeyFactory({
|
|
168
|
+
purposes: allowedPurposes,
|
|
169
|
+
keys,
|
|
71
170
|
coinInfo,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const keys = createBtcLikeKeys({ coinInfo, versions, useBip86 })
|
|
77
|
-
const bip44 = bip44Constants['BTC']
|
|
78
|
-
|
|
79
|
-
const allowedPurposes = [44, 49, 84, 86]
|
|
171
|
+
}),
|
|
172
|
+
})
|
|
80
173
|
|
|
81
|
-
|
|
174
|
+
const accountStateClass = createAccountState({ asset: asset, ordinalsEnabled, brc20Enabled })
|
|
82
175
|
|
|
83
|
-
|
|
84
|
-
accountState: true,
|
|
85
|
-
feeMonitor: true,
|
|
86
|
-
feesApi: true,
|
|
87
|
-
moveFunds: true,
|
|
88
|
-
multipleAddresses: true,
|
|
89
|
-
nfts: ordinalsEnabled,
|
|
90
|
-
customTokens: brc20Enabled,
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const getFeeEstimator = getFeeEstimatorFactory({
|
|
94
|
-
defaultOutputType: 'P2WSH',
|
|
95
|
-
addressApi: address,
|
|
96
|
-
})
|
|
176
|
+
const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset }) : undefined
|
|
97
177
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})
|
|
178
|
+
const { createToken, getTokens, validateAssetId } = brc20Enabled
|
|
179
|
+
? createTokenFactory({ address, bip44, keys, getBalances }, [])
|
|
180
|
+
: {}
|
|
102
181
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const baseGetBalances = getBalancesFactory({
|
|
109
|
-
feeData,
|
|
110
|
-
getSpendableBalance: baseFeeResolver.getSpendableBalance,
|
|
182
|
+
const createHistoryMonitor = (args) => {
|
|
183
|
+
const monitor = createBitcoinMonitor({
|
|
184
|
+
insightClient,
|
|
111
185
|
ordinalsEnabled,
|
|
186
|
+
ordinalChainIndex,
|
|
187
|
+
apiUrl,
|
|
188
|
+
gapLimit,
|
|
189
|
+
refreshGapLimit,
|
|
190
|
+
...args,
|
|
112
191
|
})
|
|
192
|
+
const assetClientInterface = args.assetClientInterface
|
|
193
|
+
if (ordinalsEnabled) {
|
|
194
|
+
nfts.initialize({ assetClientInterface })
|
|
195
|
+
}
|
|
113
196
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const baseSendTx = createAndBroadcastTXFactory({
|
|
120
|
-
getFeeEstimator,
|
|
121
|
-
allowUnconfirmedRbfEnabledUtxos,
|
|
122
|
-
ordinalsEnabled,
|
|
123
|
-
})
|
|
124
|
-
const inscriptionsService = brc20Enabled
|
|
125
|
-
? inscriptionsServiceFactory({
|
|
197
|
+
if (brc20Enabled) {
|
|
198
|
+
monitor.addHook('after-tick', async ({ walletAccount }) => {
|
|
199
|
+
const { unknownDeployInscriptionIds } = await reloadBrc20TokenBalances({
|
|
200
|
+
walletAccount,
|
|
126
201
|
asset,
|
|
127
|
-
network: coinInfo.toBitcoinJS(),
|
|
128
202
|
ordinalChainIndex,
|
|
203
|
+
brc20Client,
|
|
204
|
+
assetClientInterface,
|
|
205
|
+
tickInscriptionIdIndexer,
|
|
129
206
|
})
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
brc20Enabled
|
|
134
|
-
? brc20BalancesAndFeeAdapterFactory({
|
|
135
|
-
inscriptionsService,
|
|
136
|
-
...baseFeeResolver,
|
|
137
|
-
getBalances: baseGetBalances,
|
|
138
|
-
sendTx: baseSendTx,
|
|
139
|
-
tickInscriptionIdIndexer,
|
|
140
|
-
})
|
|
141
|
-
: { ...baseFeeResolver, getBalances: baseGetBalances, sendTx: baseSendTx }
|
|
142
|
-
|
|
143
|
-
const signTx = signTxFactory({
|
|
144
|
-
assetName: asset.name,
|
|
145
|
-
resolvePurpose: address.resolvePurpose,
|
|
146
|
-
keys,
|
|
147
|
-
coinInfo,
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
const signHardware = signHardwareFactory({
|
|
151
|
-
assetName: asset.name,
|
|
152
|
-
resolvePurpose: address.resolvePurpose,
|
|
153
|
-
keys,
|
|
154
|
-
coinInfo,
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
const moveFunds = moveFundsFactory({
|
|
158
|
-
asset,
|
|
159
|
-
insightClient,
|
|
160
|
-
getFeeEstimator,
|
|
161
|
-
address,
|
|
162
|
-
signTx,
|
|
163
|
-
getAddressesFromPrivateKey: getAddressesFromPrivateKeyFactory({
|
|
164
|
-
purposes: allowedPurposes,
|
|
165
|
-
keys,
|
|
166
|
-
coinInfo,
|
|
167
|
-
}),
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
const accountStateClass = createAccountState({ asset, ordinalsEnabled, brc20Enabled })
|
|
171
|
-
|
|
172
|
-
const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset }) : undefined
|
|
173
|
-
|
|
174
|
-
const { createToken, getTokens, validateAssetId } = brc20Enabled
|
|
175
|
-
? createTokenFactory({ address, bip44, keys, getBalances }, [])
|
|
176
|
-
: {}
|
|
177
|
-
|
|
178
|
-
const createHistoryMonitor = (args) => {
|
|
179
|
-
const monitor = createBitcoinMonitor({
|
|
180
|
-
insightClient,
|
|
181
|
-
ordinalsEnabled,
|
|
182
|
-
ordinalChainIndex,
|
|
183
|
-
apiUrl,
|
|
184
|
-
gapLimit,
|
|
185
|
-
refreshGapLimit,
|
|
186
|
-
...args,
|
|
207
|
+
if (unknownDeployInscriptionIds.length) {
|
|
208
|
+
monitor.emit('unknown-tokens', unknownDeployInscriptionIds)
|
|
209
|
+
}
|
|
187
210
|
})
|
|
188
|
-
const assetClientInterface = args.assetClientInterface
|
|
189
|
-
if (ordinalsEnabled) {
|
|
190
|
-
nfts.initialize({ assetClientInterface })
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (brc20Enabled) {
|
|
194
|
-
monitor.addHook('after-tick', async ({ walletAccount }) => {
|
|
195
|
-
const { unknownDeployInscriptionIds } = await reloadBrc20TokenBalances({
|
|
196
|
-
walletAccount,
|
|
197
|
-
asset,
|
|
198
|
-
ordinalChainIndex,
|
|
199
|
-
brc20Client,
|
|
200
|
-
assetClientInterface,
|
|
201
|
-
tickInscriptionIdIndexer,
|
|
202
|
-
})
|
|
203
|
-
if (unknownDeployInscriptionIds.length > 0) {
|
|
204
|
-
monitor.emit('unknown-tokens', unknownDeployInscriptionIds)
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return monitor
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const addressHasHistory = async (address) => {
|
|
213
|
-
assert(typeof address === 'string', 'Address is required')
|
|
214
|
-
const result = await insightClient.fetchTxData([address], { from: 0, to: 1 })
|
|
215
|
-
return !!result?.items.length
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const getBalanceForAddress = async (address) => {
|
|
219
|
-
assert(typeof address === 'string', 'Address is required')
|
|
220
|
-
const { balance } = await insightClient.fetchBalance(address)
|
|
221
|
-
return asset.currency.defaultUnit(balance)
|
|
222
211
|
}
|
|
212
|
+
return monitor
|
|
213
|
+
}
|
|
223
214
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
215
|
+
const addressHasHistory = async (address) => {
|
|
216
|
+
assert(typeof address === 'string', 'Address is required')
|
|
217
|
+
const result = await insightClient.fetchTxData([address], { from: 0, to: 1 })
|
|
218
|
+
return !!result?.items.length
|
|
219
|
+
}
|
|
228
220
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
const getBalanceForAddress = async (address) => {
|
|
222
|
+
assert(typeof address === 'string', 'Address is required')
|
|
223
|
+
const { balance } = await insightClient.fetchBalance(address)
|
|
224
|
+
return asset.currency.defaultUnit(balance)
|
|
225
|
+
}
|
|
232
226
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
)
|
|
227
|
+
const isOrdinalTx = (tx) => {
|
|
228
|
+
if (!ordinalsEnabled || tx.coinName !== asset.name) {
|
|
229
|
+
return false
|
|
237
230
|
}
|
|
238
231
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const isWaitingRbf = tx.data && tx.data.replacedBy && tx.pending
|
|
242
|
-
return !isDroppedBitcoinTx && !isWaitingRbf && !isOrdinalTx(tx)
|
|
232
|
+
if (!tx.data.inscriptionsIndexed) {
|
|
233
|
+
return false // allows users seeing the pending tx because we don't know yet if it is ordinals or btc
|
|
243
234
|
}
|
|
244
235
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return tx.data.sent
|
|
251
|
-
.map((to, i) =>
|
|
252
|
-
tx.update({
|
|
253
|
-
to: to.address,
|
|
254
|
-
data: { sentIndex: i },
|
|
255
|
-
coinAmount: to.amount
|
|
256
|
-
? parseCurrency(to.amount, asset.currency).negate()
|
|
257
|
-
: asset.currency.ZERO,
|
|
258
|
-
feeAmount,
|
|
259
|
-
})
|
|
260
|
-
)
|
|
261
|
-
.reverse()
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return tx
|
|
265
|
-
})
|
|
266
|
-
.filter(txLogFilter)
|
|
267
|
-
}
|
|
236
|
+
return (
|
|
237
|
+
tx.data.receivedInscriptions?.some(isValidInscription) ||
|
|
238
|
+
tx.data.sentInscriptions?.some(isValidInscription)
|
|
239
|
+
)
|
|
240
|
+
}
|
|
268
241
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
createFeeMonitor: (args) =>
|
|
275
|
-
new BitcoinFeeMonitor({ ...args, insight: () => insightClient, assetName: asset.name }),
|
|
276
|
-
createHistoryMonitor,
|
|
277
|
-
features,
|
|
278
|
-
getDefaultAddressPath,
|
|
279
|
-
getFeeData: () => feeData,
|
|
280
|
-
getBalances,
|
|
281
|
-
getBalanceForAddress,
|
|
282
|
-
getKeyIdentifier: createGetKeyIdentifier({
|
|
283
|
-
bip44,
|
|
284
|
-
allowedPurposes,
|
|
285
|
-
allowedChainIndices: [0, 1, 2],
|
|
286
|
-
}),
|
|
287
|
-
getSupportedPurposes,
|
|
288
|
-
hasFeature: (feature) => !!features[feature], // @deprecated use api.features instead
|
|
289
|
-
createAccountState: () => accountStateClass,
|
|
290
|
-
parseUnsignedTx,
|
|
291
|
-
parseTx: ({ unsignedTx }) => parseUnsignedTx(unsignedTx),
|
|
292
|
-
signUnsignedTx: (unsignedTx, privateKey, opts) => signTx({ unsignedTx, privateKey, ...opts }), // legacy
|
|
293
|
-
sendTx,
|
|
294
|
-
signTx,
|
|
295
|
-
signHardware,
|
|
296
|
-
getFee,
|
|
297
|
-
moveFunds,
|
|
298
|
-
nfts,
|
|
299
|
-
createToken,
|
|
300
|
-
getTokens,
|
|
301
|
-
validateAssetId,
|
|
302
|
-
}
|
|
242
|
+
const txLogFilter = (tx) => {
|
|
243
|
+
const isDroppedBitcoinTx = tx.dropped
|
|
244
|
+
const isWaitingRbf = tx.data && tx.data.replacedBy && tx.pending
|
|
245
|
+
return !isDroppedBitcoinTx && !isWaitingRbf && !isOrdinalTx(tx)
|
|
246
|
+
}
|
|
303
247
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
248
|
+
const getActivityTxs = ({ txs, asset }) => {
|
|
249
|
+
return txs
|
|
250
|
+
.flatMap((tx) => {
|
|
251
|
+
if (tx.sent && Array.isArray(tx.data.sent) && tx.data.sent.length > 0) {
|
|
252
|
+
const feeAmount = tx.feeAmount.div(tx.data.sent.length)
|
|
253
|
+
return tx.data.sent
|
|
254
|
+
.map((to, i) =>
|
|
255
|
+
tx.update({
|
|
256
|
+
to: to.address,
|
|
257
|
+
data: { sentIndex: i },
|
|
258
|
+
coinAmount: to.amount
|
|
259
|
+
? parseCurrency(to.amount, asset.currency).negate()
|
|
260
|
+
: asset.currency.ZERO,
|
|
261
|
+
feeAmount,
|
|
262
|
+
})
|
|
263
|
+
)
|
|
264
|
+
.reverse()
|
|
265
|
+
}
|
|
266
|
+
return tx
|
|
267
|
+
})
|
|
268
|
+
.filter(txLogFilter)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const api = {
|
|
272
|
+
getActivityTxs,
|
|
273
|
+
addressHasHistory,
|
|
274
|
+
defaultAddressPath: 'm/0/0', // deprecated
|
|
275
|
+
broadcastTx: (...args) => insightClient.broadcastTx(...args),
|
|
276
|
+
createFeeMonitor: (args) =>
|
|
277
|
+
new BitcoinFeeMonitor({ ...args, insight: () => insightClient, assetName: asset.name }),
|
|
278
|
+
createHistoryMonitor,
|
|
279
|
+
features,
|
|
280
|
+
getDefaultAddressPath,
|
|
281
|
+
getFeeData: () => feeData,
|
|
282
|
+
getBalances,
|
|
283
|
+
getBalanceForAddress,
|
|
284
|
+
getKeyIdentifier: createGetKeyIdentifier({
|
|
308
285
|
bip44,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
286
|
+
allowedPurposes,
|
|
287
|
+
allowedChainIndices: [0, 1, 2],
|
|
288
|
+
}),
|
|
289
|
+
getSupportedPurposes,
|
|
290
|
+
hasFeature: (feature) => !!features[feature], // @deprecated use api.features instead
|
|
291
|
+
createAccountState: () => accountStateClass,
|
|
292
|
+
parseUnsignedTx,
|
|
293
|
+
parseTx: ({ unsignedTx }) => parseUnsignedTx(unsignedTx),
|
|
294
|
+
signUnsignedTx: (unsignedTx, privateKey, opts) => signTx({ unsignedTx, privateKey, ...opts }), // legacy
|
|
295
|
+
sendTx,
|
|
296
|
+
signTx,
|
|
297
|
+
signHardware,
|
|
298
|
+
getFee,
|
|
299
|
+
moveFunds,
|
|
300
|
+
nfts,
|
|
301
|
+
createToken,
|
|
302
|
+
getTokens,
|
|
303
|
+
validateAssetId,
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const fullAsset = {
|
|
307
|
+
...asset,
|
|
308
|
+
address,
|
|
309
|
+
api,
|
|
310
|
+
bip44,
|
|
311
|
+
coinInfo,
|
|
312
|
+
keys,
|
|
313
|
+
useBip84,
|
|
314
|
+
useBip86,
|
|
315
|
+
useMultipleAddresses,
|
|
316
|
+
insightClient,
|
|
317
|
+
canBumpTx,
|
|
318
|
+
getAvailableBalance,
|
|
319
|
+
getSpendableBalance,
|
|
320
|
+
inscriptions: inscriptionsService,
|
|
321
321
|
}
|
|
322
|
+
return overrideCallback({ asset: fullAsset })
|
|
323
|
+
}
|
package/src/fee-data.js
CHANGED
|
@@ -7,7 +7,7 @@ export const _defaults = {
|
|
|
7
7
|
hourFee: '50 satoshis',
|
|
8
8
|
nextBlockMinimumFee: '60 satoshis',
|
|
9
9
|
minimumFee: '10 satoshis',
|
|
10
|
-
maxExtraCpfpFee:
|
|
10
|
+
maxExtraCpfpFee: 100000, // 100k statoshis, this is not a UnitType because it could be overridden with remote configs
|
|
11
11
|
rbfBumpFeeBlocks: 3,
|
|
12
12
|
rbfBumpFeeThreshold: 0.8,
|
|
13
13
|
rbfEnabled: true,
|
package/src/fee-monitor.js
CHANGED
|
@@ -15,8 +15,13 @@ export default class BitcoinFeeMonitor extends FeeMonitor {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async fetchFee() {
|
|
18
|
-
const {
|
|
19
|
-
|
|
18
|
+
const {
|
|
19
|
+
fastestFee,
|
|
20
|
+
halfHourFee,
|
|
21
|
+
hourFee,
|
|
22
|
+
minimumFee,
|
|
23
|
+
nextBlockMinimumFee,
|
|
24
|
+
} = await this.insight.fetchFeeRate()
|
|
20
25
|
return {
|
|
21
26
|
feePerKB: this.toPerKB(fastestFee),
|
|
22
27
|
fastestFee: `${fastestFee} satoshis`,
|
|
@@ -33,7 +38,6 @@ export default class BitcoinFeeMonitor extends FeeMonitor {
|
|
|
33
38
|
} else if (fee > MAX_FEE) {
|
|
34
39
|
fee = MAX_FEE
|
|
35
40
|
}
|
|
36
|
-
|
|
37
41
|
fee = fee * 1e3
|
|
38
42
|
return `${fee} satoshis`
|
|
39
43
|
}
|
package/src/index.js
CHANGED
|
@@ -11,12 +11,10 @@ async function improveErrorMessage(err) {
|
|
|
11
11
|
try {
|
|
12
12
|
const responseText = await err.response.text()
|
|
13
13
|
if (responseText)
|
|
14
|
-
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
|
15
14
|
return Promise.reject(new Error(`${err.message}. Error: ${responseText.slice(0, 200)}`)) // trying to get error more info from body)
|
|
16
|
-
} catch {}
|
|
15
|
+
} catch (e) {}
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
throw new Error(err.message)
|
|
17
|
+
return Promise.reject(new Error(err.message))
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
export const brc20ApiClientFactory = ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function validateAssetId(assetId) {
|
|
2
2
|
if (typeof assetId !== 'string') return false
|
|
3
|
-
const rgx = /^[
|
|
3
|
+
const rgx = /^[a-f0-9]{64}i\d+$/
|
|
4
4
|
return rgx.test(assetId)
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -19,7 +19,6 @@ export const createTokenFactory = ({ address, bip44, keys, getBalances }, networ
|
|
|
19
19
|
keys,
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
return {
|
|
24
23
|
validateAssetId,
|
|
25
24
|
createToken,
|
|
@@ -149,11 +149,9 @@ export const inscriptionsServiceFactory = ({ network, ordinalChainIndex }) => {
|
|
|
149
149
|
|
|
150
150
|
function finalizePsbt({ psbt, signature, commitTxData, tapLeafScript }) {
|
|
151
151
|
const customFinalizer = () => {
|
|
152
|
-
const witness = [
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
tapLeafScript.controlBlock,
|
|
156
|
-
]
|
|
152
|
+
const witness = [Buffer.from(signature, 'hex')]
|
|
153
|
+
.concat(commitTxData.outputScript)
|
|
154
|
+
.concat(tapLeafScript.controlBlock)
|
|
157
155
|
|
|
158
156
|
return {
|
|
159
157
|
finalScriptWitness: witnessStackToScriptWitness(witness),
|
|
@@ -184,7 +182,7 @@ export const inscriptionsServiceFactory = ({ network, ordinalChainIndex }) => {
|
|
|
184
182
|
const commitTxResult = {
|
|
185
183
|
txId,
|
|
186
184
|
sendUtxoIndex: 0,
|
|
187
|
-
sendAmount:
|
|
185
|
+
sendAmount: 100000,
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
const { tapLeafScript, psbt } = createPsbt({
|
|
@@ -2,7 +2,6 @@ export const isNftBrc20 = (nft) => {
|
|
|
2
2
|
if (nft.isBrc20) {
|
|
3
3
|
return true
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
// Void/Spent brc20 are not flagged as brc20
|
|
7
6
|
const isTextContentType =
|
|
8
7
|
nft.contentType?.startsWith('text/plain') || nft.contentType?.startsWith('application/json')
|
|
@@ -14,7 +13,6 @@ export const isNftBrc20 = (nft) => {
|
|
|
14
13
|
try {
|
|
15
14
|
const json = JSON.parse(Buffer.from(nft.contentBody, 'base64').toString())
|
|
16
15
|
return json?.p.toLowerCase() === 'brc-20'
|
|
17
|
-
} catch {}
|
|
18
|
-
|
|
16
|
+
} catch (e) {}
|
|
19
17
|
return false
|
|
20
18
|
}
|
package/src/ordinals/nfts.js
CHANGED
|
@@ -9,29 +9,29 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
9
9
|
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
10
10
|
let aci // convert to constructor argument when wallet send aci at createAsset time
|
|
11
11
|
|
|
12
|
-
const processAdditionalInscriptions = async function
|
|
12
|
+
const processAdditionalInscriptions = async function({ walletAccount, nfts }) {
|
|
13
13
|
const ordinalAddress = await getOrdinalAddress({
|
|
14
14
|
asset,
|
|
15
15
|
assetClientInterface: aci,
|
|
16
16
|
walletAccount,
|
|
17
|
-
ordinalChainIndex,
|
|
17
|
+
ordinalChainIndex: ordinalChainIndex,
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const accountState = await aci.getAccountState({
|
|
21
21
|
assetName: asset.name,
|
|
22
|
-
walletAccount,
|
|
22
|
+
walletAccount: walletAccount,
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
26
26
|
const storedUtxos = getUtxos({ accountState, asset })
|
|
27
27
|
const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
|
|
28
28
|
|
|
29
|
-
const knownUtxoIds =
|
|
30
|
-
|
|
29
|
+
const knownUtxoIds = [...allStoredUtxos].map((utxo) =>
|
|
30
|
+
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
31
31
|
)
|
|
32
32
|
|
|
33
33
|
const additionalInscriptions = nfts
|
|
34
|
-
.filter((nft) => knownUtxoIds.
|
|
34
|
+
.filter((nft) => knownUtxoIds.includes(nft.output.toLowerCase()))
|
|
35
35
|
.map((nft) => {
|
|
36
36
|
const output = nft.output.split(':')
|
|
37
37
|
return { txId: output[0], vout: parseInt(output[1]), inscriptionId: nft.tokenId }
|
|
@@ -43,10 +43,10 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
43
43
|
getOrdinalsUtxos({ accountState, asset })
|
|
44
44
|
),
|
|
45
45
|
ordinalsEnabled: true,
|
|
46
|
-
ordinalAddress,
|
|
46
|
+
ordinalAddress: ordinalAddress,
|
|
47
47
|
mustAvoidUtxoIds: accountState.mustAvoidUtxoIds,
|
|
48
48
|
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
49
|
-
additionalInscriptions,
|
|
49
|
+
additionalInscriptions: additionalInscriptions,
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
await aci.updateAccountState({
|
|
@@ -60,7 +60,6 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
60
60
|
})
|
|
61
61
|
return ordinalsUtxos
|
|
62
62
|
}
|
|
63
|
-
|
|
64
63
|
return storedOrdinalsUtxos
|
|
65
64
|
}
|
|
66
65
|
|
|
@@ -75,7 +74,6 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
75
74
|
console.warn('bitcoin nfts not initialized yet')
|
|
76
75
|
return []
|
|
77
76
|
}
|
|
78
|
-
|
|
79
77
|
return getInscriptionAddresses({
|
|
80
78
|
assetClientInterface: aci,
|
|
81
79
|
walletAccount: walletAccountInstance.toString(),
|
|
@@ -114,10 +112,9 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
114
112
|
try {
|
|
115
113
|
const retrievedNfts = await Promise.all(
|
|
116
114
|
uniqueInscriptionIds.map(async (inscriptionId) => {
|
|
117
|
-
if (nfts.
|
|
118
|
-
return
|
|
115
|
+
if (nfts.find((nft) => nft.tokenId === inscriptionId)) {
|
|
116
|
+
return undefined
|
|
119
117
|
}
|
|
120
|
-
|
|
121
118
|
try {
|
|
122
119
|
const json = await nftsProxy.getNft(inscriptionId)
|
|
123
120
|
const utxo = unconfirmedUtxosArray.find((utxo) =>
|
|
@@ -135,10 +132,11 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
135
132
|
console.warn(
|
|
136
133
|
`Cannot load ${asset.name} nft ${inscriptionId} from proxy server. Error: ${e.message}`
|
|
137
134
|
)
|
|
135
|
+
return undefined
|
|
138
136
|
}
|
|
139
137
|
})
|
|
140
138
|
)
|
|
141
|
-
const unconfirmedNfts = retrievedNfts.flat().filter(
|
|
139
|
+
const unconfirmedNfts = retrievedNfts.flat().filter((i) => i)
|
|
142
140
|
nfts.push(...unconfirmedNfts)
|
|
143
141
|
} catch (e) {
|
|
144
142
|
console.warn(
|
|
@@ -147,24 +145,22 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
const unconfirmedTxs =
|
|
151
|
-
|
|
152
|
-
walletAccount,
|
|
148
|
+
const unconfirmedTxs = Array.from(
|
|
149
|
+
await aci.getTxLog({
|
|
150
|
+
walletAccount: walletAccount,
|
|
153
151
|
assetName: asset.name,
|
|
154
|
-
})
|
|
155
|
-
|
|
152
|
+
})
|
|
153
|
+
).filter((tx) => !tx.confirmations)
|
|
156
154
|
|
|
157
|
-
const utxosOutputs =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
.filter(Boolean)
|
|
164
|
-
)
|
|
155
|
+
const utxosOutputs = storedOrdinalsUtxos
|
|
156
|
+
.toArray()
|
|
157
|
+
.map((utxo) => {
|
|
158
|
+
return `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
159
|
+
})
|
|
160
|
+
.filter(Boolean)
|
|
165
161
|
|
|
166
162
|
const expandedNfts = nfts.map((nft) => {
|
|
167
|
-
const sending = !utxosOutputs.
|
|
163
|
+
const sending = !utxosOutputs.includes(nft.output.toLowerCase())
|
|
168
164
|
|
|
169
165
|
const sendingTx =
|
|
170
166
|
sending &&
|
|
@@ -193,15 +189,14 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
193
189
|
assert(walletAccountInstance, 'walletAccount is required')
|
|
194
190
|
assert(newMustAvoidUtxoIds, 'mustAvoidUtxoIds is required')
|
|
195
191
|
|
|
196
|
-
if (!prune && newMustAvoidUtxoIds.length
|
|
192
|
+
if (!prune && !newMustAvoidUtxoIds.length) {
|
|
197
193
|
return
|
|
198
194
|
}
|
|
199
|
-
|
|
200
195
|
const walletAccount = walletAccountInstance.toString()
|
|
201
196
|
|
|
202
197
|
const accountState = await aci.getAccountState({
|
|
203
198
|
assetName: asset.name,
|
|
204
|
-
walletAccount,
|
|
199
|
+
walletAccount: walletAccount,
|
|
205
200
|
})
|
|
206
201
|
|
|
207
202
|
const storedMustAvoidUtxosIds = accountState.mustAvoidUtxoIds || []
|
|
@@ -216,12 +211,12 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
216
211
|
...new Set([...storedMustAvoidUtxosIds, ...newMustAvoidUtxoIds].sort()),
|
|
217
212
|
]
|
|
218
213
|
|
|
219
|
-
const knownUtxoIds =
|
|
220
|
-
|
|
214
|
+
const knownUtxoIds = [...allStoredUtxos].map((utxo) =>
|
|
215
|
+
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
221
216
|
)
|
|
222
217
|
|
|
223
218
|
const mustAvoidUtxoIds = prune
|
|
224
|
-
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.
|
|
219
|
+
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.includes(id))
|
|
225
220
|
: allMustAvoidUtxoIds
|
|
226
221
|
|
|
227
222
|
if (isEqual(mustAvoidUtxoIds, storedMustAvoidUtxosIds)) {
|
|
@@ -232,14 +227,14 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
232
227
|
asset,
|
|
233
228
|
assetClientInterface: aci,
|
|
234
229
|
walletAccount,
|
|
235
|
-
ordinalChainIndex,
|
|
230
|
+
ordinalChainIndex: ordinalChainIndex,
|
|
236
231
|
})
|
|
237
232
|
|
|
238
233
|
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
239
234
|
allUtxos: allStoredUtxos,
|
|
240
235
|
ordinalsEnabled: true,
|
|
241
|
-
ordinalAddress,
|
|
242
|
-
mustAvoidUtxoIds,
|
|
236
|
+
ordinalAddress: ordinalAddress,
|
|
237
|
+
mustAvoidUtxoIds: mustAvoidUtxoIds,
|
|
243
238
|
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
244
239
|
additionalInscriptions: accountState.additionalInscriptions,
|
|
245
240
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// In general, wallets don't spend the postage.
|
|
4
4
|
export const DEFAULT_BRC20_POSTAGE = 546
|
|
5
5
|
|
|
6
|
-
export const DEFAULT_ORDINAL_POSTAGE =
|
|
6
|
+
export const DEFAULT_ORDINAL_POSTAGE = 10000
|
|
7
7
|
|
|
8
8
|
// What's the taproot chain index to use as the default ordinal address (as in purpose 86, m/2/0).
|
|
9
9
|
// Note that it's recommended for exodus wallets to not use 0 as it can hold regular btc (as in purpose 86, m/0/0).
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
3
|
import { groupBy, mapValues } from 'lodash'
|
|
4
|
-
|
|
5
4
|
const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
6
5
|
const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
|
|
7
6
|
|
|
@@ -21,7 +20,7 @@ const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
|
21
20
|
sent: [
|
|
22
21
|
{
|
|
23
22
|
address: historyItem.transferTo,
|
|
24
|
-
amount,
|
|
23
|
+
amount: amount,
|
|
25
24
|
},
|
|
26
25
|
],
|
|
27
26
|
}
|
|
@@ -70,26 +69,29 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
70
69
|
|
|
71
70
|
const unknownDeployInscriptionIds = new Set()
|
|
72
71
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
token
|
|
72
|
+
const brc20History = (
|
|
73
|
+
await Promise.all(
|
|
74
|
+
addresses.map(async (address) => {
|
|
75
|
+
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ owner: address })
|
|
76
|
+
return (
|
|
77
|
+
await Promise.all(
|
|
78
|
+
tokensHistoryList.map(async (token) => {
|
|
79
|
+
const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
|
|
80
|
+
token.brc20Tick
|
|
81
|
+
)
|
|
82
|
+
const assetName = assetByAssetId.get(deployInscriptionId)?.name
|
|
83
|
+
if (assetName) {
|
|
84
|
+
return { ...token, address, assetName, deployInscriptionId }
|
|
85
|
+
} else {
|
|
86
|
+
unknownDeployInscriptionIds.add(deployInscriptionId)
|
|
87
|
+
return undefined
|
|
88
|
+
}
|
|
89
|
+
})
|
|
80
90
|
)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
unknownDeployInscriptionIds.add(deployInscriptionId)
|
|
87
|
-
})
|
|
88
|
-
)
|
|
89
|
-
return history.filter(Boolean)
|
|
90
|
-
})
|
|
91
|
-
)
|
|
92
|
-
const brc20History = historyLists.flat()
|
|
91
|
+
).filter(Boolean)
|
|
92
|
+
})
|
|
93
|
+
)
|
|
94
|
+
).flat()
|
|
93
95
|
|
|
94
96
|
const eventsByAssetNameAndAddress = mapValues(
|
|
95
97
|
groupBy(brc20History, (event) => event.assetName),
|
|
@@ -100,9 +102,9 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
100
102
|
return mapValues(eventsByAddress, (events) => {
|
|
101
103
|
const { brc20OwnerAvailableBalance, brc20OwnerTransferBalance, brc20Tick } = events[0]
|
|
102
104
|
|
|
103
|
-
const sentList =
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
const sentList = events
|
|
106
|
+
.filter((event) => event.brc20Op === 'send')
|
|
107
|
+
.map((event) => event.inscriptionId)
|
|
106
108
|
|
|
107
109
|
const transferableList = events
|
|
108
110
|
.filter((event) => event.brc20Op === 'transfer')
|
|
@@ -112,7 +114,7 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
112
114
|
inscriptionNumber: event.inscriptionNumber,
|
|
113
115
|
brc20Amt: event.brc20Amt,
|
|
114
116
|
txId: event.txId,
|
|
115
|
-
sent: sentList.
|
|
117
|
+
sent: sentList.includes(event.inscriptionId),
|
|
116
118
|
}
|
|
117
119
|
})
|
|
118
120
|
return {
|