var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { toCandyGuard } from '../models';
import { assertAccountExists, } from '../../../types';
// -----------------
// Operation
// -----------------
const Key = 'FindCandyGuardByAddressOperation';
/**
 * Find an existing Candy Guard by its address.
 *
 * ```ts
 * const candyGuard = await metaplex
 *   .candyMachines()
 *   .findCandyGuardbyAddress({ address };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const findCandyGuardByAddressOperation = _findCandyGuardByAddressOperation;
// eslint-disable-next-line @typescript-eslint/naming-convention
function _findCandyGuardByAddressOperation(input) {
    return { key: Key, input };
}
_findCandyGuardByAddressOperation.key = Key;
/**
 * @group Operations
 * @category Handlers
 */
export const findCandyGuardByAddressOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { address } = operation.input;
        const account = yield metaplex
            .rpc()
            .getAccount(address, scope.commitment);
        assertAccountExists(account);
        return toCandyGuard(account, metaplex);
    }),
};
//# sourceMappingURL=findCandyGuardByAddress.js.map