@exodus/bitcoin-plugin 1.0.16 → 1.2.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 +2 -2
- package/src/create-asset.js +11 -0
- package/src/ordinals/brc-20-client.js +95 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@exodus/keychain": "^3.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "5ca9d0137051b5030ca55dfb90b9fae8045118fe"
|
|
30
30
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -111,7 +111,18 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
111
111
|
return !!result?.items.length
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
const txLogFilter = (tx) => {
|
|
115
|
+
const isDroppedBitcoinTx = tx.dropped
|
|
116
|
+
const isWaitingRbf = tx.data && tx.data.replacedBy && tx.pending
|
|
117
|
+
return !isDroppedBitcoinTx && !isWaitingRbf
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const getTxLogFilter = () => {
|
|
121
|
+
return txLogFilter
|
|
122
|
+
}
|
|
123
|
+
|
|
114
124
|
const api = {
|
|
125
|
+
getTxLogFilter,
|
|
115
126
|
addressHasHistory,
|
|
116
127
|
defaultAddressPath: 'm/0/0',
|
|
117
128
|
broadcastTx: (...args) => insightClient.broadcastTx(...args),
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
2
|
+
import { fetchival } from '@exodus/fetch'
|
|
3
|
+
import ms from 'ms'
|
|
4
|
+
|
|
5
|
+
const HTTP_POST_TIMEOUT = ms('30s')
|
|
6
|
+
const DEFAULT_ORDINALS_API_KEY = undefined // ME's api key is included in proxy call
|
|
7
|
+
const DEFAULT_BRC_20_URL = 'https://api-mainnet-magiceden.exodus.io/'
|
|
8
|
+
|
|
9
|
+
async function improveErrorMessage(err) {
|
|
10
|
+
if (err.response) {
|
|
11
|
+
try {
|
|
12
|
+
const responseText = await err.response.text()
|
|
13
|
+
if (responseText)
|
|
14
|
+
return Promise.reject(new Error(`${err.message}. Error: ${responseText.slice(0, 200)}`)) // trying to get error more info from body)
|
|
15
|
+
} catch (e) {}
|
|
16
|
+
}
|
|
17
|
+
return Promise.reject(new Error(err.message))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const brc20ApiClientFactory = ({
|
|
21
|
+
brc20Url = DEFAULT_BRC_20_URL,
|
|
22
|
+
ordinalsApiKey = DEFAULT_ORDINALS_API_KEY,
|
|
23
|
+
} = {}) => {
|
|
24
|
+
let baseUrl = brc20Url
|
|
25
|
+
|
|
26
|
+
const setUrl = (newBaseUrl) => {
|
|
27
|
+
baseUrl = newBaseUrl || DEFAULT_BRC_20_URL
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const request = (path, queryParams) => {
|
|
31
|
+
const headers = {
|
|
32
|
+
Accept: 'application/json',
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
}
|
|
35
|
+
if (ordinalsApiKey) headers.Authorization = `Bearer ${ordinalsApiKey}`
|
|
36
|
+
|
|
37
|
+
return fetchival(baseUrl + path, { headers, timeout: HTTP_POST_TIMEOUT })
|
|
38
|
+
.get(queryParams)
|
|
39
|
+
.catch(improveErrorMessage)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getOwnerTickBalances = async ({ address }) => {
|
|
43
|
+
assert(address, 'address is required')
|
|
44
|
+
return request(`/v2/ord/btc/brc20/owner_balances/${encodeURIComponent(address)}`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getTickerInfo = async ({ tick }) => {
|
|
48
|
+
assert(tick, 'tick is required')
|
|
49
|
+
return request(`/v2/ord/btc/brc20/tick_infos/${encodeURIComponent(tick)}`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const removeNullUndefined = (obj) =>
|
|
53
|
+
Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined))
|
|
54
|
+
|
|
55
|
+
const paginatedTransactionHistory = async (queryParams) => {
|
|
56
|
+
const resolvedQueryParams = removeNullUndefined(queryParams)
|
|
57
|
+
const events = []
|
|
58
|
+
const limit = queryParams.limit || 40
|
|
59
|
+
let offset = queryParams.offset || 0
|
|
60
|
+
let response
|
|
61
|
+
do {
|
|
62
|
+
response = await request('/v2/ord/btc/brc20/events', {
|
|
63
|
+
...resolvedQueryParams,
|
|
64
|
+
limit,
|
|
65
|
+
offset,
|
|
66
|
+
})
|
|
67
|
+
offset = offset + limit
|
|
68
|
+
events.push(...response.events)
|
|
69
|
+
} while (offset < response.total)
|
|
70
|
+
|
|
71
|
+
return events
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const getTokenTransactionHistory = ({
|
|
75
|
+
tick,
|
|
76
|
+
owner,
|
|
77
|
+
brc20Op,
|
|
78
|
+
showInvalid,
|
|
79
|
+
transactionIds,
|
|
80
|
+
limit,
|
|
81
|
+
offset,
|
|
82
|
+
}) => {
|
|
83
|
+
return paginatedTransactionHistory({
|
|
84
|
+
tick,
|
|
85
|
+
owner,
|
|
86
|
+
brc20Op,
|
|
87
|
+
showInvalid,
|
|
88
|
+
transactionIds,
|
|
89
|
+
limit,
|
|
90
|
+
offset,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { setUrl, getOwnerTickBalances, getTickerInfo, getTokenTransactionHistory }
|
|
95
|
+
}
|