var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
/* eslint-disable */
import Long from "long";
import { grpc } from "@improbable-eng/grpc-web";
import _m0 from "protobufjs/minimal";
import { BrowserHeaders } from "browser-headers";
import { ObservationRequest } from "../../gossip/v1/gossip";
export var protobufPackage = "node.v1";
var baseInjectGovernanceVAARequest = {
    currentSetIndex: 0,
    timestamp: 0,
};
export var InjectGovernanceVAARequest = {
    encode: function (message, writer) {
        var e_1, _a;
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.currentSetIndex !== 0) {
            writer.uint32(8).uint32(message.currentSetIndex);
        }
        try {
            for (var _b = __values(message.messages), _c = _b.next(); !_c.done; _c = _b.next()) {
                var v = _c.value;
                GovernanceMessage.encode(v, writer.uint32(18).fork()).ldelim();
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
        if (message.timestamp !== 0) {
            writer.uint32(24).uint32(message.timestamp);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseInjectGovernanceVAARequest);
        message.messages = [];
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.currentSetIndex = reader.uint32();
                    break;
                case 2:
                    message.messages.push(GovernanceMessage.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.timestamp = reader.uint32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var e_2, _a;
        var message = __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) {
            try {
                for (var _b = __values(object.messages), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.messages.push(GovernanceMessage.fromJSON(e));
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_2) throw e_2.error; }
            }
        }
        if (object.timestamp !== undefined && object.timestamp !== null) {
            message.timestamp = Number(object.timestamp);
        }
        else {
            message.timestamp = 0;
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.currentSetIndex !== undefined &&
            (obj.currentSetIndex = message.currentSetIndex);
        if (message.messages) {
            obj.messages = message.messages.map(function (e) {
                return e ? GovernanceMessage.toJSON(e) : undefined;
            });
        }
        else {
            obj.messages = [];
        }
        message.timestamp !== undefined && (obj.timestamp = message.timestamp);
        return obj;
    },
    fromPartial: function (object) {
        var e_3, _a;
        var message = __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) {
            try {
                for (var _b = __values(object.messages), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.messages.push(GovernanceMessage.fromPartial(e));
                }
            }
            catch (e_3_1) { e_3 = { error: e_3_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_3) throw e_3.error; }
            }
        }
        if (object.timestamp !== undefined && object.timestamp !== null) {
            message.timestamp = object.timestamp;
        }
        else {
            message.timestamp = 0;
        }
        return message;
    },
};
var baseGovernanceMessage = {
    sequence: "0",
    nonce: 0,
    targetChainId: 0,
};
export var GovernanceMessage = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.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) {
            UpdateMessageFee.encode(message.updateMessageFee, writer.uint32(66).fork()).ldelim();
        }
        if (message.transferFee !== undefined) {
            TransferFee.encode(message.transferFee, writer.uint32(74).fork()).ldelim();
        }
        if (message.guardianSet !== undefined) {
            GuardianSetUpgrade.encode(message.guardianSet, writer.uint32(82).fork()).ldelim();
        }
        if (message.contractUpgrade !== undefined) {
            ContractUpgrade.encode(message.contractUpgrade, writer.uint32(90).fork()).ldelim();
        }
        if (message.bridgeRegisterChain !== undefined) {
            BridgeRegisterChain.encode(message.bridgeRegisterChain, writer.uint32(98).fork()).ldelim();
        }
        if (message.bridgeContractUpgrade !== undefined) {
            BridgeUpgradeContract.encode(message.bridgeContractUpgrade, writer.uint32(106).fork()).ldelim();
        }
        if (message.destroyUnexecutedSequenceContracts !== undefined) {
            TokenBridgeDestroyUnexecutedSequenceContracts.encode(message.destroyUnexecutedSequenceContracts, writer.uint32(162).fork()).ldelim();
        }
        if (message.updateMinimalConsistencyLevel !== undefined) {
            TokenBridgeUpdateMinimalConsistencyLevel.encode(message.updateMinimalConsistencyLevel, writer.uint32(170).fork()).ldelim();
        }
        if (message.updateRefundAddress !== undefined) {
            TokenBridgeUpdateRefundAddress.encode(message.updateRefundAddress, writer.uint32(178).fork()).ldelim();
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseGovernanceMessage);
        while (reader.pos < end) {
            var 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 = UpdateMessageFee.decode(reader, reader.uint32());
                    break;
                case 9:
                    message.transferFee = TransferFee.decode(reader, reader.uint32());
                    break;
                case 10:
                    message.guardianSet = GuardianSetUpgrade.decode(reader, reader.uint32());
                    break;
                case 11:
                    message.contractUpgrade = ContractUpgrade.decode(reader, reader.uint32());
                    break;
                case 12:
                    message.bridgeRegisterChain = BridgeRegisterChain.decode(reader, reader.uint32());
                    break;
                case 13:
                    message.bridgeContractUpgrade = BridgeUpgradeContract.decode(reader, reader.uint32());
                    break;
                case 20:
                    message.destroyUnexecutedSequenceContracts =
                        TokenBridgeDestroyUnexecutedSequenceContracts.decode(reader, reader.uint32());
                    break;
                case 21:
                    message.updateMinimalConsistencyLevel =
                        TokenBridgeUpdateMinimalConsistencyLevel.decode(reader, reader.uint32());
                    break;
                case 22:
                    message.updateRefundAddress = TokenBridgeUpdateRefundAddress.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __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 = UpdateMessageFee.fromJSON(object.updateMessageFee);
        }
        else {
            message.updateMessageFee = undefined;
        }
        if (object.transferFee !== undefined && object.transferFee !== null) {
            message.transferFee = TransferFee.fromJSON(object.transferFee);
        }
        else {
            message.transferFee = undefined;
        }
        if (object.guardianSet !== undefined && object.guardianSet !== null) {
            message.guardianSet = GuardianSetUpgrade.fromJSON(object.guardianSet);
        }
        else {
            message.guardianSet = undefined;
        }
        if (object.contractUpgrade !== undefined &&
            object.contractUpgrade !== null) {
            message.contractUpgrade = ContractUpgrade.fromJSON(object.contractUpgrade);
        }
        else {
            message.contractUpgrade = undefined;
        }
        if (object.bridgeRegisterChain !== undefined &&
            object.bridgeRegisterChain !== null) {
            message.bridgeRegisterChain = BridgeRegisterChain.fromJSON(object.bridgeRegisterChain);
        }
        else {
            message.bridgeRegisterChain = undefined;
        }
        if (object.bridgeContractUpgrade !== undefined &&
            object.bridgeContractUpgrade !== null) {
            message.bridgeContractUpgrade = BridgeUpgradeContract.fromJSON(object.bridgeContractUpgrade);
        }
        else {
            message.bridgeContractUpgrade = undefined;
        }
        if (object.destroyUnexecutedSequenceContracts !== undefined &&
            object.destroyUnexecutedSequenceContracts !== null) {
            message.destroyUnexecutedSequenceContracts =
                TokenBridgeDestroyUnexecutedSequenceContracts.fromJSON(object.destroyUnexecutedSequenceContracts);
        }
        else {
            message.destroyUnexecutedSequenceContracts = undefined;
        }
        if (object.updateMinimalConsistencyLevel !== undefined &&
            object.updateMinimalConsistencyLevel !== null) {
            message.updateMinimalConsistencyLevel =
                TokenBridgeUpdateMinimalConsistencyLevel.fromJSON(object.updateMinimalConsistencyLevel);
        }
        else {
            message.updateMinimalConsistencyLevel = undefined;
        }
        if (object.updateRefundAddress !== undefined &&
            object.updateRefundAddress !== null) {
            message.updateRefundAddress = TokenBridgeUpdateRefundAddress.fromJSON(object.updateRefundAddress);
        }
        else {
            message.updateRefundAddress = undefined;
        }
        return message;
    },
    toJSON: function (message) {
        var 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
                ? UpdateMessageFee.toJSON(message.updateMessageFee)
                : undefined);
        message.transferFee !== undefined &&
            (obj.transferFee = message.transferFee
                ? TransferFee.toJSON(message.transferFee)
                : undefined);
        message.guardianSet !== undefined &&
            (obj.guardianSet = message.guardianSet
                ? GuardianSetUpgrade.toJSON(message.guardianSet)
                : undefined);
        message.contractUpgrade !== undefined &&
            (obj.contractUpgrade = message.contractUpgrade
                ? ContractUpgrade.toJSON(message.contractUpgrade)
                : undefined);
        message.bridgeRegisterChain !== undefined &&
            (obj.bridgeRegisterChain = message.bridgeRegisterChain
                ? BridgeRegisterChain.toJSON(message.bridgeRegisterChain)
                : undefined);
        message.bridgeContractUpgrade !== undefined &&
            (obj.bridgeContractUpgrade = message.bridgeContractUpgrade
                ? BridgeUpgradeContract.toJSON(message.bridgeContractUpgrade)
                : undefined);
        message.destroyUnexecutedSequenceContracts !== undefined &&
            (obj.destroyUnexecutedSequenceContracts =
                message.destroyUnexecutedSequenceContracts
                    ? TokenBridgeDestroyUnexecutedSequenceContracts.toJSON(message.destroyUnexecutedSequenceContracts)
                    : undefined);
        message.updateMinimalConsistencyLevel !== undefined &&
            (obj.updateMinimalConsistencyLevel = message.updateMinimalConsistencyLevel
                ? TokenBridgeUpdateMinimalConsistencyLevel.toJSON(message.updateMinimalConsistencyLevel)
                : undefined);
        message.updateRefundAddress !== undefined &&
            (obj.updateRefundAddress = message.updateRefundAddress
                ? TokenBridgeUpdateRefundAddress.toJSON(message.updateRefundAddress)
                : undefined);
        return obj;
    },
    fromPartial: function (object) {
        var message = __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 = UpdateMessageFee.fromPartial(object.updateMessageFee);
        }
        else {
            message.updateMessageFee = undefined;
        }
        if (object.transferFee !== undefined && object.transferFee !== null) {
            message.transferFee = TransferFee.fromPartial(object.transferFee);
        }
        else {
            message.transferFee = undefined;
        }
        if (object.guardianSet !== undefined && object.guardianSet !== null) {
            message.guardianSet = GuardianSetUpgrade.fromPartial(object.guardianSet);
        }
        else {
            message.guardianSet = undefined;
        }
        if (object.contractUpgrade !== undefined &&
            object.contractUpgrade !== null) {
            message.contractUpgrade = ContractUpgrade.fromPartial(object.contractUpgrade);
        }
        else {
            message.contractUpgrade = undefined;
        }
        if (object.bridgeRegisterChain !== undefined &&
            object.bridgeRegisterChain !== null) {
            message.bridgeRegisterChain = BridgeRegisterChain.fromPartial(object.bridgeRegisterChain);
        }
        else {
            message.bridgeRegisterChain = undefined;
        }
        if (object.bridgeContractUpgrade !== undefined &&
            object.bridgeContractUpgrade !== null) {
            message.bridgeContractUpgrade = BridgeUpgradeContract.fromPartial(object.bridgeContractUpgrade);
        }
        else {
            message.bridgeContractUpgrade = undefined;
        }
        if (object.destroyUnexecutedSequenceContracts !== undefined &&
            object.destroyUnexecutedSequenceContracts !== null) {
            message.destroyUnexecutedSequenceContracts =
                TokenBridgeDestroyUnexecutedSequenceContracts.fromPartial(object.destroyUnexecutedSequenceContracts);
        }
        else {
            message.destroyUnexecutedSequenceContracts = undefined;
        }
        if (object.updateMinimalConsistencyLevel !== undefined &&
            object.updateMinimalConsistencyLevel !== null) {
            message.updateMinimalConsistencyLevel =
                TokenBridgeUpdateMinimalConsistencyLevel.fromPartial(object.updateMinimalConsistencyLevel);
        }
        else {
            message.updateMinimalConsistencyLevel = undefined;
        }
        if (object.updateRefundAddress !== undefined &&
            object.updateRefundAddress !== null) {
            message.updateRefundAddress = TokenBridgeUpdateRefundAddress.fromPartial(object.updateRefundAddress);
        }
        else {
            message.updateRefundAddress = undefined;
        }
        return message;
    },
};
var baseInjectGovernanceVAAResponse = {};
export var InjectGovernanceVAAResponse = {
    encode: function (message, writer) {
        var e_4, _a;
        if (writer === void 0) { writer = _m0.Writer.create(); }
        try {
            for (var _b = __values(message.digests), _c = _b.next(); !_c.done; _c = _b.next()) {
                var v = _c.value;
                writer.uint32(10).bytes(v);
            }
        }
        catch (e_4_1) { e_4 = { error: e_4_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_4) throw e_4.error; }
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseInjectGovernanceVAAResponse);
        message.digests = [];
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.digests.push(reader.bytes());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var e_5, _a;
        var message = __assign({}, baseInjectGovernanceVAAResponse);
        message.digests = [];
        if (object.digests !== undefined && object.digests !== null) {
            try {
                for (var _b = __values(object.digests), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.digests.push(bytesFromBase64(e));
                }
            }
            catch (e_5_1) { e_5 = { error: e_5_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_5) throw e_5.error; }
            }
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        if (message.digests) {
            obj.digests = message.digests.map(function (e) {
                return base64FromBytes(e !== undefined ? e : new Uint8Array());
            });
        }
        else {
            obj.digests = [];
        }
        return obj;
    },
    fromPartial: function (object) {
        var e_6, _a;
        var message = __assign({}, baseInjectGovernanceVAAResponse);
        message.digests = [];
        if (object.digests !== undefined && object.digests !== null) {
            try {
                for (var _b = __values(object.digests), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.digests.push(e);
                }
            }
            catch (e_6_1) { e_6 = { error: e_6_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_6) throw e_6.error; }
            }
        }
        return message;
    },
};
var baseUpdateMessageFee = { newMessageFee: "" };
export var UpdateMessageFee = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.newMessageFee !== "") {
            writer.uint32(10).string(message.newMessageFee);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseUpdateMessageFee);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.newMessageFee = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __assign({}, baseUpdateMessageFee);
        if (object.newMessageFee !== undefined && object.newMessageFee !== null) {
            message.newMessageFee = String(object.newMessageFee);
        }
        else {
            message.newMessageFee = "";
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.newMessageFee !== undefined &&
            (obj.newMessageFee = message.newMessageFee);
        return obj;
    },
    fromPartial: function (object) {
        var message = __assign({}, baseUpdateMessageFee);
        if (object.newMessageFee !== undefined && object.newMessageFee !== null) {
            message.newMessageFee = object.newMessageFee;
        }
        else {
            message.newMessageFee = "";
        }
        return message;
    },
};
var baseTransferFee = { amount: "", recipient: "" };
export var TransferFee = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.amount !== "") {
            writer.uint32(10).string(message.amount);
        }
        if (message.recipient !== "") {
            writer.uint32(18).string(message.recipient);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseTransferFee);
        while (reader.pos < end) {
            var 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: function (object) {
        var message = __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: function (message) {
        var obj = {};
        message.amount !== undefined && (obj.amount = message.amount);
        message.recipient !== undefined && (obj.recipient = message.recipient);
        return obj;
    },
    fromPartial: function (object) {
        var message = __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;
    },
};
var baseGuardianSetUpgrade = {};
export var GuardianSetUpgrade = {
    encode: function (message, writer) {
        var e_7, _a;
        if (writer === void 0) { writer = _m0.Writer.create(); }
        try {
            for (var _b = __values(message.guardians), _c = _b.next(); !_c.done; _c = _b.next()) {
                var v = _c.value;
                GuardianSetUpgrade_Guardian.encode(v, writer.uint32(26).fork()).ldelim();
            }
        }
        catch (e_7_1) { e_7 = { error: e_7_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_7) throw e_7.error; }
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseGuardianSetUpgrade);
        message.guardians = [];
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 3:
                    message.guardians.push(GuardianSetUpgrade_Guardian.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var e_8, _a;
        var message = __assign({}, baseGuardianSetUpgrade);
        message.guardians = [];
        if (object.guardians !== undefined && object.guardians !== null) {
            try {
                for (var _b = __values(object.guardians), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.guardians.push(GuardianSetUpgrade_Guardian.fromJSON(e));
                }
            }
            catch (e_8_1) { e_8 = { error: e_8_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_8) throw e_8.error; }
            }
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        if (message.guardians) {
            obj.guardians = message.guardians.map(function (e) {
                return e ? GuardianSetUpgrade_Guardian.toJSON(e) : undefined;
            });
        }
        else {
            obj.guardians = [];
        }
        return obj;
    },
    fromPartial: function (object) {
        var e_9, _a;
        var message = __assign({}, baseGuardianSetUpgrade);
        message.guardians = [];
        if (object.guardians !== undefined && object.guardians !== null) {
            try {
                for (var _b = __values(object.guardians), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.guardians.push(GuardianSetUpgrade_Guardian.fromPartial(e));
                }
            }
            catch (e_9_1) { e_9 = { error: e_9_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_9) throw e_9.error; }
            }
        }
        return message;
    },
};
var baseGuardianSetUpgrade_Guardian = { pubkey: "", name: "" };
export var GuardianSetUpgrade_Guardian = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.pubkey !== "") {
            writer.uint32(10).string(message.pubkey);
        }
        if (message.name !== "") {
            writer.uint32(18).string(message.name);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseGuardianSetUpgrade_Guardian);
        while (reader.pos < end) {
            var 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: function (object) {
        var message = __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: function (message) {
        var obj = {};
        message.pubkey !== undefined && (obj.pubkey = message.pubkey);
        message.name !== undefined && (obj.name = message.name);
        return obj;
    },
    fromPartial: function (object) {
        var message = __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;
    },
};
var baseGuardianKey = { unsafeDeterministicKey: false };
export var GuardianKey = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.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: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseGuardianKey);
        message.data = new Uint8Array();
        while (reader.pos < end) {
            var 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: function (object) {
        var message = __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: function (message) {
        var obj = {};
        message.data !== undefined &&
            (obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array()));
        message.unsafeDeterministicKey !== undefined &&
            (obj.unsafeDeterministicKey = message.unsafeDeterministicKey);
        return obj;
    },
    fromPartial: function (object) {
        var message = __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;
    },
};
var baseBridgeRegisterChain = {
    module: "",
    chainId: 0,
    emitterAddress: "",
};
export var BridgeRegisterChain = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.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: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseBridgeRegisterChain);
        while (reader.pos < end) {
            var 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: function (object) {
        var message = __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: function (message) {
        var 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: function (object) {
        var message = __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;
    },
};
var baseContractUpgrade = { payload: "" };
export var ContractUpgrade = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.payload !== "") {
            writer.uint32(10).string(message.payload);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseContractUpgrade);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.payload = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __assign({}, baseContractUpgrade);
        if (object.payload !== undefined && object.payload !== null) {
            message.payload = String(object.payload);
        }
        else {
            message.payload = "";
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.payload !== undefined && (obj.payload = message.payload);
        return obj;
    },
    fromPartial: function (object) {
        var message = __assign({}, baseContractUpgrade);
        if (object.payload !== undefined && object.payload !== null) {
            message.payload = object.payload;
        }
        else {
            message.payload = "";
        }
        return message;
    },
};
var baseBridgeUpgradeContract = { module: "", payload: "" };
export var BridgeUpgradeContract = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.module !== "") {
            writer.uint32(10).string(message.module);
        }
        if (message.payload !== "") {
            writer.uint32(18).string(message.payload);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseBridgeUpgradeContract);
        while (reader.pos < end) {
            var 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: function (object) {
        var message = __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: function (message) {
        var obj = {};
        message.module !== undefined && (obj.module = message.module);
        message.payload !== undefined && (obj.payload = message.payload);
        return obj;
    },
    fromPartial: function (object) {
        var message = __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;
    },
};
var baseTokenBridgeDestroyUnexecutedSequenceContracts = {
    emitterChain: 0,
    sequences: "0",
};
export var TokenBridgeDestroyUnexecutedSequenceContracts = {
    encode: function (message, writer) {
        var e_10, _a;
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.emitterChain !== 0) {
            writer.uint32(8).uint32(message.emitterChain);
        }
        writer.uint32(18).fork();
        try {
            for (var _b = __values(message.sequences), _c = _b.next(); !_c.done; _c = _b.next()) {
                var v = _c.value;
                writer.uint64(v);
            }
        }
        catch (e_10_1) { e_10 = { error: e_10_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_10) throw e_10.error; }
        }
        writer.ldelim();
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseTokenBridgeDestroyUnexecutedSequenceContracts);
        message.sequences = [];
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.emitterChain = reader.uint32();
                    break;
                case 2:
                    if ((tag & 7) === 2) {
                        var 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: function (object) {
        var e_11, _a;
        var message = __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) {
            try {
                for (var _b = __values(object.sequences), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.sequences.push(String(e));
                }
            }
            catch (e_11_1) { e_11 = { error: e_11_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_11) throw e_11.error; }
            }
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.emitterChain !== undefined &&
            (obj.emitterChain = message.emitterChain);
        if (message.sequences) {
            obj.sequences = message.sequences.map(function (e) { return e; });
        }
        else {
            obj.sequences = [];
        }
        return obj;
    },
    fromPartial: function (object) {
        var e_12, _a;
        var message = __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) {
            try {
                for (var _b = __values(object.sequences), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.sequences.push(e);
                }
            }
            catch (e_12_1) { e_12 = { error: e_12_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_12) throw e_12.error; }
            }
        }
        return message;
    },
};
var baseTokenBridgeUpdateMinimalConsistencyLevel = {
    newConsistencyLevel: 0,
};
export var TokenBridgeUpdateMinimalConsistencyLevel = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.newConsistencyLevel !== 0) {
            writer.uint32(8).uint32(message.newConsistencyLevel);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseTokenBridgeUpdateMinimalConsistencyLevel);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.newConsistencyLevel = reader.uint32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __assign({}, baseTokenBridgeUpdateMinimalConsistencyLevel);
        if (object.newConsistencyLevel !== undefined &&
            object.newConsistencyLevel !== null) {
            message.newConsistencyLevel = Number(object.newConsistencyLevel);
        }
        else {
            message.newConsistencyLevel = 0;
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.newConsistencyLevel !== undefined &&
            (obj.newConsistencyLevel = message.newConsistencyLevel);
        return obj;
    },
    fromPartial: function (object) {
        var message = __assign({}, baseTokenBridgeUpdateMinimalConsistencyLevel);
        if (object.newConsistencyLevel !== undefined &&
            object.newConsistencyLevel !== null) {
            message.newConsistencyLevel = object.newConsistencyLevel;
        }
        else {
            message.newConsistencyLevel = 0;
        }
        return message;
    },
};
var baseTokenBridgeUpdateRefundAddress = { newRefundAddress: "" };
export var TokenBridgeUpdateRefundAddress = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.newRefundAddress !== "") {
            writer.uint32(10).string(message.newRefundAddress);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseTokenBridgeUpdateRefundAddress);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.newRefundAddress = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __assign({}, baseTokenBridgeUpdateRefundAddress);
        if (object.newRefundAddress !== undefined &&
            object.newRefundAddress !== null) {
            message.newRefundAddress = String(object.newRefundAddress);
        }
        else {
            message.newRefundAddress = "";
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.newRefundAddress !== undefined &&
            (obj.newRefundAddress = message.newRefundAddress);
        return obj;
    },
    fromPartial: function (object) {
        var message = __assign({}, baseTokenBridgeUpdateRefundAddress);
        if (object.newRefundAddress !== undefined &&
            object.newRefundAddress !== null) {
            message.newRefundAddress = object.newRefundAddress;
        }
        else {
            message.newRefundAddress = "";
        }
        return message;
    },
};
var baseFindMissingMessagesRequest = {
    emitterChain: 0,
    targetChain: 0,
    emitterAddress: "",
    rpcBackfill: false,
    backfillNodes: "",
};
export var FindMissingMessagesRequest = {
    encode: function (message, writer) {
        var e_13, _a;
        if (writer === void 0) { writer = _m0.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);
        }
        try {
            for (var _b = __values(message.backfillNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
                var v = _c.value;
                writer.uint32(42).string(v);
            }
        }
        catch (e_13_1) { e_13 = { error: e_13_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_13) throw e_13.error; }
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseFindMissingMessagesRequest);
        message.backfillNodes = [];
        while (reader.pos < end) {
            var 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: function (object) {
        var e_14, _a;
        var message = __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) {
            try {
                for (var _b = __values(object.backfillNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.backfillNodes.push(String(e));
                }
            }
            catch (e_14_1) { e_14 = { error: e_14_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_14) throw e_14.error; }
            }
        }
        return message;
    },
    toJSON: function (message) {
        var 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(function (e) { return e; });
        }
        else {
            obj.backfillNodes = [];
        }
        return obj;
    },
    fromPartial: function (object) {
        var e_15, _a;
        var message = __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) {
            try {
                for (var _b = __values(object.backfillNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.backfillNodes.push(e);
                }
            }
            catch (e_15_1) { e_15 = { error: e_15_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_15) throw e_15.error; }
            }
        }
        return message;
    },
};
var baseFindMissingMessagesResponse = {
    missingMessages: "",
    firstSequence: "0",
    lastSequence: "0",
};
export var FindMissingMessagesResponse = {
    encode: function (message, writer) {
        var e_16, _a;
        if (writer === void 0) { writer = _m0.Writer.create(); }
        try {
            for (var _b = __values(message.missingMessages), _c = _b.next(); !_c.done; _c = _b.next()) {
                var v = _c.value;
                writer.uint32(10).string(v);
            }
        }
        catch (e_16_1) { e_16 = { error: e_16_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_16) throw e_16.error; }
        }
        if (message.firstSequence !== "0") {
            writer.uint32(16).uint64(message.firstSequence);
        }
        if (message.lastSequence !== "0") {
            writer.uint32(24).uint64(message.lastSequence);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseFindMissingMessagesResponse);
        message.missingMessages = [];
        while (reader.pos < end) {
            var 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: function (object) {
        var e_17, _a;
        var message = __assign({}, baseFindMissingMessagesResponse);
        message.missingMessages = [];
        if (object.missingMessages !== undefined &&
            object.missingMessages !== null) {
            try {
                for (var _b = __values(object.missingMessages), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.missingMessages.push(String(e));
                }
            }
            catch (e_17_1) { e_17 = { error: e_17_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_17) throw e_17.error; }
            }
        }
        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: function (message) {
        var obj = {};
        if (message.missingMessages) {
            obj.missingMessages = message.missingMessages.map(function (e) { return e; });
        }
        else {
            obj.missingMessages = [];
        }
        message.firstSequence !== undefined &&
            (obj.firstSequence = message.firstSequence);
        message.lastSequence !== undefined &&
            (obj.lastSequence = message.lastSequence);
        return obj;
    },
    fromPartial: function (object) {
        var e_18, _a;
        var message = __assign({}, baseFindMissingMessagesResponse);
        message.missingMessages = [];
        if (object.missingMessages !== undefined &&
            object.missingMessages !== null) {
            try {
                for (var _b = __values(object.missingMessages), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    message.missingMessages.push(e);
                }
            }
            catch (e_18_1) { e_18 = { error: e_18_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_18) throw e_18.error; }
            }
        }
        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;
    },
};
var baseSendObservationRequestRequest = {};
export var SendObservationRequestRequest = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.observationRequest !== undefined) {
            ObservationRequest.encode(message.observationRequest, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseSendObservationRequestRequest);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.observationRequest = ObservationRequest.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __assign({}, baseSendObservationRequestRequest);
        if (object.observationRequest !== undefined &&
            object.observationRequest !== null) {
            message.observationRequest = ObservationRequest.fromJSON(object.observationRequest);
        }
        else {
            message.observationRequest = undefined;
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.observationRequest !== undefined &&
            (obj.observationRequest = message.observationRequest
                ? ObservationRequest.toJSON(message.observationRequest)
                : undefined);
        return obj;
    },
    fromPartial: function (object) {
        var message = __assign({}, baseSendObservationRequestRequest);
        if (object.observationRequest !== undefined &&
            object.observationRequest !== null) {
            message.observationRequest = ObservationRequest.fromPartial(object.observationRequest);
        }
        else {
            message.observationRequest = undefined;
        }
        return message;
    },
};
var baseSendObservationRequestResponse = {};
export var SendObservationRequestResponse = {
    encode: function (_, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseSendObservationRequestResponse);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (_) {
        var message = __assign({}, baseSendObservationRequestResponse);
        return message;
    },
    toJSON: function (_) {
        var obj = {};
        return obj;
    },
    fromPartial: function (_) {
        var message = __assign({}, baseSendObservationRequestResponse);
        return message;
    },
};
var baseGetNextGovernanceVAASequenceRequest = {};
export var GetNextGovernanceVAASequenceRequest = {
    encode: function (_, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseGetNextGovernanceVAASequenceRequest);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (_) {
        var message = __assign({}, baseGetNextGovernanceVAASequenceRequest);
        return message;
    },
    toJSON: function (_) {
        var obj = {};
        return obj;
    },
    fromPartial: function (_) {
        var message = __assign({}, baseGetNextGovernanceVAASequenceRequest);
        return message;
    },
};
var baseGetNextGovernanceVAASequenceResponse = { sequence: "0" };
export var GetNextGovernanceVAASequenceResponse = {
    encode: function (message, writer) {
        if (writer === void 0) { writer = _m0.Writer.create(); }
        if (message.sequence !== "0") {
            writer.uint32(8).uint64(message.sequence);
        }
        return writer;
    },
    decode: function (input, length) {
        var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
        var end = length === undefined ? reader.len : reader.pos + length;
        var message = __assign({}, baseGetNextGovernanceVAASequenceResponse);
        while (reader.pos < end) {
            var tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.sequence = longToString(reader.uint64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON: function (object) {
        var message = __assign({}, baseGetNextGovernanceVAASequenceResponse);
        if (object.sequence !== undefined && object.sequence !== null) {
            message.sequence = String(object.sequence);
        }
        else {
            message.sequence = "0";
        }
        return message;
    },
    toJSON: function (message) {
        var obj = {};
        message.sequence !== undefined && (obj.sequence = message.sequence);
        return obj;
    },
    fromPartial: function (object) {
        var message = __assign({}, baseGetNextGovernanceVAASequenceResponse);
        if (object.sequence !== undefined && object.sequence !== null) {
            message.sequence = object.sequence;
        }
        else {
            message.sequence = "0";
        }
        return message;
    },
};
var NodePrivilegedServiceClientImpl = /** @class */ (function () {
    function NodePrivilegedServiceClientImpl(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);
    }
    NodePrivilegedServiceClientImpl.prototype.InjectGovernanceVAA = function (request, metadata) {
        return this.rpc.unary(NodePrivilegedServiceInjectGovernanceVAADesc, InjectGovernanceVAARequest.fromPartial(request), metadata);
    };
    NodePrivilegedServiceClientImpl.prototype.FindMissingMessages = function (request, metadata) {
        return this.rpc.unary(NodePrivilegedServiceFindMissingMessagesDesc, FindMissingMessagesRequest.fromPartial(request), metadata);
    };
    NodePrivilegedServiceClientImpl.prototype.SendObservationRequest = function (request, metadata) {
        return this.rpc.unary(NodePrivilegedServiceSendObservationRequestDesc, SendObservationRequestRequest.fromPartial(request), metadata);
    };
    NodePrivilegedServiceClientImpl.prototype.GetNextGovernanceVAASequence = function (request, metadata) {
        return this.rpc.unary(NodePrivilegedServiceGetNextGovernanceVAASequenceDesc, GetNextGovernanceVAASequenceRequest.fromPartial(request), metadata);
    };
    return NodePrivilegedServiceClientImpl;
}());
export { NodePrivilegedServiceClientImpl };
export var NodePrivilegedServiceDesc = {
    serviceName: "node.v1.NodePrivilegedService",
};
export var NodePrivilegedServiceInjectGovernanceVAADesc = {
    methodName: "InjectGovernanceVAA",
    service: NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary: function () {
            return InjectGovernanceVAARequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary: function (data) {
            return __assign(__assign({}, InjectGovernanceVAAResponse.decode(data)), { toObject: function () {
                    return this;
                } });
        },
    },
};
export var NodePrivilegedServiceFindMissingMessagesDesc = {
    methodName: "FindMissingMessages",
    service: NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary: function () {
            return FindMissingMessagesRequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary: function (data) {
            return __assign(__assign({}, FindMissingMessagesResponse.decode(data)), { toObject: function () {
                    return this;
                } });
        },
    },
};
export var NodePrivilegedServiceSendObservationRequestDesc = {
    methodName: "SendObservationRequest",
    service: NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary: function () {
            return SendObservationRequestRequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary: function (data) {
            return __assign(__assign({}, SendObservationRequestResponse.decode(data)), { toObject: function () {
                    return this;
                } });
        },
    },
};
export var NodePrivilegedServiceGetNextGovernanceVAASequenceDesc = {
    methodName: "GetNextGovernanceVAASequence",
    service: NodePrivilegedServiceDesc,
    requestStream: false,
    responseStream: false,
    requestType: {
        serializeBinary: function () {
            return GetNextGovernanceVAASequenceRequest.encode(this).finish();
        },
    },
    responseType: {
        deserializeBinary: function (data) {
            return __assign(__assign({}, GetNextGovernanceVAASequenceResponse.decode(data)), { toObject: function () {
                    return this;
                } });
        },
    },
};
var GrpcWebImpl = /** @class */ (function () {
    function GrpcWebImpl(host, options) {
        this.host = host;
        this.options = options;
    }
    GrpcWebImpl.prototype.unary = function (methodDesc, _request, metadata) {
        var _this = this;
        var _a;
        var request = __assign(__assign({}, _request), methodDesc.requestType);
        var maybeCombinedMetadata = metadata && this.options.metadata
            ? new BrowserHeaders(__assign(__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(function (resolve, reject) {
            grpc.unary(methodDesc, {
                request: request,
                host: _this.host,
                metadata: maybeCombinedMetadata,
                transport: _this.options.transport,
                debug: _this.options.debug,
                onEnd: function (response) {
                    if (response.status === grpc.Code.OK) {
                        resolve(response.message);
                    }
                    else {
                        var err = new Error(response.statusMessage);
                        err.code = response.status;
                        err.metadata = response.trailers;
                        reject(err);
                    }
                },
            });
        });
    };
    return GrpcWebImpl;
}());
export { GrpcWebImpl };
var globalThis = (function () {
    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";
})();
var atob = globalThis.atob ||
    (function (b64) { return globalThis.Buffer.from(b64, "base64").toString("binary"); });
function bytesFromBase64(b64) {
    var bin = atob(b64);
    var arr = new Uint8Array(bin.length);
    for (var i = 0; i < bin.length; ++i) {
        arr[i] = bin.charCodeAt(i);
    }
    return arr;
}
var btoa = globalThis.btoa ||
    (function (bin) { return globalThis.Buffer.from(bin, "binary").toString("base64"); });
function base64FromBytes(arr) {
    var e_19, _a;
    var bin = [];
    try {
        for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
            var byte = arr_1_1.value;
            bin.push(String.fromCharCode(byte));
        }
    }
    catch (e_19_1) { e_19 = { error: e_19_1 }; }
    finally {
        try {
            if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
        }
        finally { if (e_19) throw e_19.error; }
    }
    return btoa(bin.join(""));
}
function longToString(long) {
    return long.toString();
}
if (_m0.util.Long !== Long) {
    _m0.util.Long = Long;
    _m0.configure();
}
