@exodus/bitcoin-plugin 1.8.1 → 1.8.2-hotfix
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 +26 -8
- package/src/compatibility-modes.js +5 -2
- package/src/create-asset.js +259 -261
- package/src/fee-data.js +1 -1
- package/src/fee-monitor.js +3 -7
- package/src/index.js +1 -0
- package/src/ordinals/brc-20-client.js +4 -2
- package/src/ordinals/brc-20-utils.js +1 -1
- package/src/ordinals/create-token-factory.js +2 -1
- package/src/ordinals/inscriptions-service.js +6 -4
- package/src/ordinals/nft-utils.js +3 -1
- package/src/ordinals/nfts.js +37 -32
- package/src/ordinals/ordinals-constants.js +1 -1
- package/src/ordinals/reload-brc20-token-balances.js +25 -27
- package/src/ordinals/tick-inscription-id-indexer.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2-hotfix",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -13,21 +13,39 @@
|
|
|
13
13
|
"access": "restricted"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"test": "jest",
|
|
17
|
-
"lint": "eslint ./src",
|
|
16
|
+
"test": "run -T jest",
|
|
17
|
+
"lint": "run -T eslint ./src",
|
|
18
18
|
"lint:fix": "yarn lint --fix"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@exodus/asset-lib": "^4.0.0",
|
|
22
22
|
"@exodus/basic-utils": "^2.1.0",
|
|
23
|
-
"@exodus/
|
|
23
|
+
"@exodus/bip32": "^1.1.2",
|
|
24
|
+
"@exodus/bip44-constants": "^195.0.0",
|
|
25
|
+
"@exodus/bitcoin-api": "^2.9.2",
|
|
24
26
|
"@exodus/bitcoin-lib": "^2.3.0",
|
|
27
|
+
"@exodus/bitcoin-meta": "^1.0.2",
|
|
28
|
+
"@exodus/bitcoinjs-lib": "^6.1.5-exodus.0",
|
|
29
|
+
"@exodus/crypto": "^1.0.0-rc.1",
|
|
30
|
+
"@exodus/fetch": "^1.3.0",
|
|
25
31
|
"@exodus/models": "^11.0.0",
|
|
26
32
|
"@exodus/text-encoding-utf8": "^1.0.2",
|
|
27
|
-
"
|
|
33
|
+
"coininfo": "5.1.0",
|
|
34
|
+
"create-hash": "^1.2.0",
|
|
35
|
+
"lodash": "^4.17.21",
|
|
36
|
+
"minimalistic-assert": "^1.0.1",
|
|
37
|
+
"ms": "^2.1.3",
|
|
38
|
+
"tiny-secp256k1": "1.1.3"
|
|
28
39
|
},
|
|
29
40
|
"devDependencies": {
|
|
30
|
-
"@exodus/
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
"@exodus/assets-testing": "^1.0.0",
|
|
42
|
+
"@exodus/bitcoin-meta": "^1.0.2",
|
|
43
|
+
"@exodus/bitcoinregtest-meta": "^1.0.1",
|
|
44
|
+
"@exodus/bitcointestnet-meta": "^1.0.0",
|
|
45
|
+
"@exodus/currency": "^2.3.2",
|
|
46
|
+
"@exodus/hdkey": "^2.1.0-exodus.0",
|
|
47
|
+
"@exodus/nfts-proxy": "^2.10.1",
|
|
48
|
+
"@scure/btc-signer": "^1.1.0",
|
|
49
|
+
"jest-when": "^3.5.1"
|
|
50
|
+
}
|
|
33
51
|
}
|
|
@@ -6,16 +6,17 @@ 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 } = Object.create(null)) => {
|
|
10
10
|
if ([ordinals84, ordinals86].includes(compatibilityMode)) {
|
|
11
11
|
return 'm/0'
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
return 'm/0/0'
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export const getSupportedPurposes = ({ compatibilityMode, walletAccount }) => {
|
|
17
18
|
if (walletAccount?.source === WalletAccount.TREZOR_SRC || compatibilityMode === trezor) {
|
|
18
|
-
return [84, 49]
|
|
19
|
+
return [84, 49, 44]
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
if (compatibilityMode === ledger) {
|
|
@@ -25,9 +26,11 @@ export const getSupportedPurposes = ({ compatibilityMode, walletAccount }) => {
|
|
|
25
26
|
if (compatibilityMode === ordinals84) {
|
|
26
27
|
return [84, 86, 44]
|
|
27
28
|
}
|
|
29
|
+
|
|
28
30
|
if (compatibilityMode === ordinals86) {
|
|
29
31
|
return [86, 84, 44]
|
|
30
32
|
}
|
|
33
|
+
|
|
31
34
|
if (compatibilityMode === xverse49) {
|
|
32
35
|
return [49, 84, 86, 44]
|
|
33
36
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -35,289 +35,287 @@ 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
|
-
apiUrl:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
}
|
|
38
|
+
export const createBitcoinAssetFactory =
|
|
39
|
+
({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) =>
|
|
40
|
+
({
|
|
41
|
+
apiUrl: customApiUrl,
|
|
42
|
+
allowUnconfirmedRbfEnabledUtxos = false,
|
|
43
|
+
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
44
|
+
ordinalsEnabled = false,
|
|
45
|
+
brc20Enabled = false,
|
|
46
|
+
gapLimit = 10,
|
|
47
|
+
refreshGapLimit = 25,
|
|
48
|
+
overrideCallback = ({ asset }) => asset,
|
|
49
|
+
feeDataCustomValues,
|
|
50
|
+
} = {}) => {
|
|
51
|
+
const apiUrl = customApiUrl || defaultApiUrl
|
|
52
|
+
assert(asset, 'asset is required')
|
|
53
|
+
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
54
|
+
assert(apiUrl, 'apiUrl is required')
|
|
55
|
+
assert(
|
|
56
|
+
brc20Enabled ? ordinalsEnabled : true,
|
|
57
|
+
'if brc20Enabled is true then ordinalsEnabled must be true'
|
|
58
|
+
)
|
|
59
|
+
const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
|
|
90
60
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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,
|
|
61
|
+
const insightClient = new InsightAPIClient(apiUrl)
|
|
62
|
+
|
|
63
|
+
if (customApiUrl) insightClient.setBaseUrl = () => {} // not let the configuration override url when providing a custom one
|
|
64
|
+
|
|
65
|
+
const useBip84 = true
|
|
66
|
+
const useBip86 = true
|
|
67
|
+
|
|
68
|
+
const versions = getBtcVersions(coinInfo)
|
|
69
|
+
const address = createBtcLikeAddress({
|
|
70
|
+
versions,
|
|
170
71
|
coinInfo,
|
|
171
|
-
|
|
172
|
-
|
|
72
|
+
useBip86,
|
|
73
|
+
bitcoinjsLib,
|
|
74
|
+
})
|
|
173
75
|
|
|
174
|
-
|
|
76
|
+
const keys = createBtcLikeKeys({ coinInfo, versions, useBip86 })
|
|
77
|
+
const bip44 = bip44Constants['BTC']
|
|
175
78
|
|
|
176
|
-
|
|
79
|
+
const allowedPurposes = [44, 49, 84, 86]
|
|
177
80
|
|
|
178
|
-
|
|
179
|
-
? createTokenFactory({ address, bip44, keys, getBalances }, [])
|
|
180
|
-
: {}
|
|
81
|
+
const useMultipleAddresses = true
|
|
181
82
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
83
|
+
const features = {
|
|
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
|
+
})
|
|
97
|
+
|
|
98
|
+
const baseFeeResolver = new GetFeeResolver({
|
|
99
|
+
getFeeEstimator,
|
|
100
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const feeData = bitcoinFeeDataFactory({
|
|
104
|
+
currency: asset.currency,
|
|
105
|
+
overrideDefaults: feeDataCustomValues,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const baseGetBalances = getBalancesFactory({
|
|
109
|
+
feeData,
|
|
110
|
+
getSpendableBalance: baseFeeResolver.getSpendableBalance,
|
|
185
111
|
ordinalsEnabled,
|
|
186
|
-
ordinalChainIndex,
|
|
187
|
-
apiUrl,
|
|
188
|
-
gapLimit,
|
|
189
|
-
refreshGapLimit,
|
|
190
|
-
...args,
|
|
191
112
|
})
|
|
192
|
-
const assetClientInterface = args.assetClientInterface
|
|
193
|
-
if (ordinalsEnabled) {
|
|
194
|
-
nfts.initialize({ assetClientInterface })
|
|
195
|
-
}
|
|
196
113
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
114
|
+
const brc20Client = brc20Enabled ? brc20ApiClientFactory() : undefined
|
|
115
|
+
const tickInscriptionIdIndexer = brc20Enabled
|
|
116
|
+
? tickInscriptionIdIndexerFactory({ brc20Client })
|
|
117
|
+
: undefined
|
|
118
|
+
|
|
119
|
+
const baseSendTx = createAndBroadcastTXFactory({
|
|
120
|
+
getFeeEstimator,
|
|
121
|
+
allowUnconfirmedRbfEnabledUtxos,
|
|
122
|
+
ordinalsEnabled,
|
|
123
|
+
})
|
|
124
|
+
const inscriptionsService = brc20Enabled
|
|
125
|
+
? inscriptionsServiceFactory({
|
|
201
126
|
asset,
|
|
127
|
+
network: coinInfo.toBitcoinJS(),
|
|
202
128
|
ordinalChainIndex,
|
|
203
|
-
brc20Client,
|
|
204
|
-
assetClientInterface,
|
|
205
|
-
tickInscriptionIdIndexer,
|
|
206
129
|
})
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
130
|
+
: undefined
|
|
131
|
+
|
|
132
|
+
const { getFee, getBalances, getAvailableBalance, canBumpTx, getSpendableBalance, sendTx } =
|
|
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,
|
|
210
187
|
})
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
+
}
|
|
214
208
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const result = await insightClient.fetchTxData([address], { from: 0, to: 1 })
|
|
218
|
-
return !!result?.items.length
|
|
219
|
-
}
|
|
209
|
+
return monitor
|
|
210
|
+
}
|
|
220
211
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
+
}
|
|
226
217
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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)
|
|
230
222
|
}
|
|
231
223
|
|
|
232
|
-
|
|
233
|
-
|
|
224
|
+
const isOrdinalTx = (tx) => {
|
|
225
|
+
if (!ordinalsEnabled || tx.coinName !== asset.name) {
|
|
226
|
+
return false
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!tx.data.inscriptionsIndexed) {
|
|
230
|
+
return false // allows users seeing the pending tx because we don't know yet if it is ordinals or btc
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
tx.data.receivedInscriptions?.some(isValidInscription) ||
|
|
235
|
+
tx.data.sentInscriptions?.some(isValidInscription)
|
|
236
|
+
)
|
|
234
237
|
}
|
|
235
238
|
|
|
236
|
-
|
|
237
|
-
tx.
|
|
238
|
-
tx.data.
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
const txLogFilter = (tx) => {
|
|
240
|
+
const isDroppedBitcoinTx = tx.dropped
|
|
241
|
+
const isWaitingRbf = tx.data && tx.data.replacedBy && tx.pending
|
|
242
|
+
return !isDroppedBitcoinTx && !isWaitingRbf && !isOrdinalTx(tx)
|
|
243
|
+
}
|
|
241
244
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
const getActivityTxs = ({ txs, asset }) => {
|
|
246
|
+
return txs
|
|
247
|
+
.flatMap((tx) => {
|
|
248
|
+
if (tx.sent && Array.isArray(tx.data.sent) && tx.data.sent.length > 0) {
|
|
249
|
+
const feeAmount = tx.feeAmount.div(tx.data.sent.length)
|
|
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
|
+
}
|
|
247
268
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
269
|
+
const api = {
|
|
270
|
+
getActivityTxs,
|
|
271
|
+
addressHasHistory,
|
|
272
|
+
defaultAddressPath: 'm/0/0', // deprecated
|
|
273
|
+
broadcastTx: (...args) => insightClient.broadcastTx(...args),
|
|
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
|
+
}
|
|
270
303
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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({
|
|
304
|
+
const fullAsset = {
|
|
305
|
+
...asset,
|
|
306
|
+
address,
|
|
307
|
+
api,
|
|
285
308
|
bip44,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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,
|
|
309
|
+
coinInfo,
|
|
310
|
+
keys,
|
|
311
|
+
useBip84,
|
|
312
|
+
useBip86,
|
|
313
|
+
useMultipleAddresses,
|
|
314
|
+
insightClient,
|
|
315
|
+
canBumpTx,
|
|
316
|
+
getAvailableBalance,
|
|
317
|
+
getSpendableBalance,
|
|
318
|
+
inscriptions: inscriptionsService,
|
|
319
|
+
}
|
|
320
|
+
return overrideCallback({ asset: fullAsset })
|
|
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: 100_000, // 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,13 +15,8 @@ export default class BitcoinFeeMonitor extends FeeMonitor {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async fetchFee() {
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
halfHourFee,
|
|
21
|
-
hourFee,
|
|
22
|
-
minimumFee,
|
|
23
|
-
nextBlockMinimumFee,
|
|
24
|
-
} = await this.insight.fetchFeeRate()
|
|
18
|
+
const { fastestFee, halfHourFee, hourFee, minimumFee, nextBlockMinimumFee } =
|
|
19
|
+
await this.insight.fetchFeeRate()
|
|
25
20
|
return {
|
|
26
21
|
feePerKB: this.toPerKB(fastestFee),
|
|
27
22
|
fastestFee: `${fastestFee} satoshis`,
|
|
@@ -38,6 +33,7 @@ export default class BitcoinFeeMonitor extends FeeMonitor {
|
|
|
38
33
|
} else if (fee > MAX_FEE) {
|
|
39
34
|
fee = MAX_FEE
|
|
40
35
|
}
|
|
36
|
+
|
|
41
37
|
fee = fee * 1e3
|
|
42
38
|
return `${fee} satoshis`
|
|
43
39
|
}
|
package/src/index.js
CHANGED
|
@@ -11,10 +11,12 @@ 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
|
|
14
15
|
return Promise.reject(new Error(`${err.message}. Error: ${responseText.slice(0, 200)}`)) // trying to get error more info from body)
|
|
15
|
-
} catch
|
|
16
|
+
} catch {}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
throw new Error(err.message)
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
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 = /^[\da-f]{64}i\d+$/
|
|
4
4
|
return rgx.test(assetId)
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -19,6 +19,7 @@ export const createTokenFactory = ({ address, bip44, keys, getBalances }, networ
|
|
|
19
19
|
keys,
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
|
|
22
23
|
return {
|
|
23
24
|
validateAssetId,
|
|
24
25
|
createToken,
|
|
@@ -149,9 +149,11 @@ export const inscriptionsServiceFactory = ({ network, ordinalChainIndex }) => {
|
|
|
149
149
|
|
|
150
150
|
function finalizePsbt({ psbt, signature, commitTxData, tapLeafScript }) {
|
|
151
151
|
const customFinalizer = () => {
|
|
152
|
-
const witness = [
|
|
153
|
-
.
|
|
154
|
-
.
|
|
152
|
+
const witness = [
|
|
153
|
+
Buffer.from(signature, 'hex'),
|
|
154
|
+
commitTxData.outputScript,
|
|
155
|
+
tapLeafScript.controlBlock,
|
|
156
|
+
]
|
|
155
157
|
|
|
156
158
|
return {
|
|
157
159
|
finalScriptWitness: witnessStackToScriptWitness(witness),
|
|
@@ -182,7 +184,7 @@ export const inscriptionsServiceFactory = ({ network, ordinalChainIndex }) => {
|
|
|
182
184
|
const commitTxResult = {
|
|
183
185
|
txId,
|
|
184
186
|
sendUtxoIndex: 0,
|
|
185
|
-
sendAmount:
|
|
187
|
+
sendAmount: 100_000,
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
const { tapLeafScript, psbt } = createPsbt({
|
|
@@ -2,6 +2,7 @@ export const isNftBrc20 = (nft) => {
|
|
|
2
2
|
if (nft.isBrc20) {
|
|
3
3
|
return true
|
|
4
4
|
}
|
|
5
|
+
|
|
5
6
|
// Void/Spent brc20 are not flagged as brc20
|
|
6
7
|
const isTextContentType =
|
|
7
8
|
nft.contentType?.startsWith('text/plain') || nft.contentType?.startsWith('application/json')
|
|
@@ -13,6 +14,7 @@ export const isNftBrc20 = (nft) => {
|
|
|
13
14
|
try {
|
|
14
15
|
const json = JSON.parse(Buffer.from(nft.contentBody, 'base64').toString())
|
|
15
16
|
return json?.p.toLowerCase() === 'brc-20'
|
|
16
|
-
} catch
|
|
17
|
+
} catch {}
|
|
18
|
+
|
|
17
19
|
return false
|
|
18
20
|
}
|
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({ walletAccount, nfts }) {
|
|
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,
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const accountState = await aci.getAccountState({
|
|
21
21
|
assetName: asset.name,
|
|
22
|
-
walletAccount
|
|
22
|
+
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
|
-
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
29
|
+
const knownUtxoIds = new Set(
|
|
30
|
+
[...allStoredUtxos].map((utxo) => `${utxo.txId}:${utxo.vout}`.toLowerCase())
|
|
31
31
|
)
|
|
32
32
|
|
|
33
33
|
const additionalInscriptions = nfts
|
|
34
|
-
.filter((nft) => knownUtxoIds.
|
|
34
|
+
.filter((nft) => knownUtxoIds.has(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,
|
|
47
47
|
mustAvoidUtxoIds: accountState.mustAvoidUtxoIds,
|
|
48
48
|
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
49
|
-
additionalInscriptions
|
|
49
|
+
additionalInscriptions,
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
await aci.updateAccountState({
|
|
@@ -60,6 +60,7 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
60
60
|
})
|
|
61
61
|
return ordinalsUtxos
|
|
62
62
|
}
|
|
63
|
+
|
|
63
64
|
return storedOrdinalsUtxos
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -74,6 +75,7 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
74
75
|
console.warn('bitcoin nfts not initialized yet')
|
|
75
76
|
return []
|
|
76
77
|
}
|
|
78
|
+
|
|
77
79
|
return getInscriptionAddresses({
|
|
78
80
|
assetClientInterface: aci,
|
|
79
81
|
walletAccount: walletAccountInstance.toString(),
|
|
@@ -112,9 +114,10 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
112
114
|
try {
|
|
113
115
|
const retrievedNfts = await Promise.all(
|
|
114
116
|
uniqueInscriptionIds.map(async (inscriptionId) => {
|
|
115
|
-
if (nfts.
|
|
116
|
-
return
|
|
117
|
+
if (nfts.some((nft) => nft.tokenId === inscriptionId)) {
|
|
118
|
+
return
|
|
117
119
|
}
|
|
120
|
+
|
|
118
121
|
try {
|
|
119
122
|
const json = await nftsProxy.getNft(inscriptionId)
|
|
120
123
|
const utxo = unconfirmedUtxosArray.find((utxo) =>
|
|
@@ -132,11 +135,10 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
132
135
|
console.warn(
|
|
133
136
|
`Cannot load ${asset.name} nft ${inscriptionId} from proxy server. Error: ${e.message}`
|
|
134
137
|
)
|
|
135
|
-
return undefined
|
|
136
138
|
}
|
|
137
139
|
})
|
|
138
140
|
)
|
|
139
|
-
const unconfirmedNfts = retrievedNfts.flat().filter(
|
|
141
|
+
const unconfirmedNfts = retrievedNfts.flat().filter(Boolean)
|
|
140
142
|
nfts.push(...unconfirmedNfts)
|
|
141
143
|
} catch (e) {
|
|
142
144
|
console.warn(
|
|
@@ -145,22 +147,24 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
const unconfirmedTxs =
|
|
149
|
-
await aci.getTxLog({
|
|
150
|
-
walletAccount
|
|
150
|
+
const unconfirmedTxs = [
|
|
151
|
+
...(await aci.getTxLog({
|
|
152
|
+
walletAccount,
|
|
151
153
|
assetName: asset.name,
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
+
})),
|
|
155
|
+
].filter((tx) => !tx.confirmations)
|
|
154
156
|
|
|
155
|
-
const utxosOutputs =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
const utxosOutputs = new Set(
|
|
158
|
+
storedOrdinalsUtxos
|
|
159
|
+
.toArray()
|
|
160
|
+
.map((utxo) => {
|
|
161
|
+
return `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
162
|
+
})
|
|
163
|
+
.filter(Boolean)
|
|
164
|
+
)
|
|
161
165
|
|
|
162
166
|
const expandedNfts = nfts.map((nft) => {
|
|
163
|
-
const sending = !utxosOutputs.
|
|
167
|
+
const sending = !utxosOutputs.has(nft.output.toLowerCase())
|
|
164
168
|
|
|
165
169
|
const sendingTx =
|
|
166
170
|
sending &&
|
|
@@ -189,14 +193,15 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
189
193
|
assert(walletAccountInstance, 'walletAccount is required')
|
|
190
194
|
assert(newMustAvoidUtxoIds, 'mustAvoidUtxoIds is required')
|
|
191
195
|
|
|
192
|
-
if (!prune &&
|
|
196
|
+
if (!prune && newMustAvoidUtxoIds.length === 0) {
|
|
193
197
|
return
|
|
194
198
|
}
|
|
199
|
+
|
|
195
200
|
const walletAccount = walletAccountInstance.toString()
|
|
196
201
|
|
|
197
202
|
const accountState = await aci.getAccountState({
|
|
198
203
|
assetName: asset.name,
|
|
199
|
-
walletAccount
|
|
204
|
+
walletAccount,
|
|
200
205
|
})
|
|
201
206
|
|
|
202
207
|
const storedMustAvoidUtxosIds = accountState.mustAvoidUtxoIds || []
|
|
@@ -211,12 +216,12 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
211
216
|
...new Set([...storedMustAvoidUtxosIds, ...newMustAvoidUtxoIds].sort()),
|
|
212
217
|
]
|
|
213
218
|
|
|
214
|
-
const knownUtxoIds =
|
|
215
|
-
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
219
|
+
const knownUtxoIds = new Set(
|
|
220
|
+
[...allStoredUtxos].map((utxo) => `${utxo.txId}:${utxo.vout}`.toLowerCase())
|
|
216
221
|
)
|
|
217
222
|
|
|
218
223
|
const mustAvoidUtxoIds = prune
|
|
219
|
-
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.
|
|
224
|
+
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.has(id))
|
|
220
225
|
: allMustAvoidUtxoIds
|
|
221
226
|
|
|
222
227
|
if (isEqual(mustAvoidUtxoIds, storedMustAvoidUtxosIds)) {
|
|
@@ -227,14 +232,14 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
227
232
|
asset,
|
|
228
233
|
assetClientInterface: aci,
|
|
229
234
|
walletAccount,
|
|
230
|
-
ordinalChainIndex
|
|
235
|
+
ordinalChainIndex,
|
|
231
236
|
})
|
|
232
237
|
|
|
233
238
|
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
234
239
|
allUtxos: allStoredUtxos,
|
|
235
240
|
ordinalsEnabled: true,
|
|
236
|
-
ordinalAddress
|
|
237
|
-
mustAvoidUtxoIds
|
|
241
|
+
ordinalAddress,
|
|
242
|
+
mustAvoidUtxoIds,
|
|
238
243
|
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
239
244
|
additionalInscriptions: accountState.additionalInscriptions,
|
|
240
245
|
})
|
|
@@ -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 = 10_000
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
3
|
import { groupBy, mapValues } from 'lodash'
|
|
4
|
+
|
|
4
5
|
const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
5
6
|
const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
|
|
6
7
|
|
|
@@ -20,7 +21,7 @@ const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
|
20
21
|
sent: [
|
|
21
22
|
{
|
|
22
23
|
address: historyItem.transferTo,
|
|
23
|
-
amount
|
|
24
|
+
amount,
|
|
24
25
|
},
|
|
25
26
|
],
|
|
26
27
|
}
|
|
@@ -69,29 +70,26 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
69
70
|
|
|
70
71
|
const unknownDeployInscriptionIds = new Set()
|
|
71
72
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await
|
|
78
|
-
|
|
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
|
-
})
|
|
73
|
+
const historyLists = await Promise.all(
|
|
74
|
+
addresses.map(async (address) => {
|
|
75
|
+
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ owner: address })
|
|
76
|
+
const history = await Promise.all(
|
|
77
|
+
tokensHistoryList.map(async (token) => {
|
|
78
|
+
const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
|
|
79
|
+
token.brc20Tick
|
|
90
80
|
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
const assetName = assetByAssetId.get(deployInscriptionId)?.name
|
|
82
|
+
if (assetName) {
|
|
83
|
+
return { ...token, address, assetName, deployInscriptionId }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
unknownDeployInscriptionIds.add(deployInscriptionId)
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
return history.filter(Boolean)
|
|
90
|
+
})
|
|
91
|
+
)
|
|
92
|
+
const brc20History = historyLists.flat()
|
|
95
93
|
|
|
96
94
|
const eventsByAssetNameAndAddress = mapValues(
|
|
97
95
|
groupBy(brc20History, (event) => event.assetName),
|
|
@@ -102,9 +100,9 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
102
100
|
return mapValues(eventsByAddress, (events) => {
|
|
103
101
|
const { brc20OwnerAvailableBalance, brc20OwnerTransferBalance, brc20Tick } = events[0]
|
|
104
102
|
|
|
105
|
-
const sentList =
|
|
106
|
-
.filter((event) => event.brc20Op === 'send')
|
|
107
|
-
|
|
103
|
+
const sentList = new Set(
|
|
104
|
+
events.filter((event) => event.brc20Op === 'send').map((event) => event.inscriptionId)
|
|
105
|
+
)
|
|
108
106
|
|
|
109
107
|
const transferableList = events
|
|
110
108
|
.filter((event) => event.brc20Op === 'transfer')
|
|
@@ -114,7 +112,7 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
114
112
|
inscriptionNumber: event.inscriptionNumber,
|
|
115
113
|
brc20Amt: event.brc20Amt,
|
|
116
114
|
txId: event.txId,
|
|
117
|
-
sent: sentList.
|
|
115
|
+
sent: sentList.has(event.inscriptionId),
|
|
118
116
|
}
|
|
119
117
|
})
|
|
120
118
|
return {
|