@exodus/bitcoin-api 2.5.0 → 2.5.1
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/address-utils.js +0 -5
- package/src/index.js +1 -0
- package/src/ordinals-utils.js +22 -0
- package/src/tx-log/bitcoin-monitor-scanner.js +15 -2
- package/src/tx-send/index.js +9 -9
- package/src/utxos-utils.js +11 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Exodus bitcoin-api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"@scure/btc-signer": "^1.1.0",
|
|
44
44
|
"jest-when": "^3.5.1"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "562c288cde1c1d7c7ab2c7bc6b1804ccca9b37f2"
|
|
47
47
|
}
|
package/src/address-utils.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
|
|
3
|
-
export function isOrdinalAddress(address, ordinalChainIndex) {
|
|
4
|
-
assert(typeof ordinalChainIndex === 'number', `ordinalChainIndex must be a number`)
|
|
5
|
-
return parsePath(address)[0] === ordinalChainIndex
|
|
6
|
-
}
|
|
7
|
-
|
|
8
3
|
export function isReceiveAddress(address): boolean {
|
|
9
4
|
return parsePath(address)[0] === 0
|
|
10
5
|
}
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
2
|
+
|
|
3
|
+
export function getOrdinalAddress({
|
|
4
|
+
asset,
|
|
5
|
+
assetClientInterface,
|
|
6
|
+
walletAccount,
|
|
7
|
+
ordinalChainIndex,
|
|
8
|
+
}) {
|
|
9
|
+
assert(asset, 'asset is required')
|
|
10
|
+
assert(assetClientInterface, 'assetClientInterface is required')
|
|
11
|
+
assert(walletAccount, 'walletAccount is required')
|
|
12
|
+
if (ordinalChainIndex === undefined) {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
return assetClientInterface.getAddress({
|
|
16
|
+
assetName: asset.name,
|
|
17
|
+
walletAccount,
|
|
18
|
+
purpose: 86,
|
|
19
|
+
chainIndex: ordinalChainIndex,
|
|
20
|
+
addressIndex: 0,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -6,6 +6,7 @@ import ms from 'ms'
|
|
|
6
6
|
import assert from 'minimalistic-assert'
|
|
7
7
|
import { isChangeAddress, isReceiveAddress } from '../address-utils'
|
|
8
8
|
import { getOrdinalsUtxos, getUtxos, partitionUtxos } from '../utxos-utils'
|
|
9
|
+
import { getOrdinalAddress } from '../ordinals-utils'
|
|
9
10
|
|
|
10
11
|
// Time to check whether to drop a sent tx
|
|
11
12
|
const SENT_TIME_TO_DROP = ms('2m')
|
|
@@ -519,7 +520,10 @@ export class BitcoinMonitorScanner {
|
|
|
519
520
|
})
|
|
520
521
|
|
|
521
522
|
const utxosData = utxoCol
|
|
522
|
-
? partitionUtxos({
|
|
523
|
+
? partitionUtxos({
|
|
524
|
+
allUtxos: utxoCol,
|
|
525
|
+
ordinalAddress: await this.getOrdinalAddress({ walletAccount }),
|
|
526
|
+
})
|
|
523
527
|
: {}
|
|
524
528
|
|
|
525
529
|
return {
|
|
@@ -578,7 +582,7 @@ export class BitcoinMonitorScanner {
|
|
|
578
582
|
|
|
579
583
|
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
580
584
|
allUtxos: txConfirmedUtxos,
|
|
581
|
-
|
|
585
|
+
ordinalAddress: await this.getOrdinalAddress({ walletAccount }),
|
|
582
586
|
})
|
|
583
587
|
|
|
584
588
|
return {
|
|
@@ -587,4 +591,13 @@ export class BitcoinMonitorScanner {
|
|
|
587
591
|
txsToUpdate: updatedPropertiesTxs,
|
|
588
592
|
}
|
|
589
593
|
}
|
|
594
|
+
|
|
595
|
+
getOrdinalAddress({ walletAccount }) {
|
|
596
|
+
return getOrdinalAddress({
|
|
597
|
+
asset: this.#asset,
|
|
598
|
+
assetClientInterface: this.#assetClientInterface,
|
|
599
|
+
walletAccount,
|
|
600
|
+
ordinalChainIndex: this.#ordinalChainIndex,
|
|
601
|
+
})
|
|
602
|
+
}
|
|
590
603
|
}
|
package/src/tx-send/index.js
CHANGED
|
@@ -201,15 +201,15 @@ export const createAndBroadcastTXFactory = ({
|
|
|
201
201
|
`Expected ordinal utxos ${inscriptionIds.length}. Found: ${transferOrdinalsUtxos?.size || 0}`
|
|
202
202
|
)
|
|
203
203
|
|
|
204
|
-
const unconfirmedOrdinalUtxos = transferOrdinalsUtxos
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
assert(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
)
|
|
204
|
+
// const unconfirmedOrdinalUtxos = transferOrdinalsUtxos
|
|
205
|
+
// .toArray()
|
|
206
|
+
// .filter((ordinalUtxo) => !(ordinalUtxo.confirmations > 0))
|
|
207
|
+
// assert(
|
|
208
|
+
// !unconfirmedOrdinalUtxos.length,
|
|
209
|
+
// `OrdinalUtxo with inscription ids ${unconfirmedOrdinalUtxos
|
|
210
|
+
// .map((utxo) => utxo.inscriptionId)
|
|
211
|
+
// .join(', ')} have not confirmed yet`
|
|
212
|
+
// )
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
const insightClient = asset.baseAsset.insightClient
|
package/src/utxos-utils.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { UtxoCollection } from '@exodus/models'
|
|
3
3
|
import { findLargeUnconfirmedTxs } from './tx-utils'
|
|
4
4
|
import assert from 'minimalistic-assert'
|
|
5
|
-
import { isOrdinalAddress } from './address-utils'
|
|
6
5
|
|
|
7
6
|
const MAX_ORDINAL_VALUE_POSTAGE = 10000
|
|
8
7
|
|
|
@@ -24,29 +23,31 @@ export function getOrdinalsUtxos({ accountState, asset }) {
|
|
|
24
23
|
)
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
function isOrdinalUtxo({ utxo,
|
|
26
|
+
function isOrdinalUtxo({ utxo, ordinalAddress }) {
|
|
28
27
|
if (utxo.inscriptionId) {
|
|
29
28
|
return true
|
|
30
29
|
}
|
|
31
|
-
if (
|
|
30
|
+
if (!ordinalAddress) {
|
|
32
31
|
// exclude utxos splitting
|
|
33
32
|
return false
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (utxo.address.toString() === ordinalAddress.toString()) {
|
|
36
|
+
return true // we assume any utxo to the ordinal address is a ordinal utxos just in case
|
|
37
|
+
}
|
|
38
|
+
|
|
38
39
|
if (utxo.confirmations) {
|
|
39
|
-
return
|
|
40
|
+
return false
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
return utxo.value.toBaseNumber() <= MAX_ORDINAL_VALUE_POSTAGE
|
|
43
|
+
return utxo.value.toBaseNumber() <= MAX_ORDINAL_VALUE_POSTAGE // while unconfirmed, put < 10000- sats in the ordinal utxos box just in case
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export function partitionUtxos({ allUtxos,
|
|
46
|
+
export function partitionUtxos({ allUtxos, ordinalAddress }) {
|
|
46
47
|
assert(allUtxos, 'allUtxos is required')
|
|
47
48
|
return {
|
|
48
|
-
utxos: allUtxos.filter((utxo) => !isOrdinalUtxo({ utxo,
|
|
49
|
-
ordinalsUtxos: allUtxos.filter((utxo) => isOrdinalUtxo({ utxo,
|
|
49
|
+
utxos: allUtxos.filter((utxo) => !isOrdinalUtxo({ utxo, ordinalAddress })),
|
|
50
|
+
ordinalsUtxos: allUtxos.filter((utxo) => isOrdinalUtxo({ utxo, ordinalAddress })),
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|