mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 14:54:21 +08:00
refactor: minor code improvements
This commit is contained in:
@@ -34,6 +34,14 @@ export function isSameUTXO(utxo1: UTXOBasic, utxo2: UTXOBasic): boolean {
|
||||
return utxo1.txId === utxo2.txId && utxo1.index === utxo2.index
|
||||
}
|
||||
|
||||
export type UTXOFilter = <U extends UTXOBasic>(utxo: U) => boolean
|
||||
export function excludeUTXOs(excludingUTXOs: UTXOBasic[]): UTXOFilter {
|
||||
return filteringUTXO =>
|
||||
!excludingUTXOs.some(excludingUTXO =>
|
||||
isSameUTXO(excludingUTXO, filteringUTXO),
|
||||
)
|
||||
}
|
||||
|
||||
export function addressToScriptPubKey(
|
||||
network: BitcoinNetwork,
|
||||
address: string,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createRevealTx } from "../bitcoinUtils/apiHelpers/createRevealTx"
|
||||
import {
|
||||
UTXOSpendable,
|
||||
bitcoinToSatoshi,
|
||||
isSameUTXO,
|
||||
excludeUTXOs,
|
||||
sumUTXO,
|
||||
} from "../bitcoinUtils/bitcoinHelpers"
|
||||
import {
|
||||
@@ -624,8 +624,7 @@ export function reselectSpendableUTXOsFactory(
|
||||
return async (satsToSend, pinnedUTXOs, lastTimeSelectedUTXOs) => {
|
||||
satsToSend = satsToSend - sumUTXO(pinnedUTXOs)
|
||||
lastTimeSelectedUTXOs = lastTimeSelectedUTXOs.filter(
|
||||
iterUTXO =>
|
||||
!pinnedUTXOs.find(pinnedUTXO => isSameUTXO(iterUTXO, pinnedUTXO)),
|
||||
excludeUTXOs(pinnedUTXOs),
|
||||
)
|
||||
const selected = await reselectSpendableUTXOs_public(
|
||||
satsToSend,
|
||||
|
||||
@@ -31,18 +31,18 @@ export interface SDKGlobalContext {
|
||||
ignoreValidateResult?: boolean
|
||||
}
|
||||
brc20: {
|
||||
ignoreValidateResult?: boolean
|
||||
routesConfigCache?: SDKGlobalContextCache<
|
||||
KnownChainId.BRC20Chain,
|
||||
Promise<BRC20SupportedRoute[]>
|
||||
>
|
||||
ignoreValidateResult?: boolean
|
||||
}
|
||||
runes: {
|
||||
ignoreValidateResult?: boolean
|
||||
routesConfigCache?: SDKGlobalContextCache<
|
||||
KnownChainId.RunesChain,
|
||||
Promise<RunesSupportedRoute[]>
|
||||
>
|
||||
ignoreValidateResult?: boolean
|
||||
}
|
||||
evm: {
|
||||
enableMulticall?: boolean
|
||||
|
||||
Reference in New Issue
Block a user