-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter out runes utxos, closes #5207
- Loading branch information
1 parent
b4dcf87
commit 1e02992
Showing
11 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,35 @@ | ||
import { mockInscriptionsList } from '@tests/mocks/mock-inscriptions'; | ||
import { mockUtxos } from '@tests/mocks/mock-utxos'; | ||
import { mockRunesOutputsByAddressList } from '@tests/mocks/mock-runes'; | ||
import { mockUtxos, mockUtxosListWithRunes } from '@tests/mocks/mock-utxos'; | ||
|
||
import { filterUtxosWithInscriptions } from './utxos-by-address.hooks'; | ||
import { filterUtxosWithInscriptions, filterUtxosWithRunes } from './utxos-by-address.hooks'; | ||
|
||
describe(filterUtxosWithInscriptions, () => { | ||
test('that it filters out utxos with inscriptions so they are not spent', () => { | ||
const filteredUtxos = filterUtxosWithInscriptions(mockInscriptionsList, mockUtxos); | ||
expect(filteredUtxos).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe(filterUtxosWithRunes, () => { | ||
test('that it filters out utxos with runes so they are not spent', () => { | ||
const filteredUtxos = filterUtxosWithRunes( | ||
mockRunesOutputsByAddressList, | ||
mockUtxosListWithRunes | ||
); | ||
|
||
expect(filteredUtxos).toEqual([ | ||
{ | ||
txid: '66ff7d54e345170e3a76819dc90140971fdae054c9b7eea2089ba5a9720f6e44', | ||
vout: 1, | ||
status: { | ||
confirmed: true, | ||
block_height: 2585955, | ||
block_hash: '00000000000000181cae54c3c19d6ed02511a2f6302a666c3d78bcf1777bb029', | ||
block_time: 1712829917, | ||
}, | ||
value: 546, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/app/query/bitcoin/runes/runes-outputs-by-address.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import type { AppUseQueryConfig } from '@app/query/query-config'; | ||
import { useBitcoinClient } from '@app/store/common/api-clients.hooks'; | ||
import { useCurrentNetwork } from '@app/store/networks/networks.selectors'; | ||
|
||
import type { RunesOutputsByAddress } from '../bitcoin-client'; | ||
import { useRunesEnabled } from './runes.hooks'; | ||
|
||
export function useGetRunesOutputsByAddressQuery<T extends unknown = RunesOutputsByAddress[]>( | ||
address: string, | ||
options?: AppUseQueryConfig<RunesOutputsByAddress[], T> | ||
) { | ||
const client = useBitcoinClient(); | ||
const runesEnabled = useRunesEnabled(); | ||
const network = useCurrentNetwork(); | ||
|
||
return useQuery({ | ||
queryKey: ['runes-outputs-by-address', address], | ||
queryFn: () => | ||
client.BestinslotApi.getRunesOutputsByAddress({ | ||
address, | ||
network: network.chain.bitcoin.bitcoinNetwork, | ||
}), | ||
staleTime: 1000 * 60, | ||
enabled: !!address && runesEnabled, | ||
...options, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const mockRunesOutputsByAddressList = [ | ||
{ | ||
pkscript: '00148027825ee06ad337f9716df8137a1b651163c5b0', | ||
wallet_addr: 'tb1qsqncyhhqdtfn07t3dhupx7smv5gk83ds6k0gfa', | ||
output: '3298edc745bdc2168e949382fd42956a7bbe43ab885a49f1212b097ac8243650:1', | ||
rune_ids: ['2585883:3795'], | ||
balances: [100000000], | ||
rune_names: ['BESTINSLOTXYZ'], | ||
spaced_rune_names: ['BESTINSLOT•XYZ'], | ||
}, | ||
]; |
Oops, something went wrong.