import { createSerializerFromSolitaType, deserializeAccount, } from './Serializer';
import { AccountNotFoundError } from '../errors';
export function getAccountParsingFunction(parser) {
    function parse(account) {
        if ('exists' in account && !account.exists) {
            return account;
        }
        const serializer = createSerializerFromSolitaType(parser);
        return deserializeAccount(account, serializer);
    }
    return parse;
}
export function getAccountParsingAndAssertingFunction(parser) {
    const parse = getAccountParsingFunction(parser);
    return (unparsedAccount, solution) => {
        if ('exists' in unparsedAccount) {
            assertAccountExists(unparsedAccount, parser.name, solution);
        }
        return parse(unparsedAccount);
    };
}
export function assertAccountExists(account, name, solution) {
    if (!account.exists) {
        throw new AccountNotFoundError(account.publicKey, name, { solution });
    }
}
export const toAccountInfo = (account) => {
    const { executable, owner, lamports, rentEpoch } = account;
    return { executable, owner, lamports, rentEpoch };
};
//# sourceMappingURL=Account.js.map