The system provides functions for monitoring transaction status and updating UTxO maps.
// src/utils/wallet-stuff.ts
// Updates a virtual wallet UTxO map with known transaction IDs
export const updateVirtualWalletUtxoMapWithKnownTxIds = (
knownTxIds: string[],
virtualWalletUtxoMap: VirtualWalletUtxoMap
): VirtualWalletUtxoMap => {
const utxoRefToTxId: { [utxoRef: string]: string } = {};
Object.entries(virtualWalletUtxoMap.utxoRefToTxId).forEach(
([utxoRef, txId]) => {
if (!knownTxIds.includes(txId)) {
utxoRefToTxId[utxoRef] = txId;
}
}
);
const txIdToUtxos: { [txId: string]: UTxO[] } = {};
Object.entries(virtualWalletUtxoMap.txIdToUtxos).forEach(([txId, utxos]) => {
if (!knownTxIds.includes(txId)) {
txIdToUtxos[txId] = utxos;
}
});
return {
utxoRefToTxId,
txIdToUtxos,
};
};
// src/utils/wallet-stuff.ts
// Gets the latest UTxOs from known UTxOs and virtual wallet UTxO map
const getLatestUtxos = (
knownUtxos: UTxO[],
virtualWalletUtxoMap: VirtualWalletUtxoMap
): UTxO[] => {
const utxos = getLatestUtxosWorker(knownUtxos, virtualWalletUtxoMap);
const seen = new Set<string>();
return utxos.filter((utxo) => {
const utxoRef = `${utxo.txHash}#${utxo.outputIndex}`;
if (seen.has(utxoRef)) {
return false;
} else {
seen.add(utxoRef);
return true;
}
});
};