verificar-existencia.ts•2.33 kB
/**
* Tool 3: Verify Transaction Existence
* Checks if a transaction exists with specific assets (for fully private transactions)
*/
import { checkTxExists } from '@mistcash/sdk';
import { CHAMBER_ABI } from '@mistcash/config';
import { VerificarExistenciaTransaccionSchema } from '../utils/validation.js';
import { createProvider, getChamberContract, retryWithBackoff, getContractAddress } from '../utils/provider.js';
export async function verificarExistenciaTransaccion(params: unknown) {
// Validate parameters
const validated = VerificarExistenciaTransaccionSchema.parse(params);
try {
// Create provider
const provider = createProvider(
validated.provider_rpc_url ? { nodeUrl: validated.provider_rpc_url } : undefined
);
// Get contract address (supports custom Madara address)
const network = (process.env.STARKNET_NETWORK || 'mainnet') as 'mainnet' | 'sepolia';
const contractAddress = getContractAddress(network);
// Get contract instance
const contract = await getChamberContract(provider, contractAddress, CHAMBER_ABI);
// Check transaction existence with retry logic and timeout
const checkPromise = retryWithBackoff(
() => checkTxExists(
contract,
validated.claiming_key,
validated.recipient,
validated.token_address,
validated.amount
)
);
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Request timeout after 30s')), 30000)
);
const exists = await Promise.race([checkPromise, timeoutPromise]) as boolean;
return {
success: true,
exists,
transaction_details: {
claiming_key: validated.claiming_key,
recipient: validated.recipient,
token_address: validated.token_address,
amount: validated.amount
},
note: 'This method is for fully private transactions where assets are not publicly visible'
};
} catch (error) {
throw new Error(`Failed to verify transaction existence: ${(error as Error).message}`);
}
}