@exodus/bitcoin-plugin 1.0.6-ordinals.2 → 1.0.8
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 +4 -4
- package/src/create-asset.js +4 -24
- package/src/nfts.js +0 -109
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@exodus/asset-lib": "^3.7.1",
|
|
22
|
-
"@exodus/bitcoin-api": "^2.3.
|
|
22
|
+
"@exodus/bitcoin-api": "^2.3.10",
|
|
23
23
|
"@exodus/bitcoin-lib": "^2.2.5",
|
|
24
24
|
"minimalistic-assert": "^1.0.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@exodus/nfts-proxy": "^2.6.0",
|
|
28
27
|
"@exodus/keychain": "^3.0.0"
|
|
29
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "8d1b4e435fbb69abe1261aba737748d6443b759b"
|
|
30
30
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -24,15 +24,11 @@ import {
|
|
|
24
24
|
import { bitcoinFeeDataFactory } from './fee-data'
|
|
25
25
|
import BitcoinFeeMonitor from './fee-monitor'
|
|
26
26
|
import assert from 'minimalistic-assert'
|
|
27
|
-
import { nftsApiFactory } from './nfts'
|
|
28
27
|
|
|
29
28
|
export const createBitcoinAssetFactory = ({ base, apiUrl, coinInfoNetwork }) => ({
|
|
30
29
|
allowUnconfirmedRbfEnabledUtxos = false,
|
|
31
|
-
ordinalChainIndex = 2,
|
|
32
|
-
ordinalsEnabled = false,
|
|
33
30
|
overrideCallback = ({ asset }) => asset,
|
|
34
31
|
} = {}) => {
|
|
35
|
-
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
36
32
|
assert(base, 'base is required')
|
|
37
33
|
assert(apiUrl, 'apiUrl is required')
|
|
38
34
|
const asset = connectAsset(base)
|
|
@@ -64,7 +60,6 @@ export const createBitcoinAssetFactory = ({ base, apiUrl, coinInfoNetwork }) =>
|
|
|
64
60
|
feesApi: true,
|
|
65
61
|
moveFunds: true,
|
|
66
62
|
multipleAddresses: true,
|
|
67
|
-
nfts: ordinalsEnabled,
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
const getFeeEstimator = getFeeEstimatorFactory({
|
|
@@ -107,28 +102,17 @@ export const createBitcoinAssetFactory = ({ base, apiUrl, coinInfoNetwork }) =>
|
|
|
107
102
|
|
|
108
103
|
const getBalances = getBalancesFactory({ feeData, getSpendableBalance })
|
|
109
104
|
|
|
110
|
-
const createHistoryMonitor = (args) =>
|
|
111
|
-
createBitcoinMonitor({
|
|
112
|
-
insightClient,
|
|
113
|
-
ordinalsEnabled,
|
|
114
|
-
ordinalChainIndex,
|
|
115
|
-
apiUrl,
|
|
116
|
-
...args,
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
const createFeeMonitor = (args) =>
|
|
120
|
-
new BitcoinFeeMonitor({ ...args, insight: () => insightClient, assetName: asset.name })
|
|
121
|
-
|
|
122
105
|
const api = {
|
|
123
106
|
defaultAddressPath: 'm/0/0',
|
|
124
107
|
broadcastTx: (...args) => insightClient.broadcastTx(...args),
|
|
125
|
-
createFeeMonitor
|
|
126
|
-
|
|
108
|
+
createFeeMonitor: (args) =>
|
|
109
|
+
new BitcoinFeeMonitor({ ...args, insight: () => insightClient, assetName: asset.name }),
|
|
110
|
+
createHistoryMonitor: (args) => createBitcoinMonitor({ insightClient, apiUrl, ...args }),
|
|
127
111
|
getFeeData: () => feeData,
|
|
128
112
|
getBalances,
|
|
129
113
|
getKeyIdentifier: createGetKeyIdentifier({ bip44 }),
|
|
130
114
|
hasFeature: (feature) => !!features[feature],
|
|
131
|
-
createAccountState: () => createAccountState({ asset: asset
|
|
115
|
+
createAccountState: () => createAccountState({ asset: asset }),
|
|
132
116
|
parseUnsignedTx,
|
|
133
117
|
parseTx: ({ unsignedTx }) => parseUnsignedTx(unsignedTx),
|
|
134
118
|
signUnsignedTx: (unsignedTx, privateKey, opts) => signTx({ unsignedTx, privateKey, ...opts }), // legacy
|
|
@@ -136,10 +120,6 @@ export const createBitcoinAssetFactory = ({ base, apiUrl, coinInfoNetwork }) =>
|
|
|
136
120
|
signTx,
|
|
137
121
|
getFee,
|
|
138
122
|
moveFunds,
|
|
139
|
-
initialize: ({ assetClientInterface }) => {
|
|
140
|
-
// workaround until createAsset receives assetClientInterface
|
|
141
|
-
api.nfts = nftsApiFactory({ assetClientInterface, ordinalChainIndex, asset })
|
|
142
|
-
},
|
|
143
123
|
}
|
|
144
124
|
|
|
145
125
|
const fullAsset = {
|
package/src/nfts.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import assert from 'minimalistic-assert'
|
|
2
|
-
import { getOrdinalsUtxos, getUtxos, partitionUtxos } from '@exodus/bitcoin-api'
|
|
3
|
-
import { UtxoCollection } from '@exodus/models'
|
|
4
|
-
import { pickBy } from 'lodash'
|
|
5
|
-
|
|
6
|
-
export const nftsApiFactory = ({ assetClientInterface: aci, ordinalChainIndex, asset }) => {
|
|
7
|
-
assert(aci, 'assetClientInterface is required')
|
|
8
|
-
assert(asset, 'asset is required')
|
|
9
|
-
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
10
|
-
const assetName = asset.name
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
// this extension returns all possible addresses that may contain nfts
|
|
14
|
-
getNftsAddresses: async ({ walletAccount: walletAccountInstance }) => {
|
|
15
|
-
const walletAccount = walletAccountInstance.toString()
|
|
16
|
-
const accountState = await aci.getAccountState({ walletAccount, assetName })
|
|
17
|
-
|
|
18
|
-
// all the known utxos addresses are monitored,
|
|
19
|
-
// just in case the user received it to a standard btc address
|
|
20
|
-
const allUtxos = accountState.ordinalsUtxos.union(accountState.utxos)
|
|
21
|
-
const addresses = allUtxos.toArray().map((utxos) => utxos.address)
|
|
22
|
-
const specialAddress1 = await aci.getAddress({
|
|
23
|
-
assetName,
|
|
24
|
-
walletAccount,
|
|
25
|
-
purpose: 86,
|
|
26
|
-
chainIndex: ordinalChainIndex,
|
|
27
|
-
addressIndex: 0,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
const specialAddress2 = await aci.getAddress({
|
|
31
|
-
assetName,
|
|
32
|
-
walletAccount,
|
|
33
|
-
purpose: 86,
|
|
34
|
-
chainIndex: 0,
|
|
35
|
-
addressIndex: 0,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const allAddresses = [specialAddress1, specialAddress2, ...addresses].map((t) =>
|
|
39
|
-
t.address.toString()
|
|
40
|
-
)
|
|
41
|
-
return [...new Set(allAddresses)]
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
/*
|
|
45
|
-
This extension performs 2 operations.
|
|
46
|
-
1. It updates the utxo.data.inscriptionId if there is a nft found via the monitor
|
|
47
|
-
2. It removes nfts that are in transit, monitor still founds them even when the utxos doesn't exist (it was spent)
|
|
48
|
-
*/
|
|
49
|
-
postProcessNfts: async ({ nfts, walletAccount: walletAccountInstance }) => {
|
|
50
|
-
const walletAccount = walletAccountInstance.toString()
|
|
51
|
-
const accountState = await aci.getAccountState({ assetName, walletAccount })
|
|
52
|
-
const storedUtxos = getUtxos({ accountState, asset })
|
|
53
|
-
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
54
|
-
|
|
55
|
-
const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
|
|
56
|
-
const allUpdatedUtxos = UtxoCollection.fromArray(
|
|
57
|
-
allStoredUtxos.toArray().map((utxo) => {
|
|
58
|
-
if (utxo.inscriptionId) {
|
|
59
|
-
return utxo
|
|
60
|
-
}
|
|
61
|
-
const output = `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
62
|
-
const inscriptionId = nfts.find((nft) => nft.output.toLowerCase() === output)?.tokenId
|
|
63
|
-
if (inscriptionId) {
|
|
64
|
-
return { ...utxo, inscriptionId }
|
|
65
|
-
}
|
|
66
|
-
return utxo
|
|
67
|
-
}),
|
|
68
|
-
{
|
|
69
|
-
currency: asset.currency,
|
|
70
|
-
}
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
if (!allUpdatedUtxos.equals(allStoredUtxos)) {
|
|
74
|
-
// nfts sever has found a new inscription
|
|
75
|
-
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
76
|
-
allUtxos: allUpdatedUtxos,
|
|
77
|
-
ordinalChainIndex: ordinalChainIndex,
|
|
78
|
-
})
|
|
79
|
-
await aci.updateAccountState({
|
|
80
|
-
assetName,
|
|
81
|
-
walletAccount,
|
|
82
|
-
newData: pickBy(
|
|
83
|
-
{
|
|
84
|
-
utxos,
|
|
85
|
-
ordinalsUtxos,
|
|
86
|
-
},
|
|
87
|
-
Boolean
|
|
88
|
-
),
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const utxosOutputs = allUpdatedUtxos
|
|
93
|
-
.toArray()
|
|
94
|
-
.map((utxo) => {
|
|
95
|
-
return `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
96
|
-
})
|
|
97
|
-
.filter(Boolean)
|
|
98
|
-
|
|
99
|
-
const filteredNfts = nfts.filter((nft) => utxosOutputs.includes(nft.output.toLowerCase()))
|
|
100
|
-
if (filteredNfts.length !== nfts.length) {
|
|
101
|
-
console.log(
|
|
102
|
-
'Ordinal NFTs in transit',
|
|
103
|
-
nfts.filter((nft) => !utxosOutputs.includes(nft.output.toLowerCase()))
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
return filteredNfts
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
}
|