@exodus/bitcoin-plugin 1.6.9 → 1.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.10",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@exodus/asset-lib": "^4.0.0",
|
|
22
22
|
"@exodus/basic-utils": "^2.1.0",
|
|
23
|
-
"@exodus/bitcoin-api": "^2.
|
|
23
|
+
"@exodus/bitcoin-api": "^2.7.0",
|
|
24
24
|
"@exodus/bitcoin-lib": "^2.2.11",
|
|
25
25
|
"@exodus/models": "^11.0.0",
|
|
26
26
|
"@exodus/text-encoding-utf8": "^1.0.2",
|
|
27
27
|
"minimalistic-assert": "^1.0.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "5c306496cb4086ff823640e8eadb0d9750ac3683"
|
|
30
30
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
getFeeEstimatorFactory,
|
|
16
16
|
GetFeeResolver,
|
|
17
17
|
InsightAPIClient,
|
|
18
|
+
isValidInscription,
|
|
18
19
|
moveFundsFactory,
|
|
19
20
|
parseUnsignedTx,
|
|
20
21
|
signTxFactory,
|
|
22
|
+
signHardwareFactory,
|
|
21
23
|
} from '@exodus/bitcoin-api'
|
|
22
24
|
import { bitcoinFeeDataFactory } from './fee-data'
|
|
23
25
|
import BitcoinFeeMonitor from './fee-monitor'
|
|
@@ -33,7 +35,8 @@ import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
|
|
|
33
35
|
import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
|
|
34
36
|
import { getDefaultAddressPath, getSupportedPurposes } from './compatibility-modes'
|
|
35
37
|
|
|
36
|
-
export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) => ({
|
|
38
|
+
export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) => ({
|
|
39
|
+
apiUrl: customApiUrl,
|
|
37
40
|
allowUnconfirmedRbfEnabledUtxos = false,
|
|
38
41
|
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
39
42
|
ordinalsEnabled = false,
|
|
@@ -41,7 +44,9 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
41
44
|
gapLimit = 10,
|
|
42
45
|
refreshGapLimit = 25,
|
|
43
46
|
overrideCallback = ({ asset }) => asset,
|
|
47
|
+
feeDataCustomValues,
|
|
44
48
|
} = {}) => {
|
|
49
|
+
const apiUrl = customApiUrl || defaultApiUrl
|
|
45
50
|
assert(asset, 'asset is required')
|
|
46
51
|
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
47
52
|
assert(apiUrl, 'apiUrl is required')
|
|
@@ -52,6 +57,9 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
52
57
|
const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
|
|
53
58
|
|
|
54
59
|
const insightClient = new InsightAPIClient(apiUrl)
|
|
60
|
+
|
|
61
|
+
if (customApiUrl) insightClient.setBaseUrl = () => {} // not let the configuration override url when providing a custom one
|
|
62
|
+
|
|
55
63
|
const useBip84 = true
|
|
56
64
|
const useBip86 = true
|
|
57
65
|
|
|
@@ -90,7 +98,10 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
90
98
|
allowUnconfirmedRbfEnabledUtxos,
|
|
91
99
|
})
|
|
92
100
|
|
|
93
|
-
const feeData = bitcoinFeeDataFactory(
|
|
101
|
+
const feeData = bitcoinFeeDataFactory({
|
|
102
|
+
currency: asset.currency,
|
|
103
|
+
overrideDefaults: feeDataCustomValues,
|
|
104
|
+
})
|
|
94
105
|
|
|
95
106
|
const baseGetBalances = getBalancesFactory({
|
|
96
107
|
feeData,
|
|
@@ -105,6 +116,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
105
116
|
const baseSendTx = createAndBroadcastTXFactory({
|
|
106
117
|
getFeeEstimator,
|
|
107
118
|
allowUnconfirmedRbfEnabledUtxos,
|
|
119
|
+
ordinalsEnabled,
|
|
108
120
|
})
|
|
109
121
|
const inscriptionsService = brc20Enabled
|
|
110
122
|
? inscriptionsServiceFactory({
|
|
@@ -138,6 +150,13 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
138
150
|
coinInfo,
|
|
139
151
|
})
|
|
140
152
|
|
|
153
|
+
const signHardware = signHardwareFactory({
|
|
154
|
+
assetName: asset.name,
|
|
155
|
+
resolvePurpose: address.resolvePurpose,
|
|
156
|
+
keys,
|
|
157
|
+
coinInfo,
|
|
158
|
+
})
|
|
159
|
+
|
|
141
160
|
const moveFunds = moveFundsFactory({
|
|
142
161
|
asset: asset,
|
|
143
162
|
insightClient,
|
|
@@ -205,8 +224,18 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
205
224
|
}
|
|
206
225
|
|
|
207
226
|
const isOrdinalTx = (tx) => {
|
|
208
|
-
|
|
209
|
-
|
|
227
|
+
if (!ordinalsEnabled || tx.coinName !== asset.name) {
|
|
228
|
+
return false
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!tx.data.inscriptionsIndexed) {
|
|
232
|
+
return false // allows users seeing the pending tx because we don't know yet if it is ordinals or btc
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return (
|
|
236
|
+
tx.data.receivedInscriptions?.some(isValidInscription) ||
|
|
237
|
+
tx.data.sentInscriptions?.some(isValidInscription)
|
|
238
|
+
)
|
|
210
239
|
}
|
|
211
240
|
|
|
212
241
|
const txLogFilter = (tx) => {
|
|
@@ -269,6 +298,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
269
298
|
signUnsignedTx: (unsignedTx, privateKey, opts) => signTx({ unsignedTx, privateKey, ...opts }), // legacy
|
|
270
299
|
sendTx,
|
|
271
300
|
signTx,
|
|
301
|
+
signHardware,
|
|
272
302
|
getFee,
|
|
273
303
|
moveFunds,
|
|
274
304
|
nfts,
|
package/src/fee-data.js
CHANGED
|
@@ -11,6 +11,7 @@ export const _defaults = {
|
|
|
11
11
|
rbfBumpFeeBlocks: 3,
|
|
12
12
|
rbfBumpFeeThreshold: 0.8,
|
|
13
13
|
rbfEnabled: true,
|
|
14
|
+
utxoDustValue: 0,
|
|
14
15
|
}
|
|
15
|
-
export const bitcoinFeeDataFactory = (currency) =>
|
|
16
|
-
new FeeData({ config: _defaults, mainKey: 'feePerKB', currency })
|
|
16
|
+
export const bitcoinFeeDataFactory = ({ currency, overrideDefaults }) =>
|
|
17
|
+
new FeeData({ config: { ..._defaults, ...overrideDefaults }, mainKey: 'feePerKB', currency })
|
|
@@ -8,7 +8,7 @@ export const brc20Utils = {
|
|
|
8
8
|
assert(asset, 'asset is required')
|
|
9
9
|
return getOrdinalsUtxos({ accountState, asset })
|
|
10
10
|
.toArray()
|
|
11
|
-
.
|
|
11
|
+
.flatMap((utxo) => utxo.inscriptions?.map((i) => i.inscriptionId))
|
|
12
12
|
},
|
|
13
13
|
|
|
14
14
|
getAllTransferableList: ({ accountState, asset }) => {
|
package/src/ordinals/nfts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
|
-
import { updateAccountStateUtxos } from './ordinals-account-state-utils'
|
|
4
3
|
import { isNftBrc20 } from './nft-utils'
|
|
4
|
+
import { getOrdinalsUtxos } from '@exodus/bitcoin-api'
|
|
5
5
|
|
|
6
6
|
export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
7
7
|
assert(asset, 'asset is required')
|
|
@@ -27,26 +27,22 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
27
27
|
},
|
|
28
28
|
|
|
29
29
|
/*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
30
|
+
It flags the nfts in transfer, that don't have a utxo anymore
|
|
31
|
+
It removes nfts that have brc20 content
|
|
32
|
+
*/
|
|
34
33
|
postProcessNfts: async ({ nfts, walletAccount: walletAccountInstance }) => {
|
|
35
34
|
if (!aci) {
|
|
36
35
|
console.warn('bitcoin nfts not initialized yet')
|
|
37
36
|
return []
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const { allUpdatedUtxos } = await updateAccountStateUtxos({
|
|
43
|
-
asset,
|
|
39
|
+
const accountState = await aci.getAccountState({
|
|
40
|
+
assetName: asset.name,
|
|
44
41
|
walletAccount: walletAccountInstance.toString(),
|
|
45
|
-
assetClientInterface: aci,
|
|
46
|
-
outputToInscriptionId,
|
|
47
|
-
ordinalChainIndex,
|
|
48
42
|
})
|
|
49
|
-
const
|
|
43
|
+
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
44
|
+
|
|
45
|
+
const utxosOutputs = storedOrdinalsUtxos
|
|
50
46
|
.toArray()
|
|
51
47
|
.map((utxo) => {
|
|
52
48
|
return `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
@@ -55,6 +51,7 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
55
51
|
|
|
56
52
|
const expandedNfts = nfts.map((nft) => ({
|
|
57
53
|
...nft,
|
|
54
|
+
collectionName: nft.collectionName || 'No Collection',
|
|
58
55
|
inTransit: !utxosOutputs.includes(nft.output.toLowerCase()),
|
|
59
56
|
}))
|
|
60
57
|
|
|
@@ -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
|
-
import { updateAccountStateUtxos } from './ordinals-account-state-utils'
|
|
5
4
|
const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
6
5
|
const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
|
|
7
6
|
|
|
@@ -69,7 +68,6 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
69
68
|
}, new Map())
|
|
70
69
|
|
|
71
70
|
const unknownDeployInscriptionIds = new Set()
|
|
72
|
-
const knownInscriptionIds = new Set()
|
|
73
71
|
|
|
74
72
|
const brc20History = (
|
|
75
73
|
await Promise.all(
|
|
@@ -81,8 +79,6 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
81
79
|
const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
|
|
82
80
|
token.brc20Tick
|
|
83
81
|
)
|
|
84
|
-
knownInscriptionIds.add(deployInscriptionId)
|
|
85
|
-
knownInscriptionIds.add(token.inscriptionId.toLowerCase())
|
|
86
82
|
const assetName = assetByAssetId.get(deployInscriptionId)?.name
|
|
87
83
|
if (assetName) {
|
|
88
84
|
return { ...token, address, assetName, deployInscriptionId }
|
|
@@ -149,15 +145,10 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
149
145
|
})
|
|
150
146
|
)
|
|
151
147
|
|
|
152
|
-
await
|
|
153
|
-
asset,
|
|
148
|
+
await assetClientInterface.updateAccountState({
|
|
149
|
+
assetName: asset.name,
|
|
154
150
|
walletAccount,
|
|
155
|
-
|
|
156
|
-
knownInscriptionIds: [...knownInscriptionIds],
|
|
157
|
-
ordinalChainIndex,
|
|
158
|
-
moreNewData: {
|
|
159
|
-
brc20Balances,
|
|
160
|
-
},
|
|
151
|
+
newData: { brc20Balances },
|
|
161
152
|
})
|
|
162
153
|
|
|
163
154
|
return {
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getOrdinalsUtxos, getUtxos, partitionUtxos, getOrdinalAddress } from '@exodus/bitcoin-api'
|
|
2
|
-
import { UtxoCollection } from '@exodus/models'
|
|
3
|
-
import { isEmpty, pickBy } from 'lodash'
|
|
4
|
-
import { getOwnProperty } from '@exodus/basic-utils'
|
|
5
|
-
|
|
6
|
-
export const updateAccountStateUtxos = async ({
|
|
7
|
-
asset,
|
|
8
|
-
walletAccount,
|
|
9
|
-
assetClientInterface: aci,
|
|
10
|
-
outputToInscriptionId,
|
|
11
|
-
ordinalChainIndex,
|
|
12
|
-
moreNewData = {},
|
|
13
|
-
}) => {
|
|
14
|
-
const assetName = asset.name
|
|
15
|
-
const accountState = await aci.getAccountState({ assetName, walletAccount })
|
|
16
|
-
const storedUtxos = getUtxos({ accountState, asset })
|
|
17
|
-
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
18
|
-
|
|
19
|
-
const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
|
|
20
|
-
const allUpdatedUtxos = UtxoCollection.fromArray(
|
|
21
|
-
allStoredUtxos.toArray().map((utxo) => {
|
|
22
|
-
const inscriptionId = getOwnProperty(
|
|
23
|
-
outputToInscriptionId,
|
|
24
|
-
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
25
|
-
)
|
|
26
|
-
if (inscriptionId) {
|
|
27
|
-
return { ...utxo, inscriptionId }
|
|
28
|
-
}
|
|
29
|
-
return utxo
|
|
30
|
-
}),
|
|
31
|
-
{
|
|
32
|
-
currency: asset.currency,
|
|
33
|
-
}
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
const ordinalAddress = await getOrdinalAddress({
|
|
37
|
-
asset,
|
|
38
|
-
assetClientInterface: aci,
|
|
39
|
-
walletAccount,
|
|
40
|
-
ordinalChainIndex,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
if (!allUpdatedUtxos.equals(allStoredUtxos) || !isEmpty(moreNewData)) {
|
|
44
|
-
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
45
|
-
allUtxos: allUpdatedUtxos,
|
|
46
|
-
ordinalAddress,
|
|
47
|
-
})
|
|
48
|
-
const utxosData = pickBy(
|
|
49
|
-
{
|
|
50
|
-
utxos,
|
|
51
|
-
ordinalsUtxos,
|
|
52
|
-
},
|
|
53
|
-
Boolean
|
|
54
|
-
)
|
|
55
|
-
await aci.updateAccountState({
|
|
56
|
-
assetName,
|
|
57
|
-
walletAccount,
|
|
58
|
-
newData: { ...utxosData, ...moreNewData },
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
return { allUpdatedUtxos }
|
|
62
|
-
}
|