@exodus/bitcoin-plugin 1.7.0 → 1.8.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.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,7 +20,7 @@
|
|
|
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.9.0",
|
|
24
24
|
"@exodus/bitcoin-lib": "^2.3.0",
|
|
25
25
|
"@exodus/models": "^11.0.0",
|
|
26
26
|
"@exodus/text-encoding-utf8": "^1.0.2",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@exodus/nfts-proxy": "^2.10.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "ed03529f7a8bb4b39bfd173387f9cdd5d7207925"
|
|
33
33
|
}
|
|
@@ -41,12 +41,12 @@ export const brc20ApiClientFactory = ({
|
|
|
41
41
|
|
|
42
42
|
const getOwnerTickBalances = async ({ address }) => {
|
|
43
43
|
assert(address, 'address is required')
|
|
44
|
-
return request(`/v2/ord/
|
|
44
|
+
return request(`/v2/ord/brc20/balances/${encodeURIComponent(address)}`)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const getTickerInfo = async ({ tick }) => {
|
|
48
48
|
assert(tick, 'tick is required')
|
|
49
|
-
return request(`/v2/ord/
|
|
49
|
+
return request(`/v2/ord/brc20/tokens/${encodeURIComponent(tick)}`)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const getTickerInfoByDeployInscriptionId = async ({ deployInscriptionId }) => {
|
|
@@ -56,48 +56,56 @@ export const brc20ApiClientFactory = ({
|
|
|
56
56
|
)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const removeNullUndefined = (obj) =>
|
|
60
|
-
Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined))
|
|
61
|
-
|
|
62
59
|
const paginatedTransactionHistory = async (queryParams) => {
|
|
63
|
-
const
|
|
60
|
+
const address = queryParams.address
|
|
61
|
+
assert(address, 'address is required')
|
|
64
62
|
const events = []
|
|
65
63
|
const limit = queryParams.limit || 40
|
|
66
64
|
let offset = queryParams.offset || 0
|
|
67
65
|
let response
|
|
68
66
|
do {
|
|
69
|
-
response = await request(
|
|
70
|
-
...resolvedQueryParams,
|
|
67
|
+
response = await request(`/v2/ord/brc20/history/${encodeURIComponent(address)}`, {
|
|
71
68
|
limit,
|
|
72
69
|
offset,
|
|
73
70
|
})
|
|
74
71
|
offset = offset + limit
|
|
75
|
-
events.push(...response.
|
|
72
|
+
events.push(...response.results)
|
|
76
73
|
} while (offset < response.total)
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
// remap to previous event shape that later logic expects
|
|
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
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
transactionIds,
|
|
96
|
-
limit,
|
|
97
|
-
offset,
|
|
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
|
+
}
|
|
98
102
|
})
|
|
99
103
|
}
|
|
100
104
|
|
|
105
|
+
const getTokenTransactionHistory = ({ ticker, offset, limit, address }) => {
|
|
106
|
+
return paginatedTransactionHistory({ ticker, offset, limit, address })
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
return {
|
|
102
110
|
setUrl,
|
|
103
111
|
getOwnerTickBalances,
|
package/src/ordinals/nfts.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
3
|
import { isNftBrc20 } from './nft-utils'
|
|
4
|
-
import { getOrdinalsUtxos } from '@exodus/bitcoin-api'
|
|
5
|
-
import { uniq } from 'lodash'
|
|
4
|
+
import { getOrdinalAddress, getOrdinalsUtxos, getUtxos, partitionUtxos } from '@exodus/bitcoin-api'
|
|
5
|
+
import { uniq, isEqual } from 'lodash'
|
|
6
6
|
|
|
7
7
|
export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
8
8
|
assert(asset, 'asset is required')
|
|
@@ -124,5 +124,74 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
124
124
|
.filter((nft) => !isNftBrc20(nft))
|
|
125
125
|
.map((nft) => ({ ...nft, collectionName: nft.collectionName || 'No Collection' }))
|
|
126
126
|
},
|
|
127
|
+
|
|
128
|
+
addMustAvoidUtxoIds: async ({
|
|
129
|
+
walletAccount: walletAccountInstance,
|
|
130
|
+
mustAvoidUtxoIds: newMustAvoidUtxoIds,
|
|
131
|
+
prune = false,
|
|
132
|
+
}) => {
|
|
133
|
+
assert(aci, 'bitcoin nfts not initialized yet')
|
|
134
|
+
assert(walletAccountInstance, 'walletAccount is required')
|
|
135
|
+
assert(newMustAvoidUtxoIds, 'mustAvoidUtxoIds is required')
|
|
136
|
+
|
|
137
|
+
if (!prune && !newMustAvoidUtxoIds.length) {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
const walletAccount = walletAccountInstance.toString()
|
|
141
|
+
|
|
142
|
+
const accountState = await aci.getAccountState({
|
|
143
|
+
assetName: asset.name,
|
|
144
|
+
walletAccount: walletAccount,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
const storedMustAvoidUtxosIds = accountState.mustAvoidUtxoIds || []
|
|
148
|
+
|
|
149
|
+
const storedUtxos = getUtxos({ accountState, asset })
|
|
150
|
+
|
|
151
|
+
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
152
|
+
|
|
153
|
+
const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
|
|
154
|
+
|
|
155
|
+
const allMustAvoidUtxoIds = [
|
|
156
|
+
...new Set([...storedMustAvoidUtxosIds, ...newMustAvoidUtxoIds].sort()),
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
const knownUtxoIds = [...allStoredUtxos].map((utxo) =>
|
|
160
|
+
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
const mustAvoidUtxoIds = prune
|
|
164
|
+
? allMustAvoidUtxoIds.filter((id) => knownUtxoIds.includes(id))
|
|
165
|
+
: allMustAvoidUtxoIds
|
|
166
|
+
|
|
167
|
+
if (isEqual(mustAvoidUtxoIds, storedMustAvoidUtxosIds)) {
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const ordinalAddress = await getOrdinalAddress({
|
|
172
|
+
asset,
|
|
173
|
+
assetClientInterface: aci,
|
|
174
|
+
walletAccount,
|
|
175
|
+
ordinalChainIndex: ordinalChainIndex,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
179
|
+
allUtxos: allStoredUtxos,
|
|
180
|
+
ordinalsEnabled: true,
|
|
181
|
+
ordinalAddress: ordinalAddress,
|
|
182
|
+
mustAvoidUtxoIds: mustAvoidUtxoIds,
|
|
183
|
+
knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
await aci.updateAccountState({
|
|
187
|
+
walletAccount,
|
|
188
|
+
assetName: asset.name,
|
|
189
|
+
newData: {
|
|
190
|
+
utxos,
|
|
191
|
+
ordinalsUtxos,
|
|
192
|
+
mustAvoidUtxoIds,
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
},
|
|
127
196
|
}
|
|
128
197
|
}
|
|
@@ -72,7 +72,7 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
72
72
|
const brc20History = (
|
|
73
73
|
await Promise.all(
|
|
74
74
|
addresses.map(async (address) => {
|
|
75
|
-
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({
|
|
75
|
+
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ address })
|
|
76
76
|
return (
|
|
77
77
|
await Promise.all(
|
|
78
78
|
tokensHistoryList.map(async (token) => {
|
|
@@ -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.token.id
|
|
15
15
|
save({ deployInscriptionId, brc20Tick })
|
|
16
16
|
return deployInscriptionId
|
|
17
17
|
}
|