@exodus/bitcoin-plugin 1.6.8 → 1.6.9-hiro.0

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.8",
3
+ "version": "1.6.9-hiro.0",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,11 +20,10 @@
20
20
  "dependencies": {
21
21
  "@exodus/asset-lib": "^4.0.0",
22
22
  "@exodus/basic-utils": "^2.1.0",
23
- "@exodus/bitcoin-api": "^2.6.7",
23
+ "@exodus/bitcoin-api": "^2.6.8-hiro.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
- },
29
- "gitHead": "04954f04a1246db5d0cc3fd848ef23a91df2b623"
28
+ }
30
29
  }
@@ -15,6 +15,7 @@ import {
15
15
  getFeeEstimatorFactory,
16
16
  GetFeeResolver,
17
17
  InsightAPIClient,
18
+ isValidInscription,
18
19
  moveFundsFactory,
19
20
  parseUnsignedTx,
20
21
  signTxFactory,
@@ -33,7 +34,8 @@ import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
33
34
  import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
34
35
  import { getDefaultAddressPath, getSupportedPurposes } from './compatibility-modes'
35
36
 
36
- export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) => ({
37
+ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) => ({
38
+ apiUrl: customApiUrl,
37
39
  allowUnconfirmedRbfEnabledUtxos = false,
38
40
  ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
39
41
  ordinalsEnabled = false,
@@ -42,6 +44,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
42
44
  refreshGapLimit = 25,
43
45
  overrideCallback = ({ asset }) => asset,
44
46
  } = {}) => {
47
+ const apiUrl = customApiUrl || defaultApiUrl
45
48
  assert(asset, 'asset is required')
46
49
  assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
47
50
  assert(apiUrl, 'apiUrl is required')
@@ -52,6 +55,9 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
52
55
  const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
53
56
 
54
57
  const insightClient = new InsightAPIClient(apiUrl)
58
+
59
+ if (customApiUrl) insightClient.setBaseUrl = () => {} // not let the configuration override url when providing a custom one
60
+
55
61
  const useBip84 = true
56
62
  const useBip86 = true
57
63
 
@@ -105,6 +111,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
105
111
  const baseSendTx = createAndBroadcastTXFactory({
106
112
  getFeeEstimator,
107
113
  allowUnconfirmedRbfEnabledUtxos,
114
+ ordinalsEnabled,
108
115
  })
109
116
  const inscriptionsService = brc20Enabled
110
117
  ? inscriptionsServiceFactory({
@@ -205,8 +212,18 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
205
212
  }
206
213
 
207
214
  const isOrdinalTx = (tx) => {
208
- const isInscription = tx.data?.isInscriptionSent || tx.data?.isInscriptionReceived
209
- return ordinalsEnabled && tx.coinName === asset.name && isInscription
215
+ if (!ordinalsEnabled || tx.coinName !== asset.name) {
216
+ return false
217
+ }
218
+
219
+ if (!tx.data.inscriptionsIndexed) {
220
+ return false // allows users seeing the pending tx because we don't know yet if it is ordinals or btc
221
+ }
222
+
223
+ return (
224
+ tx.data.receivedInscriptions?.some(isValidInscription) ||
225
+ tx.data.sentInscriptions?.some(isValidInscription)
226
+ )
210
227
  }
211
228
 
212
229
  const txLogFilter = (tx) => {
@@ -8,7 +8,7 @@ export const brc20Utils = {
8
8
  assert(asset, 'asset is required')
9
9
  return getOrdinalsUtxos({ accountState, asset })
10
10
  .toArray()
11
- .map((utxo) => utxo.inscriptionId)
11
+ .flatMap((utxo) => utxo.inscriptions?.map((i) => i.inscriptionId))
12
12
  },
13
13
 
14
14
  getAllTransferableList: ({ accountState, asset }) => {
@@ -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
- This extension performs 2 operations.
31
- 1. It updates the utxo.data.inscriptionId if there is a nft found via the monitor
32
- 2. It removes nfts that are in transit, monitor still founds them even when the utxos doesn't exist (it was spent)
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 outputToInscriptionId = Object.fromEntries(nfts.map((nft) => [nft.output, nft.tokenId]))
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 utxosOutputs = allUpdatedUtxos
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()
@@ -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 updateAccountStateUtxos({
153
- asset,
148
+ await assetClientInterface.updateAccountState({
149
+ assetName: asset.name,
154
150
  walletAccount,
155
- assetClientInterface,
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
- }