@exodus/bitcoin-api 2.21.3 → 2.22.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/CHANGELOG.md +18 -0
- package/package.json +2 -2
- package/src/account-state.js +1 -10
- package/src/tx-log/bitcoin-monitor-scanner.js +1 -6
- package/src/tx-log/index.js +0 -1
- package/src/tx-log/bitcoin-me-monitor.js +0 -78
- package/src/tx-log/magic-eden-bitcoin-monitor.js +0 -86
- package/src/tx-log/me-flagr.js +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.22.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.21.4...@exodus/bitcoin-api@2.22.0) (2024-08-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* move ME BTC monitor to the ME codebase ([#3118](https://github.com/ExodusMovement/assets/issues/3118)) ([2610e96](https://github.com/ExodusMovement/assets/commit/2610e966f5d078e6b9d87a08c4d86ad090400583))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [2.21.4](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.21.3...@exodus/bitcoin-api@2.21.4) (2024-08-05)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* always add inputs to txLog data ([#3071](https://github.com/ExodusMovement/assets/issues/3071)) ([68b5339](https://github.com/ExodusMovement/assets/commit/68b53397b78ed11a94babd821fc8fe2625558ef5))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [2.21.3](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.21.2...@exodus/bitcoin-api@2.21.3) (2024-07-31)
|
|
7
25
|
|
|
8
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"description": "Exodus bitcoin-api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"type": "git",
|
|
67
67
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "a7d2ce9914ff528043b34b75f3823bf9f777622c"
|
|
70
70
|
}
|
package/src/account-state.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { AccountState, UtxoCollection } from '@exodus/models'
|
|
2
2
|
|
|
3
|
-
export function createAccountState({
|
|
4
|
-
asset,
|
|
5
|
-
ordinalsEnabled = false,
|
|
6
|
-
brc20Enabled = false,
|
|
7
|
-
isMagicEdenFungibleBalancesEnabled = false,
|
|
8
|
-
}) {
|
|
3
|
+
export function createAccountState({ asset, ordinalsEnabled = false, brc20Enabled = false }) {
|
|
9
4
|
const empty = UtxoCollection.createEmpty({
|
|
10
5
|
currency: asset.currency,
|
|
11
6
|
})
|
|
@@ -27,10 +22,6 @@ export function createAccountState({
|
|
|
27
22
|
defaults.brc20Balances = {}
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
if (isMagicEdenFungibleBalancesEnabled) {
|
|
31
|
-
defaults.magicEdenApiFungibleBalances = []
|
|
32
|
-
}
|
|
33
|
-
|
|
34
25
|
return class BitcoinAccountState extends AccountState {
|
|
35
26
|
static defaults = defaults
|
|
36
27
|
}
|
|
@@ -463,12 +463,7 @@ export class BitcoinMonitorScanner {
|
|
|
463
463
|
})
|
|
464
464
|
})
|
|
465
465
|
|
|
466
|
-
|
|
467
|
-
if (
|
|
468
|
-
isSent &&
|
|
469
|
-
txItem.confirmations < 1 &&
|
|
470
|
-
['bitcoin', 'bitcoinregtest', 'bitcointestnet'].includes(asset.name)
|
|
471
|
-
) {
|
|
466
|
+
if (isSent && ['bitcoin', 'bitcoinregtest', 'bitcointestnet'].includes(asset.name)) {
|
|
472
467
|
txLogItem.data.inputs = UtxoCollection.fromArray(
|
|
473
468
|
txItem.vin
|
|
474
469
|
.filter((vin) => addrMap[vin.addr])
|
package/src/tx-log/index.js
CHANGED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Monitor as BitcoinMonitor } from './bitcoin-monitor'
|
|
2
|
-
import fetchFlagrEvaluation from './me-flagr'
|
|
3
|
-
|
|
4
|
-
const FLAGR_KEY = 'bitcoin-balance-api'
|
|
5
|
-
|
|
6
|
-
export class MagicEdenBitcoinMonitor extends BitcoinMonitor {
|
|
7
|
-
constructor(args) {
|
|
8
|
-
super(args)
|
|
9
|
-
this.useMagicEdenMonitor = false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async setServer(assetConfig = {}) {
|
|
13
|
-
super.setServer(assetConfig)
|
|
14
|
-
|
|
15
|
-
const walletAccounts = await this.aci.getWalletAccounts({ assetName: this.asset.name })
|
|
16
|
-
const address = await this.aci.getReceiveAddress({
|
|
17
|
-
assetName: this.asset.name,
|
|
18
|
-
walletAccount: walletAccounts[0],
|
|
19
|
-
useCache: true,
|
|
20
|
-
})
|
|
21
|
-
await this.initFlagr(address)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async initFlagr(address) {
|
|
25
|
-
if (this.useMagicEdenMonitor) return
|
|
26
|
-
try {
|
|
27
|
-
const response = await fetchFlagrEvaluation(address, FLAGR_KEY)
|
|
28
|
-
if (response.variantKey === 'on') {
|
|
29
|
-
this.useMagicEdenMonitor = true
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error('Failed to fetch useMagicEdenMonitor config:', error)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async fetchFungibleBalances(walletAccount) {
|
|
37
|
-
if (!this.useMagicEdenMonitor) return
|
|
38
|
-
|
|
39
|
-
const purposes = await this.aci.getSupportedPurposes({
|
|
40
|
-
assetName: this.asset.name,
|
|
41
|
-
walletAccount,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const addresses = await Promise.all(
|
|
45
|
-
purposes.map((purpose) =>
|
|
46
|
-
this.aci.getReceiveAddress({
|
|
47
|
-
assetName: this.asset.name,
|
|
48
|
-
walletAccount,
|
|
49
|
-
useCache: true,
|
|
50
|
-
purpose,
|
|
51
|
-
})
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const response = await fetch('https://api-mainnet.magiceden.io/v1/wallet/balances/fungible', {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
Accept: 'application/json',
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
|
-
},
|
|
61
|
-
body: JSON.stringify(
|
|
62
|
-
addresses.map((address) => ({ address, chain: this.asset.baseAssetName }))
|
|
63
|
-
),
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`Unable to fetch bitcoin fungible balanes: API returned ${response.status}: ${response.statusText || 'Unknown Status Text'}`
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const { balances } = await response.json()
|
|
73
|
-
|
|
74
|
-
return balances
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const createMagicEdenBitcoinMonitor = (args) => new MagicEdenBitcoinMonitor(args)
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Monitor as BitcoinMonitor } from './bitcoin-monitor'
|
|
2
|
-
import fetchFlagrEvaluation from './me-flagr'
|
|
3
|
-
|
|
4
|
-
const FLAGR_KEY = 'bitcoin-balance-api'
|
|
5
|
-
|
|
6
|
-
export class MagicEdenBitcoinMonitor extends BitcoinMonitor {
|
|
7
|
-
constructor(args) {
|
|
8
|
-
super(args)
|
|
9
|
-
this.useMagicEdenMonitor = false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async setServer(assetConfig = {}) {
|
|
13
|
-
super.setServer(assetConfig)
|
|
14
|
-
|
|
15
|
-
const walletAccounts = await this.aci.getWalletAccounts({ assetName: this.asset.name })
|
|
16
|
-
const address = await this.aci.getReceiveAddress({
|
|
17
|
-
assetName: this.asset.name,
|
|
18
|
-
walletAccount: walletAccounts[0],
|
|
19
|
-
useCache: true,
|
|
20
|
-
})
|
|
21
|
-
await this.initFlagr(address)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async initFlagr(address) {
|
|
25
|
-
if (this.useMagicEdenMonitor) return
|
|
26
|
-
try {
|
|
27
|
-
const response = await fetchFlagrEvaluation(address, FLAGR_KEY)
|
|
28
|
-
if (response.variantKey === 'on') {
|
|
29
|
-
this.useMagicEdenMonitor = true
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error('Failed to fetch useMagicEdenMonitor config:', error)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async fetchFungibleBalances(walletAccount) {
|
|
37
|
-
if (!this.useMagicEdenMonitor) return
|
|
38
|
-
|
|
39
|
-
const purposes = await this.aci.getSupportedPurposes({
|
|
40
|
-
assetName: this.asset.name,
|
|
41
|
-
walletAccount,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const addresses = await Promise.all(
|
|
45
|
-
purposes.map((purpose) =>
|
|
46
|
-
this.aci.getReceiveAddress({
|
|
47
|
-
assetName: this.asset.name,
|
|
48
|
-
walletAccount,
|
|
49
|
-
useCache: true,
|
|
50
|
-
purpose,
|
|
51
|
-
})
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const response = await fetch('https://api-mainnet.magiceden.io/v1/wallet/balances/fungible', {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
Accept: 'application/json',
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
|
-
},
|
|
61
|
-
body: JSON.stringify(
|
|
62
|
-
addresses.map((address) => ({ address, chain: this.asset.baseAssetName }))
|
|
63
|
-
),
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`Unable to fetch bitcoin fungible balanes: API returned ${response.status}: ${response.statusText || 'Unknown Status Text'}`
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const { balances } = await response.json()
|
|
73
|
-
|
|
74
|
-
const metadata = new Map()
|
|
75
|
-
balances.forEach((balance) => {
|
|
76
|
-
if (balance.asset?.id && balance.image) {
|
|
77
|
-
metadata.set(balance.asset.id, { imageURL: balance.image })
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
this.emit('token-metadata', { source: 'bitcoin', metadata })
|
|
81
|
-
|
|
82
|
-
return balances
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const createMagicEdenBitcoinMonitor = (args) => new MagicEdenBitcoinMonitor(args)
|
package/src/tx-log/me-flagr.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const FLAGR_URL = 'https://flagr-w.magiceden.io/api/v1/evaluation'
|
|
2
|
-
|
|
3
|
-
const fetchFlagrEvaluation = async (wallet, flagKey) => {
|
|
4
|
-
const response = await fetch(FLAGR_URL, {
|
|
5
|
-
method: 'POST',
|
|
6
|
-
headers: {
|
|
7
|
-
Accept: 'application/json',
|
|
8
|
-
'Content-Type': 'application/json',
|
|
9
|
-
},
|
|
10
|
-
body: JSON.stringify({ entityContext: { wallet }, flagKey }),
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
if (!response.ok) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
`${FLAGR_URL} returned ${response.status}: ${response.statusText || 'Unknown Status Text'}`
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return response.json()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default fetchFlagrEvaluation
|