/**
 * This code was AUTOGENERATED using the Codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun Codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */
import { __assign, __awaiter, __generator } from "tslib";
import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU8Decoder, getU8Encoder, transformEncoder, } from "@solana/kit";
export var STATE_DISCRIMINATOR = new Uint8Array([
    216, 146, 107, 94, 104, 75, 182, 177,
]);
export function getStateDiscriminatorBytes() {
    return fixEncoderSize(getBytesEncoder(), 8).encode(STATE_DISCRIMINATOR);
}
/** Gets the encoder for {@link StateArgs} account data. */
export function getStateEncoder() {
    return transformEncoder(getStructEncoder([
        ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
        ["sourceDomain", getU32Encoder()],
        ["signer", getAddressEncoder()],
        ["bump", getU8Encoder()],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: STATE_DISCRIMINATOR })); });
}
/** Gets the decoder for {@link State} account data. */
export function getStateDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["sourceDomain", getU32Decoder()],
        ["signer", getAddressDecoder()],
        ["bump", getU8Decoder()],
    ]);
}
/** Gets the codec for {@link State} account data. */
export function getStateCodec() {
    return combineCodec(getStateEncoder(), getStateDecoder());
}
export function decodeState(encodedAccount) {
    return decodeAccount(encodedAccount, getStateDecoder());
}
export function fetchState(rpc, address, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccount;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchMaybeState(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    assertAccountExists(maybeAccount);
                    return [2 /*return*/, maybeAccount];
            }
        });
    });
}
export function fetchMaybeState(rpc, address, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccount;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchEncodedAccount(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    return [2 /*return*/, decodeState(maybeAccount)];
            }
        });
    });
}
export function fetchAllState(rpc, addresses, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccounts;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchAllMaybeState(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    assertAccountsExist(maybeAccounts);
                    return [2 /*return*/, maybeAccounts];
            }
        });
    });
}
export function fetchAllMaybeState(rpc, addresses, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccounts;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchEncodedAccounts(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    return [2 /*return*/, maybeAccounts.map(function (maybeAccount) { return decodeState(maybeAccount); })];
            }
        });
    });
}
export function getStateSize() {
    return 45;
}
//# sourceMappingURL=state.js.map