@exodus/bitcoin-plugin 1.8.0 → 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 +32 -38
- package/src/ordinals/brc-20-utils.js +1 -1
- package/src/ordinals/create-token-factory.js +2 -1
- package/src/ordinals/get-inscription-addresses.js +10 -1
- package/src/ordinals/inscriptions-service.js +6 -4
- package/src/ordinals/nft-utils.js +3 -1
- package/src/ordinals/nfts.js +89 -28
- 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 +2 -1
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 = ({
|
|
@@ -41,12 +43,12 @@ export const brc20ApiClientFactory = ({
|
|
|
41
43
|
|
|
42
44
|
const getOwnerTickBalances = async ({ address }) => {
|
|
43
45
|
assert(address, 'address is required')
|
|
44
|
-
return request(`/v2/ord/brc20/
|
|
46
|
+
return request(`/v2/ord/btc/brc20/owner_balances/${encodeURIComponent(address)}`)
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
const getTickerInfo = async ({ tick }) => {
|
|
48
50
|
assert(tick, 'tick is required')
|
|
49
|
-
return request(`/v2/ord/brc20/
|
|
51
|
+
return request(`/v2/ord/btc/brc20/tick_infos/${encodeURIComponent(tick)}`)
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
const getTickerInfoByDeployInscriptionId = async ({ deployInscriptionId }) => {
|
|
@@ -56,54 +58,46 @@ export const brc20ApiClientFactory = ({
|
|
|
56
58
|
)
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
const removeNullUndefined = (obj) =>
|
|
62
|
+
Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined))
|
|
63
|
+
|
|
59
64
|
const paginatedTransactionHistory = async (queryParams) => {
|
|
60
|
-
const
|
|
61
|
-
assert(address, 'address is required')
|
|
65
|
+
const resolvedQueryParams = removeNullUndefined(queryParams)
|
|
62
66
|
const events = []
|
|
63
67
|
const limit = queryParams.limit || 40
|
|
64
68
|
let offset = queryParams.offset || 0
|
|
65
69
|
let response
|
|
66
70
|
do {
|
|
67
|
-
response = await request(
|
|
71
|
+
response = await request('/v2/ord/btc/brc20/events', {
|
|
72
|
+
...resolvedQueryParams,
|
|
68
73
|
limit,
|
|
69
74
|
offset,
|
|
70
75
|
})
|
|
71
76
|
offset = offset + limit
|
|
72
|
-
events.push(...response.
|
|
77
|
+
events.push(...response.events)
|
|
73
78
|
} while (offset < response.total)
|
|
74
79
|
|
|
75
|
-
|
|
76
|
-
return events.map((event) => {
|
|
77
|
-
const brc20OwnerAvailableBalance = Number(event.available_balance)
|
|
78
|
-
const brc20OwnerTransferBalance = Number(event.transferrable_balance)
|
|
79
|
-
assert(!isNaN(brc20OwnerAvailableBalance))
|
|
80
|
-
assert(!isNaN(brc20OwnerTransferBalance))
|
|
81
|
-
const brc20Op =
|
|
82
|
-
event.type === 'inscribe-transfer'
|
|
83
|
-
? 'transfer'
|
|
84
|
-
: event.type === 'inscribe-mint'
|
|
85
|
-
? 'mint'
|
|
86
|
-
: event.type
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
brc20Tick: event.ticker,
|
|
90
|
-
inscriptionId: event.inscription_id,
|
|
91
|
-
inscriptionNumber: event.inscription_number,
|
|
92
|
-
txId: event.tx_id,
|
|
93
|
-
createdAt: new Date(event.block_time * 1000).toISOString(),
|
|
94
|
-
owner: address,
|
|
95
|
-
transferFrom: event.from,
|
|
96
|
-
transferTo: event.to,
|
|
97
|
-
brc20Op,
|
|
98
|
-
brc20Amt: event.amount,
|
|
99
|
-
brc20OwnerAvailableBalance, // todo use NUs for adding these
|
|
100
|
-
brc20OwnerTransferBalance, // todo use NUs for adding these
|
|
101
|
-
}
|
|
102
|
-
})
|
|
80
|
+
return events
|
|
103
81
|
}
|
|
104
82
|
|
|
105
|
-
const getTokenTransactionHistory = ({
|
|
106
|
-
|
|
83
|
+
const getTokenTransactionHistory = ({
|
|
84
|
+
tick,
|
|
85
|
+
owner,
|
|
86
|
+
brc20Op,
|
|
87
|
+
showInvalid,
|
|
88
|
+
transactionIds,
|
|
89
|
+
limit,
|
|
90
|
+
offset,
|
|
91
|
+
}) => {
|
|
92
|
+
return paginatedTransactionHistory({
|
|
93
|
+
tick,
|
|
94
|
+
owner,
|
|
95
|
+
brc20Op,
|
|
96
|
+
showInvalid,
|
|
97
|
+
transactionIds,
|
|
98
|
+
limit,
|
|
99
|
+
offset,
|
|
100
|
+
})
|
|
107
101
|
}
|
|
108
102
|
|
|
109
103
|
return {
|
|
@@ -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,
|
|
@@ -36,7 +36,16 @@ export const getInscriptionAddresses = async ({
|
|
|
36
36
|
addressIndex: 0,
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const specialAddress3 = await aci.getAddress({
|
|
40
|
+
// xverse
|
|
41
|
+
assetName,
|
|
42
|
+
walletAccount,
|
|
43
|
+
purpose: 49,
|
|
44
|
+
chainIndex: 0,
|
|
45
|
+
addressIndex: 0,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const allAddresses = [specialAddress1, specialAddress2, specialAddress3, ...addresses].map((t) =>
|
|
40
49
|
t.address.toString()
|
|
41
50
|
)
|
|
42
51
|
return [...new Set(allAddresses)]
|
|
@@ -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,6 +9,61 @@ 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 }) {
|
|
13
|
+
const ordinalAddress = await getOrdinalAddress({
|
|
14
|
+
asset,
|
|
15
|
+
assetClientInterface: aci,
|
|
16
|
+
walletAccount,
|
|
17
|
+
ordinalChainIndex,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const accountState = await aci.getAccountState({
|
|
21
|
+
assetName: asset.name,
|
|
22
|
+
walletAccount,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
26
|
+
const storedUtxos = getUtxos({ accountState, asset })
|
|
27
|
+
const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
|
|
28
|
+
|
|
29
|
+
const knownUtxoIds = new Set(
|
|
30
|
+
[...allStoredUtxos].map((utxo) => `${utxo.txId}:${utxo.vout}`.toLowerCase())
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const additionalInscriptions = nfts
|
|
34
|
+
.filter((nft) => knownUtxoIds.has(nft.output.toLowerCase()))
|
|
35
|
+
.map((nft) => {
|
|
36
|
+
const output = nft.output.split(':')
|
|
37
|
+
return { txId: output[0], vout: parseInt(output[1]), inscriptionId: nft.tokenId }
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
if (!isEqual(accountState.additionalInscriptions || [], additionalInscriptions)) {
|
|
41
|
+
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
42
|
+
allUtxos: getUtxos({ accountState, asset }).union(
|
|
43
|
+
getOrdinalsUtxos({ accountState, asset })
|
|
44
|
+
),
|
|
45
|
+
ordinalsEnabled: true,
|
|
46
|
+
ordinalAddress,
|
|
47
|
+
mustAvoidUtxoIds: accountState.mustAvoidUtxoIds,
|
|
48
|
+
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
49
|
+
additionalInscriptions,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
await aci.updateAccountState({
|
|
53
|
+
walletAccount,
|
|
54
|
+
assetName: asset.name,
|
|
55
|
+
newData: {
|
|
56
|
+
utxos,
|
|
57
|
+
ordinalsUtxos,
|
|
58
|
+
additionalInscriptions,
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
return ordinalsUtxos
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return storedOrdinalsUtxos
|
|
65
|
+
}
|
|
66
|
+
|
|
12
67
|
return {
|
|
13
68
|
initialize: ({ assetClientInterface }) => {
|
|
14
69
|
aci = assetClientInterface
|
|
@@ -20,6 +75,7 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
20
75
|
console.warn('bitcoin nfts not initialized yet')
|
|
21
76
|
return []
|
|
22
77
|
}
|
|
78
|
+
|
|
23
79
|
return getInscriptionAddresses({
|
|
24
80
|
assetClientInterface: aci,
|
|
25
81
|
walletAccount: walletAccountInstance.toString(),
|
|
@@ -38,11 +94,12 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
38
94
|
return []
|
|
39
95
|
}
|
|
40
96
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
97
|
+
const walletAccount = walletAccountInstance.toString()
|
|
98
|
+
|
|
99
|
+
const storedOrdinalsUtxos = await processAdditionalInscriptions({
|
|
100
|
+
walletAccount,
|
|
101
|
+
nfts,
|
|
44
102
|
})
|
|
45
|
-
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
46
103
|
|
|
47
104
|
if (nftsProxy) {
|
|
48
105
|
const unconfirmedUtxosArray = storedOrdinalsUtxos
|
|
@@ -57,9 +114,10 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
57
114
|
try {
|
|
58
115
|
const retrievedNfts = await Promise.all(
|
|
59
116
|
uniqueInscriptionIds.map(async (inscriptionId) => {
|
|
60
|
-
if (nfts.
|
|
61
|
-
return
|
|
117
|
+
if (nfts.some((nft) => nft.tokenId === inscriptionId)) {
|
|
118
|
+
return
|
|
62
119
|
}
|
|
120
|
+
|
|
63
121
|
try {
|
|
64
122
|
const json = await nftsProxy.getNft(inscriptionId)
|
|
65
123
|
const utxo = unconfirmedUtxosArray.find((utxo) =>
|
|
@@ -77,11 +135,10 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
77
135
|
console.warn(
|
|
78
136
|
`Cannot load ${asset.name} nft ${inscriptionId} from proxy server. Error: ${e.message}`
|
|
79
137
|
)
|
|
80
|
-
return undefined
|
|
81
138
|
}
|
|
82
139
|
})
|
|
83
140
|
)
|
|
84
|
-
const unconfirmedNfts = retrievedNfts.flat().filter(
|
|
141
|
+
const unconfirmedNfts = retrievedNfts.flat().filter(Boolean)
|
|
85
142
|
nfts.push(...unconfirmedNfts)
|
|
86
143
|
} catch (e) {
|
|
87
144
|
console.warn(
|
|
@@ -90,22 +147,24 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
90
147
|
}
|
|
91
148
|
}
|
|
92
149
|
|
|
93
|
-
const unconfirmedTxs =
|
|
94
|
-
await aci.getTxLog({
|
|
95
|
-
walletAccount
|
|
150
|
+
const unconfirmedTxs = [
|
|
151
|
+
...(await aci.getTxLog({
|
|
152
|
+
walletAccount,
|
|
96
153
|
assetName: asset.name,
|
|
97
|
-
})
|
|
98
|
-
|
|
154
|
+
})),
|
|
155
|
+
].filter((tx) => !tx.confirmations)
|
|
99
156
|
|
|
100
|
-
const utxosOutputs =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
157
|
+
const utxosOutputs = new Set(
|
|
158
|
+
storedOrdinalsUtxos
|
|
159
|
+
.toArray()
|
|
160
|
+
.map((utxo) => {
|
|
161
|
+
return `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
162
|
+
})
|
|
163
|
+
.filter(Boolean)
|
|
164
|
+
)
|
|
106
165
|
|
|
107
166
|
const expandedNfts = nfts.map((nft) => {
|
|
108
|
-
const sending = !utxosOutputs.
|
|
167
|
+
const sending = !utxosOutputs.has(nft.output.toLowerCase())
|
|
109
168
|
|
|
110
169
|
const sendingTx =
|
|
111
170
|
sending &&
|
|
@@ -134,14 +193,15 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
134
193
|
assert(walletAccountInstance, 'walletAccount is required')
|
|
135
194
|
assert(newMustAvoidUtxoIds, 'mustAvoidUtxoIds is required')
|
|
136
195
|
|
|
137
|
-
if (!prune &&
|
|
196
|
+
if (!prune && newMustAvoidUtxoIds.length === 0) {
|
|
138
197
|
return
|
|
139
198
|
}
|
|
199
|
+
|
|
140
200
|
const walletAccount = walletAccountInstance.toString()
|
|
141
201
|
|
|
142
202
|
const accountState = await aci.getAccountState({
|
|
143
203
|
assetName: asset.name,
|
|
144
|
-
walletAccount
|
|
204
|
+
walletAccount,
|
|
145
205
|
})
|
|
146
206
|
|
|
147
207
|
const storedMustAvoidUtxosIds = accountState.mustAvoidUtxoIds || []
|
|
@@ -156,12 +216,12 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
156
216
|
...new Set([...storedMustAvoidUtxosIds, ...newMustAvoidUtxoIds].sort()),
|
|
157
217
|
]
|
|
158
218
|
|
|
159
|
-
const knownUtxoIds =
|
|
160
|
-
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
219
|
+
const knownUtxoIds = new Set(
|
|
220
|
+
[...allStoredUtxos].map((utxo) => `${utxo.txId}:${utxo.vout}`.toLowerCase())
|
|
161
221
|
)
|
|
162
222
|
|
|
163
223
|
const mustAvoidUtxoIds = prune
|
|
164
|
-
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.
|
|
224
|
+
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.has(id))
|
|
165
225
|
: allMustAvoidUtxoIds
|
|
166
226
|
|
|
167
227
|
if (isEqual(mustAvoidUtxoIds, storedMustAvoidUtxosIds)) {
|
|
@@ -172,15 +232,16 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
172
232
|
asset,
|
|
173
233
|
assetClientInterface: aci,
|
|
174
234
|
walletAccount,
|
|
175
|
-
ordinalChainIndex
|
|
235
|
+
ordinalChainIndex,
|
|
176
236
|
})
|
|
177
237
|
|
|
178
238
|
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
179
239
|
allUtxos: allStoredUtxos,
|
|
180
240
|
ordinalsEnabled: true,
|
|
181
|
-
ordinalAddress
|
|
182
|
-
mustAvoidUtxoIds
|
|
241
|
+
ordinalAddress,
|
|
242
|
+
mustAvoidUtxoIds,
|
|
183
243
|
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
244
|
+
additionalInscriptions: accountState.additionalInscriptions,
|
|
184
245
|
})
|
|
185
246
|
|
|
186
247
|
await aci.updateAccountState({
|
|
@@ -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 {
|
|
@@ -11,7 +11,7 @@ export const tickInscriptionIdIndexerFactory = ({ brc20Client }) => {
|
|
|
11
11
|
|
|
12
12
|
const loadDeployInscriptionId = async (brc20Tick) => {
|
|
13
13
|
const response = await brc20Client.getTickerInfo({ tick: brc20Tick })
|
|
14
|
-
const deployInscriptionId = response.
|
|
14
|
+
const deployInscriptionId = response[0].inscriptionId
|
|
15
15
|
save({ deployInscriptionId, brc20Tick })
|
|
16
16
|
return deployInscriptionId
|
|
17
17
|
}
|
|
@@ -41,6 +41,7 @@ export const tickInscriptionIdIndexerFactory = ({ brc20Client }) => {
|
|
|
41
41
|
save({ deployInscriptionId, brc20Tick })
|
|
42
42
|
return brc20Tick
|
|
43
43
|
}
|
|
44
|
+
|
|
44
45
|
return getBrc20Tick(deployInscriptionId)
|
|
45
46
|
}
|
|
46
47
|
|