@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
45 lines • 1.49 kB
JavaScript
/**
* Rental utility functions
* @module utils/rental
*/
import { fetchRentalState } from '../generated/codama/accounts';
import { RentalStatus } from '../generated/codama/types';
import { deriveActiveRental, deriveQueuedRental } from '../pda/srsly';
import { createRpc } from './rpc';
/**
* Check if a contract has an active rental.
*
* @param contract - The contract address
* @param rpcUrl - RPC URL to use for fetching rental state
* @returns true if active rental exists and has Active status
*/
export async function hasActiveRental(contract, rpcUrl) {
const rpc = createRpc(rpcUrl);
try {
const activeRentalPda = await deriveActiveRental(contract);
const rentalState = await fetchRentalState(rpc, activeRentalPda);
return rentalState.data.status === RentalStatus.Active;
}
catch {
return false;
}
}
/**
* Check if a contract has a queued rental reservation.
*
* @param contract - The contract address
* @param rpcUrl - RPC URL to use for fetching rental state
* @returns true if queued rental exists and has Queued status
*/
export async function hasQueuedRental(contract, rpcUrl) {
const rpc = createRpc(rpcUrl);
try {
const queuedRentalPda = await deriveQueuedRental(contract);
const rentalState = await fetchRentalState(rpc, queuedRentalPda);
return rentalState.data.status === RentalStatus.Queued;
}
catch {
return false;
}
}
//# sourceMappingURL=rental.js.map