@exodus/bitcoin-plugin 1.2.0 → 1.4.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/jest.config.js +7 -0
- package/package.json +3 -4
- package/src/__tests__/address.test.js +142 -0
- package/src/__tests__/balances.test.js +67 -0
- package/src/__tests__/bitcoin-private-seed-safe-report.json +2754 -0
- package/src/__tests__/bitcoin-signing.test.js +184 -0
- package/src/__tests__/fee-data.test.js +61 -0
- package/src/__tests__/fee-estimator.test.js +174 -0
- package/src/__tests__/fixtures/segwit-all-unsigned-tx.js +87 -0
- package/src/__tests__/fixtures/segwit-legacy-change-unsigned-tx.js +38 -0
- package/src/__tests__/fixtures/segwit-segwit-change-unsigned-tx.js +96 -0
- package/src/__tests__/fixtures/taproot-15000sats-unsigned-tx.js +149 -0
- package/src/__tests__/fixtures/taproot-all-unsigned-tx.js +231 -0
- package/src/__tests__/fixtures/taproot-unsigned-tx.js +85 -0
- package/src/__tests__/get-size.test.js +70 -0
- package/src/__tests__/index.test.js +65 -0
- package/src/__tests__/keys.test.js +97 -0
- package/src/__tests__/monitor.integration.test.js +170 -0
- package/src/__tests__/move-funds.test.js +408 -0
- package/src/__tests__/parse-unsigned-tx.test.js +46 -0
- package/src/__tests__/reports/unit-test-safe-report.json +2790 -0
- package/src/__tests__/send-tx.test.js +145 -0
- package/src/__tests__/sign-tx.test.js +32 -0
- package/src/__tests__/unsigned-btclike-desktop.json +40 -0
- package/src/__tests__/wallet.test.js +78 -0
- package/src/create-asset.js +70 -7
- package/src/ordinals/__tests__/brc-20-client.integration.test.js +86 -0
- package/src/ordinals/__tests__/brc-20-utils.test.js +165 -0
- package/src/ordinals/__tests__/fixtures/inscriptions-send-usigned-tx.js +125 -0
- package/src/ordinals/__tests__/fixtures/nft-send-usigned-tx.js +97 -0
- package/src/ordinals/__tests__/monitor-ordinals-enabled-safe-report-with-inscriptions.json +2908 -0
- package/src/ordinals/__tests__/monitor-ordinals-enabled-safe-report.json +2906 -0
- package/src/ordinals/__tests__/monitor-ordinals-enabled.integration.test.js +16 -0
- package/src/ordinals/__tests__/nfts-api.test.js +221 -0
- package/src/ordinals/__tests__/ordinals-send-tx.test.js +103 -0
- package/src/ordinals/brc-20-balances-and-fee-adapter.js +41 -0
- package/src/ordinals/brc-20-utils.js +79 -0
- package/src/ordinals/create-token-factory.js +30 -0
- package/src/ordinals/get-inscription-addresses.js +42 -0
- package/src/ordinals/nfts.js +65 -0
- package/src/ordinals/ordinals-account-state-utils.js +55 -0
- package/src/ordinals/ordinals-constants.js +4 -0
- package/src/ordinals/reload-brc20-token-balances.js +154 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
2
|
+
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
|
+
import { groupBy, mapValues } from 'lodash'
|
|
4
|
+
import { updateAccountStateUtxos } from './ordinals-account-state-utils'
|
|
5
|
+
const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
6
|
+
const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
|
|
7
|
+
|
|
8
|
+
const isSend = historyItem.brc20Op === 'send'
|
|
9
|
+
const isReceive = historyItem.brc20Op === 'receive'
|
|
10
|
+
|
|
11
|
+
const data = { nftId: historyItem.inscriptionId, operation: historyItem.brc20Op }
|
|
12
|
+
return {
|
|
13
|
+
txId: historyItem.txId,
|
|
14
|
+
date: new Date(historyItem.createdAt),
|
|
15
|
+
confirmations: 1,
|
|
16
|
+
data: isSend
|
|
17
|
+
? {
|
|
18
|
+
...data,
|
|
19
|
+
sent: [
|
|
20
|
+
{
|
|
21
|
+
address: historyItem.owner, // not right probably
|
|
22
|
+
amount: amount,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
: data,
|
|
27
|
+
from: isReceive ? [historyItem.owner] : undefined, // from is wrong!!! Unknown the from!!!
|
|
28
|
+
addresses: isReceive ? [historyItem.address] : undefined,
|
|
29
|
+
dropped: false,
|
|
30
|
+
coinAmount: amount,
|
|
31
|
+
coinName: asset.name,
|
|
32
|
+
feeAmount: baseAsset.currency.defaultUnit(0), // unsure a possible value
|
|
33
|
+
feeCoinName: baseAsset.name,
|
|
34
|
+
currencies: { [baseAsset.name]: baseAsset.currency, [asset.name]: asset.currency },
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const reloadBrc20TokenBalances = async ({
|
|
39
|
+
brc20Client,
|
|
40
|
+
assetClientInterface,
|
|
41
|
+
walletAccount,
|
|
42
|
+
asset,
|
|
43
|
+
ordinalChainIndex,
|
|
44
|
+
}) => {
|
|
45
|
+
assert(brc20Client, 'brc20Client is required')
|
|
46
|
+
assert(assetClientInterface, 'assetClientInterface is required')
|
|
47
|
+
assert(asset, 'asset is required')
|
|
48
|
+
assert(walletAccount, 'walletAccount is required')
|
|
49
|
+
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
50
|
+
const addresses = await getInscriptionAddresses({
|
|
51
|
+
assetClientInterface,
|
|
52
|
+
walletAccount,
|
|
53
|
+
asset,
|
|
54
|
+
ordinalChainIndex,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const assets = await assetClientInterface.getAssetsForNetwork({ baseAssetName: asset.name })
|
|
58
|
+
|
|
59
|
+
const assetByAssetId = Object.values(assets)
|
|
60
|
+
.filter((asset) => asset.assetId)
|
|
61
|
+
.reduce((map, token) => {
|
|
62
|
+
map.set(token.assetId, token)
|
|
63
|
+
return map
|
|
64
|
+
}, new Map())
|
|
65
|
+
|
|
66
|
+
const unknownBrc20Ticks = new Set()
|
|
67
|
+
const knownInscriptionIds = new Set()
|
|
68
|
+
|
|
69
|
+
const brc20History = (
|
|
70
|
+
await Promise.all(
|
|
71
|
+
addresses.map(async (address) => {
|
|
72
|
+
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ owner: address })
|
|
73
|
+
return tokensHistoryList
|
|
74
|
+
.map((token) => {
|
|
75
|
+
knownInscriptionIds.add(token.inscriptionId.toLowerCase())
|
|
76
|
+
const assetName = assetByAssetId.get(token.brc20Tick)?.name
|
|
77
|
+
if (assetName) {
|
|
78
|
+
return { ...token, address, assetName }
|
|
79
|
+
} else {
|
|
80
|
+
unknownBrc20Ticks.add(token.brc20Tick)
|
|
81
|
+
return undefined
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
})
|
|
86
|
+
)
|
|
87
|
+
).flat()
|
|
88
|
+
|
|
89
|
+
const eventsByAssetNameAndAddress = mapValues(
|
|
90
|
+
groupBy(brc20History, (event) => event.assetName),
|
|
91
|
+
(anotherList) => groupBy(anotherList, (event) => event.address)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
const brc20Balances = mapValues(eventsByAssetNameAndAddress, (eventsByAddress) => {
|
|
95
|
+
return mapValues(eventsByAddress, (events) => {
|
|
96
|
+
const { brc20OwnerAvailableBalance, brc20OwnerTransferBalance, brc20Tick } = events[0]
|
|
97
|
+
|
|
98
|
+
const sentList = events
|
|
99
|
+
.filter((event) => event.brc20Op === 'send')
|
|
100
|
+
.map((event) => event.inscriptionId)
|
|
101
|
+
|
|
102
|
+
const transferableList = events
|
|
103
|
+
.filter((event) => event.brc20Op === 'transfer' && !sentList.includes(event.inscriptionId))
|
|
104
|
+
.map((event) => {
|
|
105
|
+
return {
|
|
106
|
+
inscriptionId: event.inscriptionId,
|
|
107
|
+
inscriptionNumber: event.inscriptionNumber,
|
|
108
|
+
brc20Amt: event.brc20Amt,
|
|
109
|
+
txId: event.txId,
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
return {
|
|
113
|
+
brc20Tick,
|
|
114
|
+
brc20OwnerAvailableBalance,
|
|
115
|
+
brc20OwnerTransferBalance,
|
|
116
|
+
brc20OwnerTotalBalance: brc20OwnerAvailableBalance + brc20OwnerTransferBalance,
|
|
117
|
+
transferableList,
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const allLogItems = brc20History
|
|
123
|
+
.filter(({ assetName }) => assetName)
|
|
124
|
+
.map((historyItem) => {
|
|
125
|
+
return toTxLog({ historyItem, baseAsset: asset, asset: assets[historyItem.assetName] })
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const logItemsByAsset = groupBy(allLogItems, 'coinName')
|
|
129
|
+
|
|
130
|
+
await Promise.all(
|
|
131
|
+
Object.entries(logItemsByAsset).map(([assetName, txs]) => {
|
|
132
|
+
return assetClientInterface.updateTxLogAndNotify({
|
|
133
|
+
assetName,
|
|
134
|
+
walletAccount,
|
|
135
|
+
txs,
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
await updateAccountStateUtxos({
|
|
141
|
+
asset,
|
|
142
|
+
walletAccount,
|
|
143
|
+
assetClientInterface,
|
|
144
|
+
knownInscriptionIds: [...knownInscriptionIds],
|
|
145
|
+
ordinalChainIndex,
|
|
146
|
+
moreNewData: {
|
|
147
|
+
brc20Balances,
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
unknownBrc20Ticks: [...unknownBrc20Ticks],
|
|
153
|
+
}
|
|
154
|
+
}
|