-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: filter ordinal UTXOs --------- Co-authored-by: wjrjerome <[email protected]>
- Loading branch information
1 parent
83cb1f6
commit b0eae41
Showing
19 changed files
with
597 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
import { chunkArray } from "@/utils/chunkArray"; | ||
import { UTXO } from "@/utils/wallet/wallet_provider"; | ||
|
||
import { apiWrapper } from "./apiWrapper"; | ||
|
||
interface UtxoInfo { | ||
txid: string; | ||
vout: number; | ||
inscription: boolean; | ||
} | ||
|
||
const TIMEOUT_DURATION = 2000; // 2 seconds | ||
const BATCH_SIZE = 30; | ||
|
||
export const postFilterOrdinals = async ( | ||
utxos: UTXO[], | ||
address: string, | ||
): Promise<UTXO[]> => { | ||
try { | ||
const utxoChunks = chunkArray(utxos, BATCH_SIZE); | ||
const responses = await Promise.all( | ||
utxoChunks.map((chunk) => | ||
apiWrapper( | ||
"POST", | ||
"/v1/ordinals/verify-utxos", | ||
"Error filtering ordinals", | ||
{ | ||
address, | ||
utxos: chunk.map((utxo) => ({ | ||
txid: utxo.txid, | ||
vout: utxo.vout, | ||
})), | ||
}, | ||
TIMEOUT_DURATION, | ||
), | ||
), | ||
); | ||
|
||
const allUtxoInfo = responses.flatMap((response) => response.data.data); | ||
|
||
// turn the data into map with key of the `txid:vout` | ||
const utxoInfoMap = allUtxoInfo.reduce( | ||
(acc: Record<string, boolean>, u: UtxoInfo) => { | ||
acc[getUTXOIdentifier(u)] = u.inscription; | ||
return acc; | ||
}, | ||
{}, | ||
); | ||
|
||
// filter out the ordinals | ||
return utxos.filter((utxo) => !utxoInfoMap[getUTXOIdentifier(utxo)]); | ||
} catch (error) { | ||
// in case if any error we return the original utxos | ||
return utxos; | ||
} | ||
}; | ||
|
||
// helper function to get the identifier of a UTXO | ||
const getUTXOIdentifier = (utxo: { txid: string; vout: number }) => | ||
`${utxo.txid}:${utxo.vout}`; |
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,2 +1,3 @@ | ||
export const OVERFLOW_TVL_WARNING_THRESHOLD = 0.8; | ||
export const OVERFLOW_HEIGHT_WARNING_THRESHOLD = 3; | ||
export const UTXO_KEY = "UTXOs"; |
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
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
Oops, something went wrong.