"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrpcWebImpl = exports.NodePrivilegedServiceGetNextGovernanceVAASequenceDesc = exports.NodePrivilegedServiceSendObservationRequestDesc = exports.NodePrivilegedServiceFindMissingMessagesDesc = exports.NodePrivilegedServiceInjectGovernanceVAADesc = exports.NodePrivilegedServiceDesc = exports.NodePrivilegedServiceClientImpl = exports.GetNextGovernanceVAASequenceResponse = exports.GetNextGovernanceVAASequenceRequest = exports.SendObservationRequestResponse = exports.SendObservationRequestRequest = exports.FindMissingMessagesResponse = exports.FindMissingMessagesRequest = exports.TokenBridgeUpdateRefundAddress = exports.TokenBridgeUpdateMinimalConsistencyLevel = exports.TokenBridgeDestroyUnexecutedSequenceContracts = exports.BridgeUpgradeContract = exports.ContractUpgrade = exports.BridgeRegisterChain = exports.GuardianKey = exports.GuardianSetUpgrade_Guardian = exports.GuardianSetUpgrade = exports.TransferFee = exports.UpdateMessageFee = exports.InjectGovernanceVAAResponse = exports.GovernanceMessage = exports.InjectGovernanceVAARequest = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const grpc_web_1 = require("@improbable-eng/grpc-web");
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const browser_headers_1 = require("browser-headers");
const gossip_1 = require("../../gossip/v1/gossip");
exports.protobufPackage = "node.v1";
const baseInjectGovernanceVAARequest = {
    currentSetIndex: 0,
    timestamp: 0,
};
exports.InjectGovernanceVAARequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.currentSetIndex !== 0) {
            writer.uint32(8).uint32(message.currentSetIndex);
        }
        for (const v of message.messages) {
            exports.GovernanceMessage.encode(v, writer.uint32(18).fork()).ldelim();
        }
        if (message.timestamp !== 0) {
            writer.uint32(24).uint32(message.timestamp);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseInjectGovernanceVAARequest);
        message.messages = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.currentSetIndex = reader.uint32();
                    break;
                case 2:
                    message.messages.push(exports.GovernanceMessage.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.timestamp = reader.uint32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseInjectGovernanceVAARequest);
        message.messages = [];
        if (object.currentSetIndex !== undefined &&
            object.currentSetIndex !== null) {
            message.currentSetIndex = Number(object.currentSetIndex);
        }
        else {
            message.currentSetIndex = 0;
        }
        if (object.messages !== undefined && object.messages !== null) {
            for (const e of object.messages) {
                message.messages.push(exports.GovernanceMessage.fromJSON(e));
            }
        }
        if (object.timestamp !== undefined && object.timestamp !== null) {
            message.timestamp = Number(object.timestamp);
        }
        else {
            message.timestamp = 0;
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.currentSetIndex !== undefined &&
            (obj.currentSetIndex = message.currentSetIndex);
        if (message.messages) {
            obj.messages = message.messages.map((e) => e ? exports.GovernanceMessage.toJSON(e) : undefined);
        }
        else {
            obj.messages = [];
        }
        message.timestamp !== undefined && (obj.timestamp = message.timestamp);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseInjectGovernanceVAARequest);
        message.messages = [];
        if (object.currentSetIndex !== undefined &&
            object.currentSetIndex !== null) {
            message.currentSetIndex = object.currentSetIndex;
        }
        else {
            message.currentSetIndex = 0;
        }
        if (object.messages !== undefined && object.messages !== null) {
            for (const e of object.messages) {
                message.messages.push(exports.GovernanceMessage.fromPartial(e));
            }
        }
        if (object.timestamp !== undefined && object.timestamp !== null) {
            message.timestamp = object.timestamp;
        }
        else {
            message.timestamp = 0;
        }
        return message;
    },
};
const baseGovernanceMessage = {
    sequence: "0",
    nonce: 0,
    targetChainId: 0,
};
exports.GovernanceMessage = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.sequence !== "0") {
            writer.uint32(16).uint64(message.sequence);
        }
        if (message.nonce !== 0) {
            writer.uint32(24).uint32(message.nonce);
        }
        if (message.targetChainId !== 0) {
            writer.uint32(32).uint32(message.targetChainId);
        }
        if (message.updateMessageFee !== undefined) {
            exports.UpdateMessageFee.encode(message.updateMessageFee, writer.uint32(66).fork()).ldelim();
        }
        if (message.transferFee !== undefined) {
            exports.TransferFee.encode(message.transferFee, writer.uint32(74).fork()).ldelim();
        }
        if (message.guardianSet !== undefined) {
            exports.GuardianSetUpgrade.encode(message.guardianSet, writer.uint32(82).fork()).ldelim();
        }
        if (message.contractUpgrade !== undefined) {
            exports.ContractUpgrade.encode(message.contractUpgrade, writer.uint32(90).fork()).ldelim();
        }
        if (message.bridgeRegisterChain !== undefined) {
            exports.BridgeRegisterChain.encode(message.bridgeRegisterChain, writer.uint32(98).fork()).ldelim();
        }
        if (message.bridgeContractUpgrade !== undefined) {
            exports.BridgeUpgradeContract.encode(message.bridgeContractUpgrade, writer.uint32(106).fork()).ldelim();
        }
        if (message.destroyUnexecutedSequenceContracts !== undefined) {
            exports.TokenBridgeDestroyUnexecutedSequenceContracts.encode(message.destroyUnexecutedSequenceContracts, writer.uint32(162).fork()).ldelim();
        }
        if (message.updateMinimalConsistencyLevel !== undefined) {
            exports.TokenBridgeUpdateMinimalConsistencyLevel.encode(message.updateMinimalConsistencyLevel, writer.uint32(170).fork()).ldelim();
        }
        if (message.updateRefundAddress !== undefined) {
            exports.TokenBridgeUpdateRefundAddress.encode(message.updateRefundAddress, writer.uint32(178).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseGovernanceMessage);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 2:
                    message.sequence = longToString(reader.uint64());
                    break;
                case 3:
                    message.nonce = reader.uint32();
                    break;
                case 4:
                    message.targetChainId = reader.uint32();
                    break;
                case 8:
                    message.updateMessageFee = exports.UpdateMessageFee.decode(reader, reader.uint32());
                    break;
                case 9:
                    message.transferFee = exports.TransferFee.decode(reader, reader.uint32());
                    break;
                case 10:
                    message.guardianSet = exports.GuardianSetUpgrade.decode(reader, reader.uint32());
                    break;
                case 11:
                    message.contractUpgrade = exports.ContractUpgrade.decode(reader, reader.uint32());
                    break;
                case 12:
                    message.bridgeRegisterChain = exports.BridgeRegisterChain.decode(reader, reader.uint32());
                    break;
                case 13:
                    message.bridgeContractUpgrade = exports.BridgeUpgradeContract.decode(reader, reader.uint32());
                    break;
                case 20:
                    message.destroyUnexecutedSequenceContracts =
                        exports.TokenBridgeDestroyUnexecutedSequenceContracts.decode(reader, reader.uint32());
                    break;
                case 21:
                    message.updateMinimalConsistencyLevel =
                        exports.TokenBridgeUpdateMinimalConsistencyLevel.decode(reader, reader.uint32());
                    break;
                case 22:
                    message.updateRefundAddress = exports.TokenBridgeUpdateRefundAddress.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGovernanceMessage);
        if (object.sequence !== undefined && object.sequence !== null) {
            message.sequence = String(object.sequence);
        }
        else {
            message.sequence = "0";
        }
        if (object.nonce !== undefined && object.nonce !== null) {
            message.nonce = Number(object.nonce);
        }
        else {
            message.nonce = 0;
        }
        if (object.targetChainId !== undefined && object.targetChainId !== null) {
            message.targetChainId = Number(object.targetChainId);
        }
        else {
            message.targetChainId = 0;
        }
        if (object.updateMessageFee !== undefined &&
            object.updateMessageFee !== null) {
            message.updateMessageFee = exports.UpdateMessageFee.fromJSON(object.updateMessageFee);
        }
        else {
            message.updateMessageFee = undefined;
        }
        if (object.transferFee !== undefined && object.transferFee !== null) {
            message.transferFee = exports.TransferFee.fromJSON(object.transferFee);
        }
        else {
            message.transferFee = undefined;
        }
        if (object.guardianSet !== undefined && object.guardianSet !== null) {
            message.guardianSet = exports.GuardianSetUpgrade.fromJSON(object.guardianSet);
        }
        else {
            message.guardianSet = undefined;
        }
        if (object.contractUpgrade !== undefined &&
            object.contractUpgrade !== null) {
            message.contractUpgrade = exports.ContractUpgrade.fromJSON(object.contractUpgrade);
        }
        else {
            message.contractUpgrade = undefined;
        }
        if (object.bridgeRegisterChain !== undefined &&
            object.bridgeRegisterChain !== null) {
            message.bridgeRegisterChain = exports.BridgeRegisterChain.fromJSON(object.bridgeRegisterChain);
        }
        else {
            message.bridgeRegisterChain = undefined;
        }
        if (object.bridgeContractUpgrade !== undefined &&
            object.bridgeContractUpgrade !== null) {
            message.bridgeContractUpgrade = exports.BridgeUpgradeContract.fromJSON(object.bridgeContractUpgrade);
        }
        else {
            message.bridgeContractUpgrade = undefined;
        }
        if (object.destroyUnexecutedSequenceContracts !== undefined &&
            object.destroyUnexecutedSequenceContracts !== null) {
            message.destroyUnexecutedSequenceContracts =
                exports.TokenBridgeDestroyUnexecutedSequenceContracts.fromJSON(object.destroyUnexecutedSequenceContracts);
        }
        else {
            message.destroyUnexecutedSequenceContracts = undefined;
        }
        if (object.updateMinimalConsistencyLevel !== undefined &&
            object.updateMinimalConsistencyLevel !== null) {
            message.updateMinimalConsistencyLevel =
                exports.TokenBridgeUpdateMinimalConsistencyLevel.fromJSON(object.updateMinimalConsistencyLevel);
        }
        else {
            message.updateMinimalConsistencyLevel = undefined;
        }
        if (object.updateRefundAddress !== undefined &&
            object.updateRefundAddress !== null) {
            message.updateRefundAddress = exports.TokenBridgeUpdateRefundAddress.fromJSON(object.updateRefundAddress);
        }
        else {
            message.updateRefundAddress = undefined;
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.sequence !== undefined && (obj.sequence = message.sequence);
        message.nonce !== undefined && (obj.nonce = message.nonce);
        message.targetChainId !== undefined &&
            (obj.targetChainId = message.targetChainId);
        message.updateMessageFee !== undefined &&
            (obj.updateMessageFee = message.updateMessageFee
                ? exports.UpdateMessageFee.toJSON(message.updateMessageFee)
                : undefined);
        message.transferFee !== undefined &&
            (obj.transferFee = message.transferFee
                ? exports.TransferFee.toJSON(message.transferFee)
                : undefined);
        message.guardianSet !== undefined &&
            (obj.guardianSet = message.guardianSet
                ? exports.GuardianSetUpgrade.toJSON(message.guardianSet)
                : undefined);
        message.contractUpgrade !== undefined &&
            (obj.contractUpgrade = message.contractUpgrade
                ? exports.ContractUpgrade.toJSON(message.contractUpgrade)
                : undefined);
        message.bridgeRegisterChain !== undefined &&
            (obj.bridgeRegisterChain = message.bridgeRegisterChain
                ? exports.BridgeRegisterChain.toJSON(message.bridgeRegisterChain)
                : undefined);
        message.bridgeContractUpgrade !== undefined &&
            (obj.bridgeContractUpgrade = message.bridgeContractUpgrade
                ? exports.BridgeUpgradeContract.toJSON(message.bridgeContractUpgrade)
                : undefined);
        message.destroyUnexecutedSequenceContracts !== undefined &&
            (obj.destroyUnexecutedSequenceContracts =
                message.destroyUnexecutedSequenceContracts
                    ? exports.TokenBridgeDestroyUnexecutedSequenceContracts.toJSON(message.destroyUnexecutedSequenceContracts)
                    : undefined);
        message.updateMinimalConsistencyLevel !== undefined &&
            (obj.updateMinimalConsistencyLevel = message.updateMinimalConsistencyLevel
                ? exports.TokenBridgeUpdateMinimalConsistencyLevel.toJSON(message.updateMinimalConsistencyLevel)
                : undefined);
        message.updateRefundAddress !== undefined &&
            (obj.updateRefundAddress = message.updateRefundAddress
                ? exports.TokenBridgeUpdateRefundAddress.toJSON(message.updateRefundAddress)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseGovernanceMessage);
        if (object.sequence !== undefined && object.sequence !== null) {
            message.sequence = object.sequence;
        }
        else {
            message.sequence = "0";
        }
        if (object.nonce !== undefined && object.nonce !== null) {
            message.nonce = object.nonce;
        }
        else {
            message.nonce = 0;
        }
        if (object.targetChainId !== undefined && object.targetChainId !== null) {
            message.targetChainId = object.targetChainId;
        }
        else {
            message.targetChainId = 0;
        }
        if (object.updateMessageFee !== undefined &&
            object.updateMessageFee !== null) {
            message.updateMessageFee = exports.UpdateMessageFee.fromPartial(object.updateMessageFee);
        }
        else {
            message.updateMessageFee = undefined;
        }
        if (object.transferFee !== undefined && object.transferFee !== null) {
            message.transferFee = exports.TransferFee.fromPartial(object.transferFee);
        }
        else {
            message.transferFee = undefined;
        }
        if (object.guardianSet !== undefined && object.guardianSet !== null) {
            message.guardianSet = exports.GuardianSetUpgrade.fromPartial(object.guardianSet);
        }
        else {
            message.guardianSet = undefined;
        }
        if (object.contractUpgrade !== undefined &&
            object.contractUpgrade !== null) {
            message.contractUpgrade = exports.ContractUpgrade.fromPartial(object.contractUpgrade);
        }
        else {
            message.contractUpgrade = undefined;
        }
        if (object.bridgeRegisterChain !== undefined &&
            object.bridgeRegisterChain !== null) {
            message.bridgeRegisterChain = exports.BridgeRegisterChain.fromPartial(object.bridgeRegisterChain);
        }
        else {
            message.bridgeRegisterChain = undefined;
        }
        if (object.bridgeContractUpgrade !== undefined &&
            object.bridgeContractUpgrade !== null) {
            message.bridgeContractUpgrade = exports.BridgeUpgradeContract.fromPartial(object.bridgeContractUpgrade);
        }
        else {
            message.bridgeContractUpgrade = undefined;
        }
        if (object.destroyUnexecutedSequenceContracts !== undefined &&
            object.destroyUnexecutedSequenceContracts !== null) {
            message.destroyUnexecutedSequenceContracts =
                exports.TokenBridgeDestroyUnexecutedSequenceContracts.fromPartial(object.destroyUnexecutedSequenceContracts);
        }
        else {
            message.destroyUnexecutedSequenceContracts = undefined;
        }
        if (object.updateMinimalConsistencyLevel !== undefined &&
            object.updateMinimalConsistencyLevel !== null) {
            message.updateMinimalConsistencyLevel =
                exports.TokenBridgeUpdateMinimalConsistencyLevel.fromPartial(object.updateMinimalConsistencyLevel);
        }
        else {
            message.updateMinimalConsistencyLevel = undefined;
        }
        if (object.updateRefundAddress !== undefined &&
            object.updateRefundAddress !== null) {
            message.updateRefundAddress = exports.TokenBridgeUpdateRefundAddress.fromPartial(object.updateRefundAddress);
        }
        else {
            message.updateRefundAddress = undefined;
        }
        return message;
    },
};
const baseInjectGovernanceVAAResponse = {};
exports.InjectGovernanceVAAResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.digests) {
            writer.uint32(10).bytes(v);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseInjectGovernanceVAAResponse);
        message.digests = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.digests.push(reader.bytes());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseInjectGovernanceVAAResponse);
        message.digests = [];
        if (object.digests !== undefined && object.digests !== null) {
            for (const e of object.digests) {
                message.digests.push(bytesFromBase64(e));
            }
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.digests) {
            obj.digests = message.digests.map((e) => base64FromBytes(e !== undefined ? e : new Uint8Array()));
        }
        else {
            obj.digests = [];
        }
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseInjectGovernanceVAAResponse);
        message.digests = [];
        if (object.digests !== undefined && object.digests !== null) {
            for (const e of object.digests) {
                message.digests.push(e);
            }
        }
        return message;
    },
};
const baseUpdateMessageFee = { newMessageFee: "" };
exports.UpdateMessageFee = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.newMessageFee !== "") {
            writer.uint32(10).string(message.newMessageFee);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseUpdateMessageFee);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.newMessageFee = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUpdateMessageFee);
        if (object.newMessageFee !== undefined && object.newMessageFee !== null) {
            message.newMessageFee = String(object.newMessageFee);
        }
        else {
            message.newMessageFee = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.newMessageFee !== undefined &&
            (obj.newMessageFee = message.newMessageFee);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseUpdateMessageFee);
        if (object.newMessageFee !== undefined && object.newMessageFee !== null) {
            message.newMessageFee = object.newMessageFee;
        }
        else {
            message.newMessageFee = "";
        }
        return message;
    },
};
const baseTransferFee = { amount: "", recipient: "" };
exports.TransferFee = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.amount !== "") {
            writer.uint32(10).string(message.amount);
        }
        if (message.recipient !== "") {
            writer.uint32(18).string(message.recipient);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseTransferFee);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.amount = reader.string();
                    break;
                case 2:
                    message.recipient = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTransferFee);
        if (object.amount !== undefined && object.amount !== null) {
            message.amount = String(object.amount);
        }
        else {
            message.amount = "";
        }
        if (object.recipient !== undefined && object.recipient !== null) {
            message.recipient = String(object.recipient);
        }
        else {
            message.recipient = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.amount !== undefined && (obj.amount = message.amount);
        message.recipient !== undefined && (obj.recipient = message.recipient);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseTransferFee);
        if (object.amount !== undefined && object.amount !== null) {
            message.amount = object.amount;
        }
        else {
            message.amount = "";
        }
        if (object.recipient !== undefined && object.recipient !== null) {
            message.recipient = object.recipient;
        }
        else {
            message.recipient = "";
        }
        return message;
    },
};
const baseGuardianSetUpgrade = {};
exports.GuardianSetUpgrade = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.guardians) {
            exports.GuardianSetUpgrade_Guardian.encode(v, writer.uint32(26).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseGuardianSetUpgrade);
        message.guardians = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 3:
                    message.guardians.push(exports.GuardianSetUpgrade_Guardian.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGuardianSetUpgrade);
        message.guardians = [];
        if (object.guardians !== undefined && object.guardians !== null) {
            for (const e of object.guardians) {
                message.guardians.push(exports.GuardianSetUpgrade_Guardian.fromJSON(e));
            }
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.guardians) {
            obj.guardians = message.guardians.map((e) => e ? exports.GuardianSetUpgrade_Guardian.toJSON(e) : undefined);
        }
        else {
            obj.guardians = [];
        }
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseGuardianSetUpgrade);
        message.guardians = [];
        if (object.guardians !== undefined && object.guardians !== null) {
            for (const e of object.guardians) {
                message.guardians.push(exports.GuardianSetUpgrade_Guardian.fromPartial(e));
            }
        }
        return message;
    },
};
const baseGuardianSetUpgrade_Guardian = { pubkey: "", name: "" };
exports.GuardianSetUpgrade_Guardian = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.pubkey !== "") {
            writer.uint32(10).string(message.pubkey);
        }
        if (message.name !== "") {
            writer.uint32(18).string(message.name);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseGuardianSetUpgrade_Guardian);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.pubkey = reader.string();
                    break;
                case 2:
                    message.name = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGuardianSetUpgrade_Guardian);
        if (object.pubkey !== undefined && object.pubkey !== null) {
            message.pubkey = String(object.pubkey);
        }
        else {
            message.pubkey = "";
        }
        if (object.name !== undefined && object.name !== null) {
            message.name = String(object.name);
        }
        else {
            message.name = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.pubkey !== undefined && (obj.pubkey = message.pubkey);
        message.name !== undefined && (obj.name = message.name);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseGuardianSetUpgrade_Guardian);
        if (object.pubkey !== undefined && object.pubkey !== null) {
            message.pubkey = object.pubkey;
        }
        else {
            message.pubkey = "";
        }
        if (object.name !== undefined && object.name !== null) {
            message.name = object.name;
        }
        else {
            message.name = "";
        }
        return message;
    },
};
const baseGuardianKey = { unsafeDeterministicKey: false };
exports.GuardianKey = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.data.length !== 0) {
            writer.uint32(10).bytes(message.data);
        }
        if (message.unsafeDeterministicKey === true) {
            writer.uint32(16).bool(message.unsafeDeterministicKey);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseGuardianKey);
        message.data = new Uint8Array();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.data = reader.bytes();
                    break;
                case 2:
                    message.unsafeDeterministicKey = reader.bool();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGuardianKey);
        message.data = new Uint8Array();
        if (object.data !== undefined && object.data !== null) {
            message.data = bytesFromBase64(object.data);
        }
        if (object.unsafeDeterministicKey !== undefined &&
            object.unsafeDeterministicKey !== null) {
            message.unsafeDeterministicKey = Boolean(object.unsafeDeterministicKey);
        }
        else {
            message.unsafeDeterministicKey = false;
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.data !== undefined &&
            (obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array()));
        message.unsafeDeterministicKey !== undefined &&
            (obj.unsafeDeterministicKey = message.unsafeDeterministicKey);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseGuardianKey);
        if (object.data !== undefined && object.data !== null) {
            message.data = object.data;
        }
        else {
            message.data = new Uint8Array();
        }
        if (object.unsafeDeterministicKey !== undefined &&
            object.unsafeDeterministicKey !== null) {
            message.unsafeDeterministicKey = object.unsafeDeterministicKey;
        }
        else {
            message.unsafeDeterministicKey = false;
        }
        return message;
    },
};
const baseBridgeRegisterChain = {
    module: "",
    chainId: 0,
    emitterAddress: "",
};
exports.BridgeRegisterChain = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.module !== "") {
            writer.uint32(10).string(message.module);
        }
        if (message.chainId !== 0) {
            writer.uint32(16).uint32(message.chainId);
        }
        if (message.emitterAddress !== "") {
            writer.uint32(26).string(message.emitterAddress);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseBridgeRegisterChain);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.module = reader.string();
                    break;
                case 2:
                    message.chainId = reader.uint32();
                    break;
                case 3:
                    message.emitterAddress = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseBridgeRegisterChain);
        if (object.module !== undefined && object.module !== null) {
            message.module = String(object.module);
        }
        else {
            message.module = "";
        }
        if (object.chainId !== undefined && object.chainId !== null) {
            message.chainId = Number(object.chainId);
        }
        else {
            message.chainId = 0;
        }
        if (object.emitterAddress !== undefined && object.emitterAddress !== null) {
            message.emitterAddress = String(object.emitterAddress);
        }
        else {
            message.emitterAddress = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.module !== undefined && (obj.module = message.module);
        message.chainId !== undefined && (obj.chainId = message.chainId);
        message.emitterAddress !== undefined &&
            (obj.emitterAddress = message.emitterAddress);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseBridgeRegisterChain);
        if (object.module !== undefined && object.module !== null) {
            message.module = object.module;
        }
        else {
            message.module = "";
        }
        if (object.chainId !== undefined && object.chainId !== null) {
            message.chainId = object.chainId;
        }
        else {
            message.chainId = 0;
        }
        if (object.emitterAddress !== undefined && object.emitterAddress !== null) {
            message.emitterAddress = object.emitterAddress;
        }
        else {
            message.emitterAddress = "";
        }
        return message;
    },
};
const baseContractUpgrade = { payload: "" };
exports.ContractUpgrade = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.payload !== "") {
            writer.uint32(10).string(message.payload);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseContractUpgrade);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.payload = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseContractUpgrade);
        if (object.payload !== undefined && object.payload !== null) {
            message.payload = String(object.payload);
        }
        else {
            message.payload = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.payload !== undefined && (obj.payload = message.payload);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseContractUpgrade);
        if (object.payload !== undefined && object.payload !== null) {
            message.payload = object.payload;
        }
        else {
            message.payload = "";
        }
        return message;
    },
};
const baseBridgeUpgradeContract = { module: "", payload: "" };
exports.BridgeUpgradeContract = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.module !== "") {
            writer.uint32(10).string(message.module);
        }
        if (message.payload !== "") {
            writer.uint32(18).string(message.payload);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseBridgeUpgradeContract);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.module = reader.string();
                    break;
                case 2:
                    message.payload = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseBridgeUpgradeContract);
        if (object.module !== undefined && object.module !== null) {
            message.module = String(object.module);
        }
        else {
            message.module = "";
        }
        if (object.payload !== undefined && object.payload !== null) {
            message.payload = String(object.payload);
        }
        else {
            message.payload = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.module !== undefined && (obj.module = message.module);
        message.payload !== undefined && (obj.payload = message.payload);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseBridgeUpgradeContract);
        if (object.module !== undefined && object.module !== null) {
            message.module = object.module;
        }
        else {
            message.module = "";
        }
        if (object.payload !== undefined && object.payload !== null) {
            message.payload = object.payload;
        }
        else {
            message.payload = "";
        }
        return message;
    },
};
const baseTokenBridgeDestroyUnexecutedSequenceContracts = {
    emitterChain: 0,
    sequences: "0",
};
exports.TokenBridgeDestroyUnexecutedSequenceContracts = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.emitterChain !== 0) {
            writer.uint32(8).uint32(message.emitterChain);
        }
        writer.uint32(18).fork();
        for (const v of message.sequences) {
            writer.uint64(v);
        }
        writer.ldelim();
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseTokenBridgeDestroyUnexecutedSequenceContracts);
        message.sequences = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.emitterChain = reader.uint32();
                    break;
                case 2:
                    if ((tag & 7) === 2) {
                        const end2 = reader.uint32() + reader.pos;
                        while (reader.pos < end2) {
                            message.sequences.push(longToString(reader.uint64()));
                        }
                    }
                    else {
                        message.sequences.push(longToString(reader.uint64()));
                    }
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTokenBridgeDestroyUnexecutedSequenceContracts);
        message.sequences = [];
        if (object.emitterChain !== undefined && object.emitterChain !== null) {
            message.emitterChain = Number(object.emitterChain);
        }
        else {
            message.emitterChain = 0;
        }
        if (object.sequences !== undefined && object.sequences !== null) {
            for (const e of object.sequences) {
                message.sequences.push(String(e));
            }
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.emitterChain !== undefined &&
            (obj.emitterChain = message.emitterChain);
        if (message.sequences) {
            obj.sequences = message.sequences.map((e) => e);
        }
        else {
            obj.sequences = [];
        }
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseTokenBridgeDestroyUnexecutedSequenceContracts);
        message.sequences = [];
        if (object.emitterChain !== undefined && object.emitterChain !== null) {
            message.emitterChain = object.emitterChain;
        }
        else {
            message.emitterChain = 0;
        }
        if (object.sequences !== undefined && object.sequences !== null) {
            for (const e of object.sequences) {
                message.sequences.push(e);
            }
        }
        return message;
    },
};
const baseTokenBridgeUpdateMinimalConsistencyLevel = {
    newConsistencyLevel: 0,
};
exports.TokenBridgeUpdateMinimalConsistencyLevel = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.newConsistencyLevel !== 0) {
            writer.uint32(8).uint32(message.newConsistencyLevel);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseTokenBridgeUpdateMinimalConsistencyLevel);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.newConsistencyLevel = reader.uint32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTokenBridgeUpdateMinimalConsistencyLevel);
        if (object.newConsistencyLevel !== undefined &&
            object.newConsistencyLevel !== null) {
            message.newConsistencyLevel = Number(object.newConsistencyLevel);
        }
        else {
            message.newConsistencyLevel = 0;
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.newConsistencyLevel !== undefined &&
            (obj.newConsistencyLevel = message.newConsistencyLevel);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseTokenBridgeUpdateMinimalConsistencyLevel);
        if (object.newConsistencyLevel !== undefined &&
            object.newConsistencyLevel !== null) {
            message.newConsistencyLevel = object.newConsistencyLevel;
        }
        else {
            message.newConsistencyLevel = 0;
        }
        return message;
    },
};
const baseTokenBridgeUpdateRefundAddress = { newRefundAddress: "" };
exports.TokenBridgeUpdateRefundAddress = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.newRefundAddress !== "") {
            writer.uint32(10).string(message.newRefundAddress);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseTokenBridgeUpdateRefundAddress);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.newRefundAddress = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTokenBridgeUpdateRefundAddress);
        if (object.newRefundAddress !== undefined &&
            object.newRefundAddress !== null) {
            message.newRefundAddress = String(object.newRefundAddress);
        }
        else {
            message.newRefundAddress = "";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.newRefundAddress !== undefined &&
            (obj.newRefundAddress = message.newRefundAddress);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseTokenBridgeUpdateRefundAddress);
        if (object.newRefundAddress !== undefined &&
            object.newRefundAddress !== null) {
            message.newRefundAddress = object.newRefundAddress;
        }
        else {
            message.newRefundAddress = "";
        }
        return message;
    },
};
const baseFindMissingMessagesRequest = {
    emitterChain: 0,
    targetChain: 0,
    emitterAddress: "",
    rpcBackfill: false,
    backfillNodes: "",
};
exports.FindMissingMessagesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.emitterChain !== 0) {
            writer.uint32(8).uint32(message.emitterChain);
        }
        if (message.targetChain !== 0) {
            writer.uint32(16).uint32(message.targetChain);
        }
        if (message.emitterAddress !== "") {
            writer.uint32(26).string(message.emitterAddress);
        }
        if (message.rpcBackfill === true) {
            writer.uint32(32).bool(message.rpcBackfill);
        }
        for (const v of message.backfillNodes) {
            writer.uint32(42).string(v);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseFindMissingMessagesRequest);
        message.backfillNodes = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.emitterChain = reader.uint32();
                    break;
                case 2:
                    message.targetChain = reader.uint32();
                    break;
                case 3:
                    message.emitterAddress = reader.string();
                    break;
                case 4:
                    message.rpcBackfill = reader.bool();
                    break;
                case 5:
                    message.backfillNodes.push(reader.string());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseFindMissingMessagesRequest);
        message.backfillNodes = [];
        if (object.emitterChain !== undefined && object.emitterChain !== null) {
            message.emitterChain = Number(object.emitterChain);
        }
        else {
            message.emitterChain = 0;
        }
        if (object.targetChain !== undefined && object.targetChain !== null) {
            message.targetChain = Number(object.targetChain);
        }
        else {
            message.targetChain = 0;
        }
        if (object.emitterAddress !== undefined && object.emitterAddress !== null) {
            message.emitterAddress = String(object.emitterAddress);
        }
        else {
            message.emitterAddress = "";
        }
        if (object.rpcBackfill !== undefined && object.rpcBackfill !== null) {
            message.rpcBackfill = Boolean(object.rpcBackfill);
        }
        else {
            message.rpcBackfill = false;
        }
        if (object.backfillNodes !== undefined && object.backfillNodes !== null) {
            for (const e of object.backfillNodes) {
                message.backfillNodes.push(String(e));
            }
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.emitterChain !== undefined &&
            (obj.emitterChain = message.emitterChain);
        message.targetChain !== undefined &&
            (obj.targetChain = message.targetChain);
        message.emitterAddress !== undefined &&
            (obj.emitterAddress = message.emitterAddress);
        message.rpcBackfill !== undefined &&
            (obj.rpcBackfill = message.rpcBackfill);
        if (message.backfillNodes) {
            obj.backfillNodes = message.backfillNodes.map((e) => e);
        }
        else {
            obj.backfillNodes = [];
        }
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseFindMissingMessagesRequest);
        message.backfillNodes = [];
        if (object.emitterChain !== undefined && object.emitterChain !== null) {
            message.emitterChain = object.emitterChain;
        }
        else {
            message.emitterChain = 0;
        }
        if (object.targetChain !== undefined && object.targetChain !== null) {
            message.targetChain = object.targetChain;
        }
        else {
            message.targetChain = 0;
        }
        if (object.emitterAddress !== undefined && object.emitterAddress !== null) {
            message.emitterAddress = object.emitterAddress;
        }
        else {
            message.emitterAddress = "";
        }
        if (object.rpcBackfill !== undefined && object.rpcBackfill !== null) {
            message.rpcBackfill = object.rpcBackfill;
        }
        else {
            message.rpcBackfill = false;
        }
        if (object.backfillNodes !== undefined && object.backfillNodes !== null) {
            for (const e of object.backfillNodes) {
                message.backfillNodes.push(e);
            }
        }
        return message;
    },
};
const baseFindMissingMessagesResponse = {
    missingMessages: "",
    firstSequence: "0",
    lastSequence: "0",
};
exports.FindMissingMessagesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.missingMessages) {
            writer.uint32(10).string(v);
        }
        if (message.firstSequence !== "0") {
            writer.uint32(16).uint64(message.firstSequence);
        }
        if (message.lastSequence !== "0") {
            writer.uint32(24).uint64(message.lastSequence);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseFindMissingMessagesResponse);
        message.missingMessages = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.missingMessages.push(reader.string());
                    break;
                case 2:
                    message.firstSequence = longToString(reader.uint64());
                    break;
                case 3:
                    message.lastSequence = longToString(reader.uint64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseFindMissingMessagesResponse);
        message.missingMessages = [];
        if (object.missingMessages !== undefined &&
            object.missingMessages !== null) {
            for (const e of object.missingMessages) {
                message.missingMessages.push(String(e));
            }
        }
        if (object.firstSequence !== undefined && object.firstSequence !== null) {
            message.firstSequence = String(object.firstSequence);
        }
        else {
            message.firstSequence = "0";
        }
        if (object.lastSequence !== undefined && object.lastSequence !== null) {
            message.lastSequence = String(object.lastSequence);
        }
        else {
            message.lastSequence = "0";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.missingMessages) {
            obj.missingMessages = message.missingMessages.map((e) => e);
        }
        else {
            obj.missingMessages = [];
        }
        message.firstSequence !== undefined &&
            (obj.firstSequence = message.firstSequence);
        message.lastSequence !== undefined &&
            (obj.lastSequence = message.lastSequence);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseFindMissingMessagesResponse);
        message.missingMessages = [];
        if (object.missingMessages !== undefined &&
            object.missingMessages !== null) {
            for (const e of object.missingMessages) {
                message.missingMessages.push(e);
            }
        }
        if (object.firstSequence !== undefined && object.firstSequence !== null) {
            message.firstSequence = object.firstSequence;
        }
        else {
            message.firstSequence = "0";
        }
        if (object.lastSequence !== undefined && object.lastSequence !== null) {
            message.lastSequence = object.lastSequence;
        }
        else {
            message.lastSequence = "0";
        }
        return message;
    },
};
const baseSendObservationRequestRequest = {};
exports.SendObservationRequestRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.observationRequest !== undefined) {
            gossip_1.ObservationRequest.encode(message.observationRequest, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseSendObservationRequestRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.observationRequest = gossip_1.ObservationRequest.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseSendObservationRequestRequest);
        if (object.observationRequest !== undefined &&
            object.observationRequest !== null) {
            message.observationRequest = gossip_1.ObservationRequest.fromJSON(object.observationRequest);
        }
        else {
            message.observationRequest = undefined;
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.observationRequest !== undefined &&
            (obj.observationRequest = message.observationRequest
                ? gossip_1.ObservationRequest.toJSON(message.observationRequest)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseSendObservationRequestRequest);
        if (object.observationRequest !== undefined &&
            object.observationRequest !== null) {
            message.observationRequest = gossip_1.ObservationRequest.fromPartial(object.observationRequest);
        }
        else {
            message.observationRequest = undefined;
        }
        return message;
    },
};
const baseSendObservationRequestResponse = {};
exports.SendObservationRequestResponse = {
    encode(_, writer = minimal_1.default.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseSendObservationRequestResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(_) {
        const message = Object.assign({}, baseSendObservationRequestResponse);
        return message;
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    fromPartial(_) {
        const message = Object.assign({}, baseSendObservationRequestResponse);
        return message;
    },
};
const baseGetNextGovernanceVAASequenceRequest = {};
exports.GetNextGovernanceVAASequenceRequest = {
    encode(_, writer = minimal_1.default.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseGetNextGovernanceVAASequenceRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(_) {
        const message = Object.assign({}, baseGetNextGovernanceVAASequenceRequest);
        return message;
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    fromPartial(_) {
        const message = Object.assign({}, baseGetNextGovernanceVAASequenceRequest);
        return message;
    },
};
const baseGetNextGovernanceVAASequenceResponse = { sequence: "0" };
exports.GetNextGovernanceVAASequenceResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.sequence !== "0") {
            writer.uint32(8).uint64(message.sequence);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseGetNextGovernanceVAASequenceResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.sequence = longToString(reader.uint64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetNextGovernanceVAASequenceResponse);
        if (object.sequence !== undefined && object.sequence !== null) {
            message.sequence = String(object.sequence);
        }
        else {
            message.sequence = "0";
        }
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.sequence !== undefined && (obj.sequence = message.sequence);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseGetNextGovernanceVAASequenceResponse);
        if (object.sequence !== undefined && object.sequence !== null) {
            message.sequence = object.sequence;
        }
        else {
            message.sequence = "0";
        }
        return message;
    },
};
class NodePrivilegedServiceClientImpl {
    constructor(rpc) {
        this.rpc = rpc;
        this.InjectGovernanceVAA = this.InjectGovernanceVAA.bind(this);
        this.FindMissingMessages = this.FindMissingMessages.bind(this);
        this.SendObservationRequest = this.SendObservationRequest.bind(this);
        this.GetNextGovernanceVAASequence =
            this.GetNextGovernanceVAASequence.bind(this);
    }
    InjectGovernanceVAA(request, metadata) {
        return this.rpc.unary(exports.NodePrivilegedServiceInjectGovernanceVAADesc, exports.InjectGovernanceVAARequest.fromPartial(request), metadata);
    }
    FindMissingMessages(request, metadata) {
        return this.rpc.unary(exports.NodePrivilegedServiceFindMissingMessagesDesc, exports.FindMissingMessagesRequest.fromPartial(request), metadata);
    }
    SendObservationRequest(request, metadata) {
        return this.rpc.unary(exports.NodePrivilegedServiceSendObservationRequestDesc, exports.SendObservationRequestRequest.fromPartial(request), metadata);
    }
    GetNextGovernanceVAASequence(request, metadata) {
        return this.rpc.unary(exports.NodePrivilegedServiceGetNextGovernanceVAASequenceDesc, exports.GetNextGovernanceVAASequenceRequest.fromPartial(request), metadata);
    }
}
exports.NodePrivilegedServiceClientImpl = NodePrivilegedServiceClientImpl;
exports.NodePrivilegedServiceDesc = {
    serviceName: "node.v1.NodePrivilegedService",
};
exports.NodePrivilegedServiceInjectGovernanceVAADesc = {
    methodName: "InjectGovernanceVAA",
    service: exports.NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary() {
            return exports.InjectGovernanceVAARequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary(data) {
            return Object.assign(Object.assign({}, exports.InjectGovernanceVAAResponse.decode(data)), { toObject() {
                    return this;
                } });
        },
    },
};
exports.NodePrivilegedServiceFindMissingMessagesDesc = {
    methodName: "FindMissingMessages",
    service: exports.NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary() {
            return exports.FindMissingMessagesRequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary(data) {
            return Object.assign(Object.assign({}, exports.FindMissingMessagesResponse.decode(data)), { toObject() {
                    return this;
                } });
        },
    },
};
exports.NodePrivilegedServiceSendObservationRequestDesc = {
    methodName: "SendObservationRequest",
    service: exports.NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary() {
            return exports.SendObservationRequestRequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary(data) {
            return Object.assign(Object.assign({}, exports.SendObservationRequestResponse.decode(data)), { toObject() {
                    return this;
                } });
        },
    },
};
exports.NodePrivilegedServiceGetNextGovernanceVAASequenceDesc = {
    methodName: "GetNextGovernanceVAASequence",
    service: exports.NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary() {
            return exports.GetNextGovernanceVAASequenceRequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary(data) {
            return Object.assign(Object.assign({}, exports.GetNextGovernanceVAASequenceResponse.decode(data)), { toObject() {
                    return this;
                } });
        },
    },
};
class GrpcWebImpl {
    constructor(host, options) {
        this.host = host;
        this.options = options;
    }
    unary(methodDesc, _request, metadata) {
        var _a;
        const request = Object.assign(Object.assign({}, _request), methodDesc.requestType);
        const maybeCombinedMetadata = metadata && this.options.metadata
            ? new browser_headers_1.BrowserHeaders(Object.assign(Object.assign({}, (_a = this.options) === null || _a === void 0 ? void 0 : _a.metadata.headersMap), metadata === null || metadata === void 0 ? void 0 : metadata.headersMap))
            : metadata || this.options.metadata;
        return new Promise((resolve, reject) => {
            grpc_web_1.grpc.unary(methodDesc, {
                request,
                host: this.host,
                metadata: maybeCombinedMetadata,
                transport: this.options.transport,
                debug: this.options.debug,
                onEnd: function (response) {
                    if (response.status === grpc_web_1.grpc.Code.OK) {
                        resolve(response.message);
                    }
                    else {
                        const err = new Error(response.statusMessage);
                        err.code = response.status;
                        err.metadata = response.trailers;
                        reject(err);
                    }
                },
            });
        });
    }
}
exports.GrpcWebImpl = GrpcWebImpl;
var globalThis = (() => {
    if (typeof globalThis !== "undefined")
        return globalThis;
    if (typeof self !== "undefined")
        return self;
    if (typeof window !== "undefined")
        return window;
    if (typeof global !== "undefined")
        return global;
    throw "Unable to locate global object";
})();
const atob = globalThis.atob ||
    ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary"));
function bytesFromBase64(b64) {
    const bin = atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
        arr[i] = bin.charCodeAt(i);
    }
    return arr;
}
const btoa = globalThis.btoa ||
    ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64"));
function base64FromBytes(arr) {
    const bin = [];
    for (const byte of arr) {
        bin.push(String.fromCharCode(byte));
    }
    return btoa(bin.join(""));
}
function longToString(long) {
    return long.toString();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
