UNPKG

@wuwei-labs/srsly

Version:
49 lines 1.69 kB
"use strict"; /** * Rental utility functions * @module utils/rental */ Object.defineProperty(exports, "__esModule", { value: true }); exports.hasActiveRental = hasActiveRental; exports.hasQueuedRental = hasQueuedRental; const accounts_1 = require("../generated/codama/accounts"); const types_1 = require("../generated/codama/types"); const srsly_1 = require("../pda/srsly"); const rpc_1 = require("./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 */ async function hasActiveRental(contract, rpcUrl) { const rpc = (0, rpc_1.createRpc)(rpcUrl); try { const activeRentalPda = await (0, srsly_1.deriveActiveRental)(contract); const rentalState = await (0, accounts_1.fetchRentalState)(rpc, activeRentalPda); return rentalState.data.status === types_1.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 */ async function hasQueuedRental(contract, rpcUrl) { const rpc = (0, rpc_1.createRpc)(rpcUrl); try { const queuedRentalPda = await (0, srsly_1.deriveQueuedRental)(contract); const rentalState = await (0, accounts_1.fetchRentalState)(rpc, queuedRentalPda); return rentalState.data.status === types_1.RentalStatus.Queued; } catch { return false; } } //# sourceMappingURL=rental.js.map