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

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.9-hiro.0",
3
+ "version": "1.6.9",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,10 +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.6.8-hiro.0",
23
+ "@exodus/bitcoin-api": "^2.6.8",
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": "eae322a1c75f9cdaebc919af510619cb59ba4c0e"
29
30
  }
@@ -15,7 +15,6 @@ import {
15
15
  getFeeEstimatorFactory,
16
16
  GetFeeResolver,
17
17
  InsightAPIClient,
18
- isValidInscription,
19
18
  moveFundsFactory,
20
19
  parseUnsignedTx,
21
20
  signTxFactory,
@@ -34,8 +33,7 @@ import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
34
33
  import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
35
34
  import { getDefaultAddressPath, getSupportedPurposes } from './compatibility-modes'
36
35
 
37
- export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) => ({
38
- apiUrl: customApiUrl,
36
+ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) => ({
39
37
  allowUnconfirmedRbfEnabledUtxos = false,
40
38
  ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
41
39
  ordinalsEnabled = false,
@@ -44,7 +42,6 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
44
42
  refreshGapLimit = 25,
45
43
  overrideCallback = ({ asset }) => asset,
46
44
  } = {}) => {
47
- const apiUrl = customApiUrl || defaultApiUrl
48
45
  assert(asset, 'asset is required')
49
46
  assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
50
47
  assert(apiUrl, 'apiUrl is required')
@@ -55,9 +52,6 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
55
52
  const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
56
53
 
57
54
  const insightClient = new InsightAPIClient(apiUrl)
58
-
59
- if (customApiUrl) insightClient.setBaseUrl = () => {} // not let the configuration override url when providing a custom one
60
-
61
55
  const useBip84 = true
62
56
  const useBip86 = true
63
57
 
@@ -111,7 +105,6 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
111
105
  const baseSendTx = createAndBroadcastTXFactory({
112
106
  getFeeEstimator,
113
107
  allowUnconfirmedRbfEnabledUtxos,
114
- ordinalsEnabled,
115
108
  })
116
109
  const inscriptionsService = brc20Enabled
117
110
  ? inscriptionsServiceFactory({
@@ -212,18 +205,8 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinIn
212
205
  }
213
206
 
214
207
  const isOrdinalTx = (tx) => {
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
- )
208
+ const isInscription = tx.data?.isInscriptionSent || tx.data?.isInscriptionReceived
209
+ return ordinalsEnabled && tx.coinName === asset.name && isInscription
227
210
  }
228
211
 
229
212
  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
- .flatMap((utxo) => utxo.inscriptions?.map((i) => i.inscriptionId))
11
+ .map((utxo) => utxo.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'
3
4
  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,22 +27,26 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
27
27
  },
28
28
 
29
29
  /*
30
- It flags the nfts in transfer, that don't have a utxo anymore
31
- It removes nfts that have brc20 content
32
- */
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
+ */
33
34
  postProcessNfts: async ({ nfts, walletAccount: walletAccountInstance }) => {
34
35
  if (!aci) {
35
36
  console.warn('bitcoin nfts not initialized yet')
36
37
  return []
37
38
  }
38
39
 
39
- const accountState = await aci.getAccountState({
40
- assetName: asset.name,
40
+ const outputToInscriptionId = Object.fromEntries(nfts.map((nft) => [nft.output, nft.tokenId]))
41
+
42
+ const { allUpdatedUtxos } = await updateAccountStateUtxos({
43
+ asset,
41
44
  walletAccount: walletAccountInstance.toString(),
45
+ assetClientInterface: aci,
46
+ outputToInscriptionId,
47
+ ordinalChainIndex,
42
48
  })
43
- const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
44
-
45
- const utxosOutputs = storedOrdinalsUtxos
49
+ const utxosOutputs = allUpdatedUtxos
46
50
  .toArray()
47
51
  .map((utxo) => {
48
52
  return `${utxo.txId}:${utxo.vout}`.toLowerCase()
@@ -0,0 +1,62 @@
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
+ }
@@ -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
+ import { updateAccountStateUtxos } from './ordinals-account-state-utils'
4
5
  const toTxLog = ({ historyItem, baseAsset, asset }) => {
5
6
  const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
6
7
 
@@ -68,6 +69,7 @@ export const reloadBrc20TokenBalances = async ({
68
69
  }, new Map())
69
70
 
70
71
  const unknownDeployInscriptionIds = new Set()
72
+ const knownInscriptionIds = new Set()
71
73
 
72
74
  const brc20History = (
73
75
  await Promise.all(
@@ -79,6 +81,8 @@ export const reloadBrc20TokenBalances = async ({
79
81
  const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
80
82
  token.brc20Tick
81
83
  )
84
+ knownInscriptionIds.add(deployInscriptionId)
85
+ knownInscriptionIds.add(token.inscriptionId.toLowerCase())
82
86
  const assetName = assetByAssetId.get(deployInscriptionId)?.name
83
87
  if (assetName) {
84
88
  return { ...token, address, assetName, deployInscriptionId }
@@ -145,10 +149,15 @@ export const reloadBrc20TokenBalances = async ({
145
149
  })
146
150
  )
147
151
 
148
- await assetClientInterface.updateAccountState({
149
- assetName: asset.name,
152
+ await updateAccountStateUtxos({
153
+ asset,
150
154
  walletAccount,
151
- newData: { brc20Balances },
155
+ assetClientInterface,
156
+ knownInscriptionIds: [...knownInscriptionIds],
157
+ ordinalChainIndex,
158
+ moreNewData: {
159
+ brc20Balances,
160
+ },
152
161
  })
153
162
 
154
163
  return {