diff --git a/scripts/proto/get-proto.sh b/scripts/proto/get-proto.sh index a13dd532..632a5794 100755 --- a/scripts/proto/get-proto.sh +++ b/scripts/proto/get-proto.sh @@ -1,5 +1,18 @@ #!/bin/bash -# TODO: get automatically from tgrade repo -# Create a "tgrade" folder with "confio" and "third_party" subfolders. -# "confio" contents come from: https://github.com/confio/tgrade/tree/main/proto/confio -# "third_party" contents come from: https://github.com/confio/tgrade/tree/main/third_party +# TODO: generate new proto automatically with support of context from Tgrade repo +# Steps: +# - Create a tgrade/ folder on the same folder as the codegen.sh and get-proto.sh. +# - Then inside that new tgrade/ folder you need 2 subfolders: confio/ and third_party/. +# ************************************** +## 1. src/scripts/proto/get-proto.sh +## 2. src/scripts/proto/codegen.sh +## 3. src/scripts/proto/tgrade/confio/ +## 4. src/scripts/proto/tgrade/third_party/ +# ************************************** + +# - Then for 3 and 4 we now need to fill those folders with content: +# - The contents for tgrade/confio/ come from https://github.com/confio/tgrade/tree/main/proto/confio +# - The contents for tgrade/third_party/ come from https://github.com/confio/tgrade/tree/main/third_party + +# To clone content - clone the main branch from the Tgrade repo and copy pasting those folders there. +# After you should be able to execute the codegen.sh script by yarn proto command. diff --git a/src/App/components/ApComplaintDetailModal/components/ProposalAddOCMembers.tsx b/src/App/components/ApComplaintDetailModal/components/ProposalAddOCMembers.tsx new file mode 100644 index 00000000..80ac2cee --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/components/ProposalAddOCMembers.tsx @@ -0,0 +1,18 @@ +import AddressList from "App/components/AddressList"; + +import { TextValue } from "../style"; + +interface ProposalAddOCMembersProps { + readonly proposalAddVotingMembers: readonly string[] | undefined; +} + +export default function ProposalAddOCMembers({ + proposalAddVotingMembers, +}: ProposalAddOCMembersProps): JSX.Element | null { + return proposalAddVotingMembers?.length ? ( + <> + Members to be added: + + + ) : null; +} diff --git a/src/App/components/ApComplaintDetailModal/components/ProposalGrantEngagementPoints.tsx b/src/App/components/ApComplaintDetailModal/components/ProposalGrantEngagementPoints.tsx new file mode 100644 index 00000000..fba60529 --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/components/ProposalGrantEngagementPoints.tsx @@ -0,0 +1,19 @@ +import AddressTag from "App/components/AddressTag"; +import { Engagement } from "utils/trustedCircle"; + +import { AddressField, TextLabel } from "../style"; + +interface ProposalGrantEngagementPointsProps { + readonly proposalGrantEngagement: Engagement | undefined; +} + +export default function ProposalGrantEngagementPoints({ + proposalGrantEngagement, +}: ProposalGrantEngagementPointsProps): JSX.Element | null { + return proposalGrantEngagement ? ( + + Grant {proposalGrantEngagement.points} Engagement Points to: + + + ) : null; +} diff --git a/src/App/components/ApComplaintDetailModal/components/ProposalPunishOCMember.tsx b/src/App/components/ApComplaintDetailModal/components/ProposalPunishOCMember.tsx new file mode 100644 index 00000000..946911a1 --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/components/ProposalPunishOCMember.tsx @@ -0,0 +1,119 @@ +import { Decimal } from "@cosmjs/math"; +import AddressList from "App/components/AddressList"; +import AddressTag from "App/components/AddressTag"; +import { useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { isValidAddress } from "utils/forms"; +import { OcContractQuerier } from "utils/oversightCommunity"; +import { Punishment } from "utils/trustedCircle"; + +import { AddressField, ChangedField, TextLabel, TextValue } from "../style"; + +interface ProposalPunishOCMemberProps { + readonly proposalPunishVotingMember: Punishment | undefined; +} + +export default function ProposalPunishOCMember({ + proposalPunishVotingMember, +}: ProposalPunishOCMemberProps): JSX.Element | null { + const memberToPunish = + proposalPunishVotingMember?.burn_escrow?.member || proposalPunishVotingMember?.distribute_escrow?.member; + + const kickOutMember = + proposalPunishVotingMember?.burn_escrow?.kick_out || + proposalPunishVotingMember?.distribute_escrow?.kick_out; + + const slashingPercentage = + proposalPunishVotingMember?.burn_escrow?.slashing_percentage || + proposalPunishVotingMember?.distribute_escrow?.slashing_percentage; + + const distributionList = proposalPunishVotingMember?.distribute_escrow?.distribution_list ?? []; + + const { handleError } = useError(); + const { + sdkState: { config, client }, + } = useSdk(); + const feeTokenDenom = config.coinMap[config.feeToken].denom || ""; + + const [memberEscrow, setMemberEscrow] = useState("0"); + const [toSlash, setToSlash] = useState("0"); + + useEffect(() => { + (async function updateMemberEscrow() { + if (!client || !memberToPunish) return; + + if (!isValidAddress(memberToPunish, config.addressPrefix)) { + setMemberEscrow("0"); + return; + } + + const ocContract = new OcContractQuerier(config, client); + + try { + const escrowResponse = await ocContract.getEscrow(memberToPunish); + if (!escrowResponse) throw new Error("No escrow found for user"); + + const decimals = config.coinMap[config.feeToken].fractionalDigits; + const userEscrowDecimal = Decimal.fromAtomics(escrowResponse.paid, decimals); + setMemberEscrow(userEscrowDecimal.toString()); + } catch (error) { + console.error(error); + setMemberEscrow("0"); + } + })(); + }, [client, config, memberToPunish]); + + useEffect(() => { + if (!slashingPercentage) return; + + try { + const slashingPercentageNumber = parseFloat(slashingPercentage); + const toSlash = ( + Decimal.fromUserInput( + memberEscrow, + config.coinMap[config.feeToken].fractionalDigits, + ).toFloatApproximation() * slashingPercentageNumber + ).toString(); + + setToSlash(toSlash); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + }, [config.coinMap, config.feeToken, handleError, memberEscrow, slashingPercentage]); + + if (!memberToPunish) return null; + + return ( + <> + + Member to punish: + + + {kickOutMember !== undefined ? ( + + + {kickOutMember + ? "The member WILL BE kicked out of the Trusted Circle" + : "The member WILL NOT BE kicked out of the Trusted Circle"} + + + ) : null} + {slashingPercentage?.length && slashingPercentage !== "0" ? ( + + {`Escrow to be slashed: ${ + parseFloat(slashingPercentage) * 100 + }% of ${memberEscrow} ${feeTokenDenom} = ${toSlash} ${feeTokenDenom}`} + + ) : null} + {distributionList.length ? ( + <> + The slashed escrow will be distributed to: + + + ) : ( + The slashed escrow will be burned + )} + + ); +} diff --git a/src/App/components/ApComplaintDetailModal/components/ProposalPunishValidator.tsx b/src/App/components/ApComplaintDetailModal/components/ProposalPunishValidator.tsx new file mode 100644 index 00000000..e01dccb9 --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/components/ProposalPunishValidator.tsx @@ -0,0 +1,51 @@ +import AddressTag from "App/components/AddressTag"; +import moment from "moment"; +import { ValidatorPunishment } from "utils/trustedCircle"; + +import { TextLabel } from "../style"; + +interface ProposalPunishValidatorProps { + readonly proposalPunishValidator: ValidatorPunishment | undefined; +} + +const todayDate = Math.round(new Date().getTime() / 1000); +// dateOffset required due to inacuraccy in actual release time +const dateOffset = 43200; + +export default function ProposalPunishValidator({ + proposalPunishValidator, +}: ProposalPunishValidatorProps): JSX.Element | null { + if (!proposalPunishValidator) return null; + + const dateInSeconds = proposalPunishValidator.jailing_duration?.duration + ? todayDate + proposalPunishValidator.jailing_duration.duration + dateOffset + : 0; + + return ( + <> + + Validator To be Punished: + + {proposalPunishValidator.jailing_duration?.forever ? ( + + Validator will be jailed forever + + ) : null} + {proposalPunishValidator.jailing_duration?.duration && + proposalPunishValidator.jailing_duration.duration !== 0 ? ( + + Validator will be jailed until:{" "} + + {moment.unix(dateInSeconds).local().format("DD/MM/YYYY")} + + + ) : null} + {proposalPunishValidator.portion && proposalPunishValidator.portion !== "0" ? ( + + Percentage to slash of funds and Distributed Points:{" "} + {parseFloat(proposalPunishValidator.portion) * 100}% + + ) : null} + + ); +} diff --git a/src/App/components/ApComplaintDetailModal/components/ProposalUnjailValidator.tsx b/src/App/components/ApComplaintDetailModal/components/ProposalUnjailValidator.tsx new file mode 100644 index 00000000..faa74aa8 --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/components/ProposalUnjailValidator.tsx @@ -0,0 +1,22 @@ +import AddressTag from "App/components/AddressTag"; +import { ValidatorUnjail } from "utils/trustedCircle"; + +import { TextLabel } from "../style"; + +interface ProposalUnjailValidatorProps { + readonly proposalUnjailValidator: ValidatorUnjail | undefined; +} + +export default function ProposalUnjailValidator({ + proposalUnjailValidator, +}: ProposalUnjailValidatorProps): JSX.Element | null { + if (!proposalUnjailValidator) return null; + + return ( + <> + + Validator To be Unjailed: + + + ); +} diff --git a/src/App/components/ApComplaintDetailModal/index.tsx b/src/App/components/ApComplaintDetailModal/index.tsx new file mode 100644 index 00000000..bb90e42e --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/index.tsx @@ -0,0 +1,334 @@ +import { calculateFee, Coin } from "@cosmjs/stargate"; +import { Collapse } from "antd"; +import closeIcon from "App/assets/icons/cross.svg"; +import { ReactComponent as StatusExecutedIcon } from "App/assets/icons/status-executed-icon.svg"; +import { ReactComponent as StatusOpenIcon } from "App/assets/icons/status-open-icon.svg"; +import { ReactComponent as StatusPassedIcon } from "App/assets/icons/status-passed-icon.svg"; +import Button from "App/components/Button"; +import ShowTxResult, { TxResult } from "App/components/ShowTxResult"; +import Stack from "App/components/Stack/style"; +import { useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContract, ApContractQuerier, ProposalResponse, VoteInfo, VoteOption } from "utils/arbiterPool"; +import { getDisplayAmountFromFee } from "utils/currency"; +import { getErrorFromStackTrace } from "utils/errors"; + +import ButtonVote from "../ButtonVote"; +import VotesTable from "../VotesTable"; +import WarningBanner from "../WarningBanner"; +import { + ButtonGroup, + FeeWrapper, + ModalHeader, + Paragraph, + SectionWrapper, + Separator, + StyledCollapse, + StyledModal, + Text, + Title, +} from "./style"; + +interface ApComplaintDetailModalProps { + readonly isModalOpen: boolean; + readonly closeModal: () => void; + readonly proposalId: number | undefined; + readonly refreshComplaints: () => void; +} + +export default function ApComplaintDetailModal({ + isModalOpen, + closeModal, + proposalId, + refreshComplaints, +}: ApComplaintDetailModalProps): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { config, client, address, signingClient }, + } = useSdk(); + + const [submitting, setSubmitting] = useState(); + const [txResult, setTxResult] = useState(); + const [hasVoted, setHasVoted] = useState(false); + + const [txFee, setTxFee] = useState("0"); + const feeTokenDenom = config.coinMap[config.feeToken].denom || ""; + + const [proposal, setProposal] = useState(); + + const expiryTime = proposal + ? Number(typeof proposal.expires === "string" ? proposal.expires : proposal.expires.at_time) / 1000000 + : 0; + const isProposalNotExpired = expiryTime > Date.now(); + + //const { amount: nativeCoinToSend, to_addr: receiverAddress } = proposal?.proposal.send_proposal ?? {}; + const [isVotingMember, setVotingMember] = useState(false); + const [coinToSend, setCoinToSend] = useState(); + + const [isTableLoading, setTableLoading] = useState(false); + const [votes, setVotes] = useState([]); + useEffect(() => { + (async function queryVotes() { + if (!client || !proposalId) return; + + try { + const tcContract = new ApContractQuerier(config, client); + setTableLoading(true); + const votes = await tcContract.getAllVotes(proposalId); + setVotes(votes); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } finally { + setTableLoading(false); + } + })(); + }, [client, config, handleError, proposalId]); + + useEffect(() => { + if (!signingClient) return; + + try { + const fee = calculateFee(ApContract.GAS_PROPOSE, config.gasPrice); + const txFee = getDisplayAmountFromFee(fee, config); + setTxFee(txFee); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + }, [config, handleError, signingClient]); + + useEffect(() => { + (async function queryProposal() { + if (!client || !proposalId) return; + + try { + const arbiterPoolContractQuerier = new ApContractQuerier(config, client); + const proposal = await arbiterPoolContractQuerier.getProposal(proposalId); + setProposal(proposal); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [client, config, handleError, proposalId]); + + useEffect(() => { + (async function queryVoter() { + if (!address || !client || !proposalId) return; + + try { + const arbiterPoolContractQuerier = new ApContractQuerier(config, client); + const voter = await arbiterPoolContractQuerier.getVote(proposalId, address); + setHasVoted(voter.vote?.voter === address); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [address, client, config, handleError, proposalId]); + + useEffect(() => { + (async function queryMembership() { + if (!client || !address) return; + + try { + const arbiterPoolContractQuerier = new ApContractQuerier(config, client); + const isVotingMember = (await arbiterPoolContractQuerier.getVoters()).some( + (voter) => voter.addr === address, + ); + setVotingMember(isVotingMember); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [address, client, config, handleError]); + + function resetModal() { + closeModal(); + setTxResult(undefined); + refreshComplaints(); + } + + async function submitVoteProposal(chosenVote: VoteOption) { + if (!signingClient || !address || !proposalId) return; + setSubmitting(chosenVote); + + try { + const cPoolContract = new ApContract(config, signingClient); + const transactionHash = await cPoolContract.voteProposal(address, proposalId, chosenVote); + + setTxResult({ + msg: `Voted proposal with ID ${proposalId}. Transaction ID: ${transactionHash}`, + }); + } catch (error) { + if (!(error instanceof Error)) return; + setTxResult({ error: getErrorFromStackTrace(error) }); + handleError(error); + } finally { + setSubmitting(undefined); + } + } + + function calculateTotalVotes(): number { + return (proposal?.votes.yes ?? 0) + (proposal?.votes.no ?? 0) + (proposal?.votes.abstain ?? 0); + } + + async function submitExecuteProposal() { + if (!signingClient || !address || !proposalId) return; + setSubmitting("executing"); + + try { + const arbiterPoolContract = new ApContract(config, signingClient); + const transactionHash = await arbiterPoolContract.executeProposal(address, proposalId); + + setTxResult({ + msg: `Executed proposal with ID ${proposalId}. Transaction ID: ${transactionHash}`, + }); + } catch (error) { + if (!(error instanceof Error)) return; + setTxResult({ error: getErrorFromStackTrace(error) }); + handleError(error); + } finally { + setSubmitting(undefined); + } + } + + const canUserVote = + address && + !hasVoted && + isProposalNotExpired && + isVotingMember && + (proposal?.status === "open" || proposal?.status === "passed"); + + return ( + + {txResult ? ( + + {txResult.error ? ( + + ) : null} + + + ) : ( + + + {proposal ? ( +
+ + NÂș {proposal.id} "{proposal.title}" + + {proposal?.status === "passed" ? : null} + {proposal?.status === "open" ? : null} + {proposal?.status === "executed" ? : null} +
+ ) : null} + {!submitting ? Close button resetModal()} /> : null} +
+ + {proposal ? ( + <> + + + + + Progress and results + + + Total voted: + + {calculateTotalVotes()} of {proposal.total_points} + + + + Yes: {proposal.votes.yes ?? 0} + + + No: {proposal.votes.no ?? 0} + + + Abstain: {proposal.votes.abstain ?? 0} + + + + } + > + + + + + + + {address && proposal?.status === "passed" ? ( + + ) : null} + + +

Transaction fee

+

{`~${txFee} ${feeTokenDenom}`}

+
+ submitVoteProposal("yes")} + > + Yes + + submitVoteProposal("no")} + > + No + + submitVoteProposal("abstain")} + > + Abstain + +
+
+ {!isVotingMember ? ( + + ) : null} + + ) : null} +
+ )} +
+ ); +} diff --git a/src/App/components/ApComplaintDetailModal/style.ts b/src/App/components/ApComplaintDetailModal/style.ts new file mode 100644 index 00000000..d15e8321 --- /dev/null +++ b/src/App/components/ApComplaintDetailModal/style.ts @@ -0,0 +1,184 @@ +import { Collapse, Divider, Modal, Typography } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + & .ant-modal-content { + border-radius: 16px; + } + + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; +`; + +export const TextLabel = styled(Typography.Text)` + && { + color: var(--color-text-1ary); + font-weight: 500; + } +`; + +export const TextValue = styled(Typography.Text)` + && { + color: var(--color-text-1ary); + white-space: pre-line; + } +`; + +export const AddressField = styled(Typography)` + margin-top: var(--s-1); + display: flex; + + & * + * { + margin-left: var(--s-2); + } +`; + +export const ChangedField = styled(Typography)` + margin-top: var(--s-1); + + & > * { + display: block; + } +`; + +export const FeeGroup = styled.div` + display: flex; + align-items: center; + flex-wrap: wrap; + + & > *:first-child { + margin-right: var(--s0); + } +`; + +export const Title = styled(Typography.Title)` + &.ant-typography { + color: #000; + font-weight: 500; + font-size: 30px; + } +`; + +export const Paragraph = styled.p` + margin-left: 50px; + & b { + margin-left: 5px; + } +`; + +export const Text = styled(Typography.Text)` + &.ant-typography { + color: #000; + font-weight: 500; + } +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + flex-direction: column; + flex-wrap: wrap; + align-items: flex-start; + justify-content: space-between; + + & div { + width: 100%; + display: flex; + align-items: center; + justify-content: space-between; + } + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & span.ant-typography { + line-height: 28px; + color: #8692a6; + } + + & img { + position: absolute; + top: 0; + right: -40px; + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled(Divider)` + margin: 2px; +`; + +export const SectionWrapper = styled.div` + display: flex; + align-items: center; + justify-content: space-between; +`; + +export const FeeWrapper = styled.div` + display: flex; + flex-direction: column; + margin-right: 10px; + align-items: flex-end; + min-width: 100px; +`; + +export const ParticipantsWrapper = styled.div` + display: flex; + flex-direction: column; + & p { + margin: 0; + } +`; + +export const ButtonGroup = styled.div` + margin-left: auto; + display: flex; + height: 82px; + align-items: center; + + & button { + height: 42px; + flex-basis: calc(50% - calc(var(--s1) / 2)); + } + + & button + button { + margin-left: var(--s1); + } + + & .ant-btn { + } +`; + +export const StyledCollapse = styled(Collapse)` + flex-basis: 100%; + + &.ant-collapse > .ant-collapse-item > .ant-collapse-header { + padding: 0; + display: flex; + align-items: center; + + & > div { + flex-basis: 100%; + } + } + + & .ant-collapse-content > .ant-collapse-content-box { + padding: 0; + } +`; diff --git a/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/ConfirmationOpenText/index.tsx b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/ConfirmationOpenText/index.tsx new file mode 100644 index 00000000..42844295 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/ConfirmationOpenText/index.tsx @@ -0,0 +1,69 @@ +import { calculateFee } from "@cosmjs/stargate"; +import { Typography } from "antd"; +import BackButtonOrLink from "App/components/BackButtonOrLink"; +import Button from "App/components/Button"; +import { lazy, useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContract } from "utils/arbiterPool"; +import { getDisplayAmountFromFee } from "utils/currency"; + +import { ButtonGroup, FeeGroup, ProposalText, Separator } from "./style"; + +const ConnectWalletModal = lazy(() => import("App/components/ConnectWalletModal")); +const { Paragraph } = Typography; + +interface ConfirmationOpenTextProps { + readonly text: string; + readonly isSubmitting: boolean; + readonly goBack: () => void; + readonly submitForm: () => void; +} + +export default function ConfirmationOpenText({ + text, + isSubmitting, + goBack, + submitForm, +}: ConfirmationOpenTextProps): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { config, signer, signingClient }, + } = useSdk(); + + const [isModalOpen, setModalOpen] = useState(false); + const [txFee, setTxFee] = useState("0"); + const feeTokenDenom = config.coinMap[config.feeToken].denom || ""; + + useEffect(() => { + if (!signingClient) return; + + try { + const fee = calculateFee(ApContract.GAS_PROPOSE, config.gasPrice); + const txFee = getDisplayAmountFromFee(fee, config); + setTxFee(txFee); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + }, [config, handleError, signingClient]); + + return ( + <> + {text} + + + goBack()} text="Back" /> + + + Tx fee + {`~${txFee} ${feeTokenDenom}`} + + + + + setModalOpen(false)} /> + + ); +} diff --git a/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/ConfirmationOpenText/style.ts b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/ConfirmationOpenText/style.ts new file mode 100644 index 00000000..f1370f05 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/ConfirmationOpenText/style.ts @@ -0,0 +1,38 @@ +import { Typography } from "antd"; +import styled from "styled-components"; + +const { Text } = Typography; + +export const ProposalText = styled(Text)` + && { + color: var(--color-text-1ary); + white-space: pre-line; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const ButtonGroup = styled.div` + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + + & > *:first-child { + margin-right: var(--s0); + } +`; + +export const FeeGroup = styled.div` + display: flex; + align-items: center; + flex-wrap: wrap; + + & > *:first-child { + margin-right: var(--s0); + } +`; diff --git a/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/FormOpenText/index.tsx b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/FormOpenText/index.tsx new file mode 100644 index 00000000..bd4b3a17 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/FormOpenText/index.tsx @@ -0,0 +1,62 @@ +import BackButtonOrLink from "App/components/BackButtonOrLink"; +import Button from "App/components/Button"; +import Field from "App/components/Field"; +import { Formik } from "formik"; +import { Form } from "formik-antd"; +import { getFormItemName } from "utils/forms"; +import * as Yup from "yup"; + +import { ButtonGroup, FormStack, Separator } from "./style"; + +const textLabel = "Text"; + +const validationSchema = Yup.object().shape({ + [getFormItemName(textLabel)]: Yup.string() + .typeError("Text must be alphanumeric") + .required("Text is required") + .min(10, "Text length should be between 10 and 500 characters") + .max(500, "Text length should be between 10 and 500 characters"), +}); + +export interface FormOpenTextValues { + readonly text: string; +} + +interface FormOpenTextProps extends FormOpenTextValues { + readonly goBack: () => void; + readonly handleSubmit: (values: FormOpenTextValues) => void; +} + +export default function FormOpenText({ text, goBack, handleSubmit }: FormOpenTextProps): JSX.Element { + return ( + + handleSubmit({ + text: values[getFormItemName(textLabel)], + }) + } + > + {({ isValid, submitForm }) => ( + <> +
+ + + + + goBack()} text="Back" /> + + + +
+ + )} +
+ ); +} diff --git a/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/FormOpenText/style.ts b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/FormOpenText/style.ts new file mode 100644 index 00000000..77606f57 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/components/FormOpenText/style.ts @@ -0,0 +1,28 @@ +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FormStack = styled(Stack)` + & .ant-input-textarea { + flex-basis: 100%; + } + + & .ant-form-item-has-error .ant-input-textarea::after { + color: var(--color-error-form); + } +`; + +export const ButtonGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + button:first-child { + margin-right: var(--s0); + } +`; diff --git a/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/index.tsx b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/index.tsx new file mode 100644 index 00000000..ef6f1678 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/index.tsx @@ -0,0 +1,72 @@ +import { TxResult } from "App/components/ShowTxResult"; +import { useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContract } from "utils/arbiterPool"; +import { getErrorFromStackTrace } from "utils/errors"; + +import { ProposalStep, ProposalType } from "../.."; +import ConfirmationOpenText from "./components/ConfirmationOpenText"; +import FormOpenText, { FormOpenTextValues } from "./components/FormOpenText"; + +interface ProposalOpenTextProps { + readonly proposalStep: ProposalStep; + readonly setProposalStep: React.Dispatch>; + readonly isSubmitting: boolean; + readonly setSubmitting: React.Dispatch>; + readonly setTxResult: React.Dispatch>; +} + +export default function ProposalOpenText({ + proposalStep, + setProposalStep, + isSubmitting, + setSubmitting, + setTxResult, +}: ProposalOpenTextProps): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { address, signingClient, config }, + } = useSdk(); + + const [text, setText] = useState(""); + + async function submitOpenText({ text }: FormOpenTextValues) { + setText(text); + setProposalStep({ type: ProposalType.OpenText, confirmation: true }); + } + + async function submitCreateProposal() { + if (!signingClient || !address) return; + setSubmitting(true); + + try { + const ocContract = new ApContract(config, signingClient); + const { txHash } = await ocContract.propose(address, text, { text: {} }); + + setTxResult({ + msg: `Created proposal for Open Text from Arbiter Pool Proposals. Transaction ID: ${txHash}`, + }); + } catch (error) { + if (!(error instanceof Error)) return; + setTxResult({ error: getErrorFromStackTrace(error) }); + handleError(error); + } finally { + setSubmitting(false); + } + } + + return ( + <> + {proposalStep.confirmation ? ( + setProposalStep({ type: ProposalType.OpenText })} + submitForm={submitCreateProposal} + /> + ) : ( + setProposalStep(undefined)} handleSubmit={submitOpenText} /> + )} + + ); +} diff --git a/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/style.ts b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/style.ts new file mode 100644 index 00000000..535a1178 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ProposalOpenText/style.ts @@ -0,0 +1,53 @@ +import { Modal } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + align-items: center; + justify-content: space-between; + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & img { + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateComplaintModal/components/SelectProposal/index.tsx b/src/App/components/ApCreateComplaintModal/components/SelectProposal/index.tsx new file mode 100644 index 00000000..dd76d52e --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/SelectProposal/index.tsx @@ -0,0 +1,44 @@ +import { Typography } from "antd"; +import { SelectValue } from "antd/lib/select"; +import { ReactComponent as DownArrow } from "App/assets/icons/down-arrow.svg"; +import Button from "App/components/Button"; +import Select from "App/components/Select"; +import * as React from "react"; +import { useState } from "react"; + +import { proposalLabels, ProposalStep, ProposalType } from "../.."; +import { ProposalStack, Separator, StyledSelect } from "./style"; + +const { Option } = Select; +const { Text } = Typography; + +interface SelectProposalProps { + readonly setProposalStep: React.Dispatch>; +} + +export default function SelectProposal({ setProposalStep }: SelectProposalProps): JSX.Element { + const [selectedProposal, setSelectedProposal] = useState(ProposalType.OpenText); + + return ( + <> + + Proposal + } + defaultActiveFirstOption + size="large" + value={selectedProposal} + onChange={(proposalType: SelectValue) => setSelectedProposal(proposalType as ProposalType)} + > + {Object.values(ProposalType).map((proposalType) => ( + + ))} + + + + + + ); +} diff --git a/src/App/components/ApCreateComplaintModal/components/SelectProposal/style.ts b/src/App/components/ApCreateComplaintModal/components/SelectProposal/style.ts new file mode 100644 index 00000000..88f23bb3 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/SelectProposal/style.ts @@ -0,0 +1,38 @@ +import Select from "App/components/Select"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const ProposalStack = styled(Stack)` + & span.ant-typography { + font-size: var(--s0); + color: var(--color-text-1ary); + } + + & .ant-select { + align-self: flex-start; + width: 100%; + max-width: 22rem; + } +`; + +export const StyledSelect = styled(Select)` + .ant-select-arrow { + color: #8692a6; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateComplaintModal/components/ShowTxResultProposal/index.tsx b/src/App/components/ApCreateComplaintModal/components/ShowTxResultProposal/index.tsx new file mode 100644 index 00000000..bec9bfd5 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ShowTxResultProposal/index.tsx @@ -0,0 +1,28 @@ +import Button from "App/components/Button"; +import ShowTxResult, { TxResult } from "App/components/ShowTxResult"; + +interface ShowTxResultProposalProps { + readonly txResult: TxResult; + readonly setTxResult: React.Dispatch>; + readonly tryAgain: () => void; + readonly resetModal: () => void; +} + +export default function ShowTxResultProposal({ + txResult, + tryAgain, + resetModal, +}: ShowTxResultProposalProps): JSX.Element { + return ( + + {txResult.error ? ( + + ) : null} + + + ); +} diff --git a/src/App/components/ApCreateComplaintModal/components/ShowTxResultProposal/style.ts b/src/App/components/ApCreateComplaintModal/components/ShowTxResultProposal/style.ts new file mode 100644 index 00000000..535a1178 --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/components/ShowTxResultProposal/style.ts @@ -0,0 +1,53 @@ +import { Modal } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + align-items: center; + justify-content: space-between; + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & img { + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateComplaintModal/index.tsx b/src/App/components/ApCreateComplaintModal/index.tsx new file mode 100644 index 00000000..e86497fb --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/index.tsx @@ -0,0 +1,131 @@ +import { Typography } from "antd"; +import closeIcon from "App/assets/icons/cross.svg"; +import { TxResult } from "App/components/ShowTxResult"; +import Stack from "App/components/Stack/style"; +import Steps from "App/components/Steps"; +import { lazy, useState } from "react"; + +import SelectProposal from "./components/SelectProposal"; +import ShowTxResultProposal from "./components/ShowTxResultProposal"; +import { ModalHeader, Separator, StyledModal } from "./style"; + +const ProposalOpenText = lazy(() => import("./components/ProposalOpenText")); + +const { Title, Text } = Typography; +const { Step } = Steps; + +export enum ProposalType { + OpenText = "open-text", +} + +export const proposalLabels = { + [ProposalType.OpenText]: "Open text proposal", +}; + +export const proposalTitles = { + newProposal: "New proposal", + ...proposalLabels, + confirmation: "Confirmation", +}; + +export type ProposalStep = { type: ProposalType; confirmation?: true }; + +function getTitleFromStep(step?: ProposalStep): string { + return step?.confirmation + ? proposalTitles.confirmation + : step + ? proposalTitles[step.type] + : proposalTitles.newProposal; +} + +function getCurrentStepIndex(step?: ProposalStep): number { + return step?.confirmation ? 2 : step?.type ? 1 : 0; +} + +interface ApCreateComplaintModalProps { + readonly isModalOpen: boolean; + readonly closeModal: () => void; + readonly refreshComplaints: () => void; +} + +export default function ApCreateComplaintModal({ + isModalOpen, + closeModal, + refreshComplaints, +}: ApCreateComplaintModalProps): JSX.Element { + const [proposalStep, setProposalStep] = useState(); + const [isSubmitting, setSubmitting] = useState(false); + const [txResult, setTxResult] = useState(); + + function tryAgain() { + setProposalStep(proposalStep ? { type: proposalStep.type } : undefined); + setTxResult(undefined); + } + + function resetModal() { + closeModal(); + setProposalStep(undefined); + setSubmitting(false); + setTxResult(undefined); + refreshComplaints(); + } + + return ( + + {txResult ? ( + + ) : ( + + + + {getTitleFromStep(proposalStep)} + Community Pool + + + + + + + {!isSubmitting ? Close button closeModal()} /> : null} + + + {!proposalStep ? ( + + ) : proposalStep.type === ProposalType.OpenText ? ( + + ) : null} + + )} + + ); +} diff --git a/src/App/components/ApCreateComplaintModal/style.ts b/src/App/components/ApCreateComplaintModal/style.ts new file mode 100644 index 00000000..4774277a --- /dev/null +++ b/src/App/components/ApCreateComplaintModal/style.ts @@ -0,0 +1,65 @@ +import { Modal } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + & .ant-modal-content { + border-radius: 16px; + } + + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; + + & .ant-btn { + align-self: flex-end; + } +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + flex-wrap: wrap; + align-items: flex-start; + justify-content: space-between; + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & img { + position: absolute; + top: 0; + right: -40px; + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/ConfirmationOpenText/index.tsx b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/ConfirmationOpenText/index.tsx new file mode 100644 index 00000000..42844295 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/ConfirmationOpenText/index.tsx @@ -0,0 +1,69 @@ +import { calculateFee } from "@cosmjs/stargate"; +import { Typography } from "antd"; +import BackButtonOrLink from "App/components/BackButtonOrLink"; +import Button from "App/components/Button"; +import { lazy, useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContract } from "utils/arbiterPool"; +import { getDisplayAmountFromFee } from "utils/currency"; + +import { ButtonGroup, FeeGroup, ProposalText, Separator } from "./style"; + +const ConnectWalletModal = lazy(() => import("App/components/ConnectWalletModal")); +const { Paragraph } = Typography; + +interface ConfirmationOpenTextProps { + readonly text: string; + readonly isSubmitting: boolean; + readonly goBack: () => void; + readonly submitForm: () => void; +} + +export default function ConfirmationOpenText({ + text, + isSubmitting, + goBack, + submitForm, +}: ConfirmationOpenTextProps): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { config, signer, signingClient }, + } = useSdk(); + + const [isModalOpen, setModalOpen] = useState(false); + const [txFee, setTxFee] = useState("0"); + const feeTokenDenom = config.coinMap[config.feeToken].denom || ""; + + useEffect(() => { + if (!signingClient) return; + + try { + const fee = calculateFee(ApContract.GAS_PROPOSE, config.gasPrice); + const txFee = getDisplayAmountFromFee(fee, config); + setTxFee(txFee); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + }, [config, handleError, signingClient]); + + return ( + <> + {text} + + + goBack()} text="Back" /> + + + Tx fee + {`~${txFee} ${feeTokenDenom}`} + + + + + setModalOpen(false)} /> + + ); +} diff --git a/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/ConfirmationOpenText/style.ts b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/ConfirmationOpenText/style.ts new file mode 100644 index 00000000..f1370f05 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/ConfirmationOpenText/style.ts @@ -0,0 +1,38 @@ +import { Typography } from "antd"; +import styled from "styled-components"; + +const { Text } = Typography; + +export const ProposalText = styled(Text)` + && { + color: var(--color-text-1ary); + white-space: pre-line; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const ButtonGroup = styled.div` + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + + & > *:first-child { + margin-right: var(--s0); + } +`; + +export const FeeGroup = styled.div` + display: flex; + align-items: center; + flex-wrap: wrap; + + & > *:first-child { + margin-right: var(--s0); + } +`; diff --git a/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/FormOpenText/index.tsx b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/FormOpenText/index.tsx new file mode 100644 index 00000000..bd4b3a17 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/FormOpenText/index.tsx @@ -0,0 +1,62 @@ +import BackButtonOrLink from "App/components/BackButtonOrLink"; +import Button from "App/components/Button"; +import Field from "App/components/Field"; +import { Formik } from "formik"; +import { Form } from "formik-antd"; +import { getFormItemName } from "utils/forms"; +import * as Yup from "yup"; + +import { ButtonGroup, FormStack, Separator } from "./style"; + +const textLabel = "Text"; + +const validationSchema = Yup.object().shape({ + [getFormItemName(textLabel)]: Yup.string() + .typeError("Text must be alphanumeric") + .required("Text is required") + .min(10, "Text length should be between 10 and 500 characters") + .max(500, "Text length should be between 10 and 500 characters"), +}); + +export interface FormOpenTextValues { + readonly text: string; +} + +interface FormOpenTextProps extends FormOpenTextValues { + readonly goBack: () => void; + readonly handleSubmit: (values: FormOpenTextValues) => void; +} + +export default function FormOpenText({ text, goBack, handleSubmit }: FormOpenTextProps): JSX.Element { + return ( + + handleSubmit({ + text: values[getFormItemName(textLabel)], + }) + } + > + {({ isValid, submitForm }) => ( + <> +
+ + + + + goBack()} text="Back" /> + + + +
+ + )} +
+ ); +} diff --git a/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/FormOpenText/style.ts b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/FormOpenText/style.ts new file mode 100644 index 00000000..77606f57 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/components/FormOpenText/style.ts @@ -0,0 +1,28 @@ +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FormStack = styled(Stack)` + & .ant-input-textarea { + flex-basis: 100%; + } + + & .ant-form-item-has-error .ant-input-textarea::after { + color: var(--color-error-form); + } +`; + +export const ButtonGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + button:first-child { + margin-right: var(--s0); + } +`; diff --git a/src/App/components/ApCreateProposalModal/components/ProposalOpenText/index.tsx b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/index.tsx new file mode 100644 index 00000000..ef6f1678 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/index.tsx @@ -0,0 +1,72 @@ +import { TxResult } from "App/components/ShowTxResult"; +import { useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContract } from "utils/arbiterPool"; +import { getErrorFromStackTrace } from "utils/errors"; + +import { ProposalStep, ProposalType } from "../.."; +import ConfirmationOpenText from "./components/ConfirmationOpenText"; +import FormOpenText, { FormOpenTextValues } from "./components/FormOpenText"; + +interface ProposalOpenTextProps { + readonly proposalStep: ProposalStep; + readonly setProposalStep: React.Dispatch>; + readonly isSubmitting: boolean; + readonly setSubmitting: React.Dispatch>; + readonly setTxResult: React.Dispatch>; +} + +export default function ProposalOpenText({ + proposalStep, + setProposalStep, + isSubmitting, + setSubmitting, + setTxResult, +}: ProposalOpenTextProps): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { address, signingClient, config }, + } = useSdk(); + + const [text, setText] = useState(""); + + async function submitOpenText({ text }: FormOpenTextValues) { + setText(text); + setProposalStep({ type: ProposalType.OpenText, confirmation: true }); + } + + async function submitCreateProposal() { + if (!signingClient || !address) return; + setSubmitting(true); + + try { + const ocContract = new ApContract(config, signingClient); + const { txHash } = await ocContract.propose(address, text, { text: {} }); + + setTxResult({ + msg: `Created proposal for Open Text from Arbiter Pool Proposals. Transaction ID: ${txHash}`, + }); + } catch (error) { + if (!(error instanceof Error)) return; + setTxResult({ error: getErrorFromStackTrace(error) }); + handleError(error); + } finally { + setSubmitting(false); + } + } + + return ( + <> + {proposalStep.confirmation ? ( + setProposalStep({ type: ProposalType.OpenText })} + submitForm={submitCreateProposal} + /> + ) : ( + setProposalStep(undefined)} handleSubmit={submitOpenText} /> + )} + + ); +} diff --git a/src/App/components/ApCreateProposalModal/components/ProposalOpenText/style.ts b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/style.ts new file mode 100644 index 00000000..535a1178 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ProposalOpenText/style.ts @@ -0,0 +1,53 @@ +import { Modal } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + align-items: center; + justify-content: space-between; + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & img { + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateProposalModal/components/SelectProposal/index.tsx b/src/App/components/ApCreateProposalModal/components/SelectProposal/index.tsx new file mode 100644 index 00000000..dd76d52e --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/SelectProposal/index.tsx @@ -0,0 +1,44 @@ +import { Typography } from "antd"; +import { SelectValue } from "antd/lib/select"; +import { ReactComponent as DownArrow } from "App/assets/icons/down-arrow.svg"; +import Button from "App/components/Button"; +import Select from "App/components/Select"; +import * as React from "react"; +import { useState } from "react"; + +import { proposalLabels, ProposalStep, ProposalType } from "../.."; +import { ProposalStack, Separator, StyledSelect } from "./style"; + +const { Option } = Select; +const { Text } = Typography; + +interface SelectProposalProps { + readonly setProposalStep: React.Dispatch>; +} + +export default function SelectProposal({ setProposalStep }: SelectProposalProps): JSX.Element { + const [selectedProposal, setSelectedProposal] = useState(ProposalType.OpenText); + + return ( + <> + + Proposal + } + defaultActiveFirstOption + size="large" + value={selectedProposal} + onChange={(proposalType: SelectValue) => setSelectedProposal(proposalType as ProposalType)} + > + {Object.values(ProposalType).map((proposalType) => ( + + ))} + + + + + + ); +} diff --git a/src/App/components/ApCreateProposalModal/components/SelectProposal/style.ts b/src/App/components/ApCreateProposalModal/components/SelectProposal/style.ts new file mode 100644 index 00000000..88f23bb3 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/SelectProposal/style.ts @@ -0,0 +1,38 @@ +import Select from "App/components/Select"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const ProposalStack = styled(Stack)` + & span.ant-typography { + font-size: var(--s0); + color: var(--color-text-1ary); + } + + & .ant-select { + align-self: flex-start; + width: 100%; + max-width: 22rem; + } +`; + +export const StyledSelect = styled(Select)` + .ant-select-arrow { + color: #8692a6; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateProposalModal/components/ShowTxResultProposal/index.tsx b/src/App/components/ApCreateProposalModal/components/ShowTxResultProposal/index.tsx new file mode 100644 index 00000000..bec9bfd5 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ShowTxResultProposal/index.tsx @@ -0,0 +1,28 @@ +import Button from "App/components/Button"; +import ShowTxResult, { TxResult } from "App/components/ShowTxResult"; + +interface ShowTxResultProposalProps { + readonly txResult: TxResult; + readonly setTxResult: React.Dispatch>; + readonly tryAgain: () => void; + readonly resetModal: () => void; +} + +export default function ShowTxResultProposal({ + txResult, + tryAgain, + resetModal, +}: ShowTxResultProposalProps): JSX.Element { + return ( + + {txResult.error ? ( + + ) : null} + + + ); +} diff --git a/src/App/components/ApCreateProposalModal/components/ShowTxResultProposal/style.ts b/src/App/components/ApCreateProposalModal/components/ShowTxResultProposal/style.ts new file mode 100644 index 00000000..535a1178 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/components/ShowTxResultProposal/style.ts @@ -0,0 +1,53 @@ +import { Modal } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + align-items: center; + justify-content: space-between; + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & img { + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApCreateProposalModal/index.tsx b/src/App/components/ApCreateProposalModal/index.tsx new file mode 100644 index 00000000..8218f036 --- /dev/null +++ b/src/App/components/ApCreateProposalModal/index.tsx @@ -0,0 +1,131 @@ +import { Typography } from "antd"; +import closeIcon from "App/assets/icons/cross.svg"; +import { TxResult } from "App/components/ShowTxResult"; +import Stack from "App/components/Stack/style"; +import Steps from "App/components/Steps"; +import { lazy, useState } from "react"; + +import SelectProposal from "./components/SelectProposal"; +import ShowTxResultProposal from "./components/ShowTxResultProposal"; +import { ModalHeader, Separator, StyledModal } from "./style"; + +const ProposalOpenText = lazy(() => import("./components/ProposalOpenText")); + +const { Title, Text } = Typography; +const { Step } = Steps; + +export enum ProposalType { + OpenText = "open-text", +} + +export const proposalLabels = { + [ProposalType.OpenText]: "Open text proposal", +}; + +export const proposalTitles = { + newProposal: "New proposal", + ...proposalLabels, + confirmation: "Confirmation", +}; + +export type ProposalStep = { type: ProposalType; confirmation?: true }; + +function getTitleFromStep(step?: ProposalStep): string { + return step?.confirmation + ? proposalTitles.confirmation + : step + ? proposalTitles[step.type] + : proposalTitles.newProposal; +} + +function getCurrentStepIndex(step?: ProposalStep): number { + return step?.confirmation ? 2 : step?.type ? 1 : 0; +} + +interface APoolCreateProposalModalProps { + readonly isModalOpen: boolean; + readonly closeModal: () => void; + readonly refreshProposals: () => void; +} + +export default function APoolCreateProposalModal({ + isModalOpen, + closeModal, + refreshProposals, +}: APoolCreateProposalModalProps): JSX.Element { + const [proposalStep, setProposalStep] = useState(); + const [isSubmitting, setSubmitting] = useState(false); + const [txResult, setTxResult] = useState(); + + function tryAgain() { + setProposalStep(proposalStep ? { type: proposalStep.type } : undefined); + setTxResult(undefined); + } + + function resetModal() { + closeModal(); + setProposalStep(undefined); + setSubmitting(false); + setTxResult(undefined); + refreshProposals(); + } + + return ( + + {txResult ? ( + + ) : ( + + + + {getTitleFromStep(proposalStep)} + Community Pool + + + + + + + {!isSubmitting ? Close button closeModal()} /> : null} + + + {!proposalStep ? ( + + ) : proposalStep.type === ProposalType.OpenText ? ( + + ) : null} + + )} + + ); +} diff --git a/src/App/components/ApCreateProposalModal/style.ts b/src/App/components/ApCreateProposalModal/style.ts new file mode 100644 index 00000000..4774277a --- /dev/null +++ b/src/App/components/ApCreateProposalModal/style.ts @@ -0,0 +1,65 @@ +import { Modal } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + & .ant-modal-content { + border-radius: 16px; + } + + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; + + & .ant-btn { + align-self: flex-end; + } +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + flex-wrap: wrap; + align-items: flex-start; + justify-content: space-between; + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & img { + position: absolute; + top: 0; + right: -40px; + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled.hr` + margin: 0 -20px 0 -20px; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const FieldGroup = styled.div` + display: flex; + justify-content: space-between; + flex-wrap: wrap; + + & .ant-form-item { + flex-basis: 18rem; + } +`; diff --git a/src/App/components/ApDetail/index.tsx b/src/App/components/ApDetail/index.tsx new file mode 100644 index 00000000..9436d4cc --- /dev/null +++ b/src/App/components/ApDetail/index.tsx @@ -0,0 +1,321 @@ +import { Typography } from "antd"; +import pendingIcon from "App/assets/icons/clock.svg"; +import rejectedIcon from "App/assets/icons/cross.svg"; +import passedIcon from "App/assets/icons/tick.svg"; +import ButtonAddNew from "App/components/ButtonAddNew"; +import { lazy, useCallback, useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { + ApContractQuerier, + Complaint, + ComplaintState, + Cw3Status, + getProposalTitle, + ProposalResponse, +} from "utils/arbiterPool"; + +import ApVotingRules from "../ApVotingRules"; +import Stack from "../Stack/style"; +import { + ProposalsContainer as ComplaintsContainer, + ProposalsContainer, + StatusBlock, + StatusParagraph, +} from "./style"; + +const ApCreateProposalModal = lazy(() => import("App/components/ApCreateProposalModal")); +const ApCreateComplaintModal = lazy(() => import("App/components/ApCreateComplaintModal")); +const ApProposalDetailModal = lazy(() => import("App/components/ApProposalDetailModal")); +const ApComplaintDetailModal = lazy(() => import("App/components/ApComplaintDetailModal")); +const ArbiterPoolIdActions = lazy(() => import("App/components/ApIdActions")); +const Table = lazy(() => import("App/components/Table")); + +const { Title, Paragraph } = Typography; + +function getImgSrcFromStatus(status: Cw3Status) { + switch (status) { + case "executed": + case "passed": + return { src: passedIcon }; + case "rejected": + return { src: rejectedIcon }; + default: + return { src: pendingIcon }; + } +} + +const proposalColumns = [ + { + title: "NÂș", + dataIndex: "id", + key: "id", + width: "5%", + sorter: (a: ProposalResponse, b: ProposalResponse) => a.id - b.id, + }, + { + title: "Type", + key: "title", + width: "25%", + render: (record: ProposalResponse) => getProposalTitle(record.proposal), + }, + { + title: "Description", + key: "description", + width: "45%", + render: (record: ProposalResponse) => {record.description}, + }, + { + title: "Due date", + key: "expires", + width: "10%", + render: (record: ProposalResponse) => { + const expiryTime = + Number(typeof record.expires === "string" ? record.expires : record.expires.at_time) / 1000000; + const formatedDate = new Date(expiryTime).toLocaleDateString(); + const formatedTime = new Date(expiryTime).toLocaleTimeString(); + return ( + <> +
{formatedDate}
+
{formatedTime}
+ + ); + }, + sorter: (a: ProposalResponse, b: ProposalResponse) => { + const aExpiryTime = Number(typeof a.expires === "string" ? a.expires : a.expires.at_time) / 1000000; + const bExpiryTime = Number(typeof b.expires === "string" ? b.expires : b.expires.at_time) / 1000000; + return bExpiryTime - aExpiryTime; + }, + defaultSortOrder: "ascend", + }, + { + title: "Status", + key: "status", + width: "10%", + render: (record: ProposalResponse) => ( + + + + {record.status.charAt(0).toUpperCase() + record.status.slice(1)} + + Yes: {record.votes.yes ?? 0} + No: {record.votes.no ?? 0} + Abstained: {record.votes.abstain ?? 0} + + ), + sorter: (a: ProposalResponse, b: ProposalResponse) => { + function getSortNumFromStatus(status: Cw3Status): number { + switch (status) { + case "executed": + return 1; + case "passed": + return 2; + case "rejected": + return 3; + default: + return 4; + } + } + + return getSortNumFromStatus(b.status) - getSortNumFromStatus(a.status); + }, + }, + { + title: "Results", + key: "results", + width: "35%", + }, +]; + +const complaintColumns = [ + { + title: "NÂș", + dataIndex: "complaint_id", + key: "complaint_id", + width: "5%", + sorter: (a: Complaint, b: Complaint) => a.complaint_id - b.complaint_id, + }, + { + title: "Title", + key: "title", + width: "25%", + }, + { + title: "Defendant", + key: "defendant", + width: "10%", + }, + { + title: "Plaintiff", + key: "plaintiff", + width: "10%", + }, + { + title: "Description", + key: "description", + width: "45%", + render: (record: Complaint) => {record.description}, + }, + { + title: "State", + key: "state", + width: "10%", + render: (record: Complaint) => { + const state = Object.keys(record.state)[0]; + const capitalizedState = state.charAt(0).toUpperCase() + state.slice(1); + return capitalizedState; + }, + sorter: (a: Complaint, b: Complaint) => { + function getSortNumFromState(state: ComplaintState): number { + switch (state) { + case "waiting": + return 1; + case "initiated": + return 2; + case "processing": + return 3; + case "accepted": + return 4; + case "closed": + return 5; + case "aborted": + return 6; + default: + return 7; + } + } + + return getSortNumFromState(b.state) - getSortNumFromState(a.state); + }, + }, +]; + +export default function ArbiterPoolDetail(): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { config, client, address }, + } = useSdk(); + + const [isProposalsTableLoading, setProposalsTableLoading] = useState(true); + const [isComplaintsTableLoading, setComplaintsTableLoading] = useState(true); + const [isCreateProposalModalOpen, setCreateProposalModalOpen] = useState(false); + const [isCreateComplaintModalOpen, setCreateComplaintModalOpen] = useState(false); + + const [proposals, setProposals] = useState([]); + const [complaints, setComplaints] = useState([]); + const [clickedProposal, setClickedProposal] = useState(); + const [clickedComplaint, setClickedComplaint] = useState(); + const [isVotingMember, setVotingMember] = useState(false); + + const refreshProposals = useCallback(async () => { + if (!client) return; + + try { + const apContract = new ApContractQuerier(config, client); + const proposals = await apContract.getAllProposals(); + setProposals(proposals); + + const isVotingMember = (await apContract.getAllVoters()).some((member) => member.addr === address); + setVotingMember(isVotingMember); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } finally { + setProposalsTableLoading(false); + } + }, [address, client, config, handleError]); + + const refreshComplaints = useCallback(async () => { + if (!client) return; + + try { + const apContract = new ApContractQuerier(config, client); + const complaints = await apContract.getAllComplaints(); + setComplaints(complaints); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } finally { + setComplaintsTableLoading(false); + } + }, [client, config, handleError]); + + useEffect(() => { + refreshProposals(); + refreshComplaints(); + }, [refreshComplaints, refreshProposals]); + + return ( + <> + + + + +
+ + Proposals + + {isVotingMember && ( + setCreateProposalModalOpen(true)} /> + )} +
+ record.id} + onRow={(record: ProposalResponse) => ({ + onClick: () => setClickedProposal(record.id), + })} + /> + + +
+ + Complaints + + setCreateComplaintModalOpen(true)} /> +
+
record.complaint_id} + onRow={(record: Complaint) => ({ + onClick: () => setClickedComplaint(record.complaint_id), + })} + /> + + + setCreateProposalModalOpen(false)} + refreshProposals={refreshProposals} + /> + {/* TODO NÂș1: Implement this component. It should be a form that allows ApContract.registerComplaint() */} + setCreateComplaintModalOpen(false)} + refreshComplaints={refreshComplaints} + /> + setClickedProposal(undefined)} + proposalId={clickedProposal} + refreshProposals={refreshProposals} + /> + {/* TODO NÂș2: Implement this component. It should be a form that shows Complaint details and allows: + - ApContract.acceptComplaint() + - ApContract.withdrawComplaint() + - ApContract.renderDecision() + */} + setClickedComplaint(undefined)} + proposalId={clickedComplaint} + refreshComplaints={refreshComplaints} + /> + + ); +} diff --git a/src/App/components/ApDetail/style.ts b/src/App/components/ApDetail/style.ts new file mode 100644 index 00000000..eea5b7e3 --- /dev/null +++ b/src/App/components/ApDetail/style.ts @@ -0,0 +1,76 @@ +import { Typography } from "antd"; +import styled from "styled-components"; + +const { Paragraph } = Typography; + +export const EscrowEngagementContainer = styled.div` + display: grid; + grid-template-columns: 1fr 1fr; + gap: var(--s0); +`; + +export const ProposalsContainer = styled.div` + border: 1px solid var(--color-border); + border-radius: var(--border-radius); + background-color: white; + + & header { + padding: var(--s1); + display: flex; + align-items: baseline; + justify-content: space-between; + } + + & table { + border-top: 1px solid var(--color-border); + color: var(--color-text-1ary); + font-size: var(--s-1); + font-family: var(--ff-text); + } + + & .ant-table-row { + cursor: pointer; + } + + & .ant-table-cell { + max-width: 20rem; + } + + & .ant-table-thead .ant-table-cell { + color: var(--color-text-2ary); + font-size: var(--s0); + } + + & div.ant-typography { + color: var(--color-text-1ary); + font-size: var(--s-1); + } +`; + +export const StatusBlock = styled.div` + text-align: right; +`; + +export const StatusParagraph = styled(Paragraph)<{ readonly status: string }>` + display: flex; + align-items: center; + justify-content: flex-end; + + img { + margin-right: 3px; + } + + &&.ant-typography { + color: ${({ status }) => { + switch (status) { + case "executed": + case "passed": + return "var(--color-result-success)"; + case "rejected": + return "var(--color-result-failure)"; + default: + return "var(--color-warning)"; + } + }}; + } +`; diff --git a/src/App/components/ApIdActions/index.tsx b/src/App/components/ApIdActions/index.tsx new file mode 100644 index 00000000..3894ed7d --- /dev/null +++ b/src/App/components/ApIdActions/index.tsx @@ -0,0 +1,35 @@ +import { Dropdown, Menu } from "antd"; +import gearIcon from "App/assets/icons/gear.svg"; +import AddressTag from "App/components/AddressTag"; +import { openLeaveOcModal, useOc } from "service"; + +import { ActionsButton, StyledOcIdActions } from "./style"; + +export default function ApIdActions(): JSX.Element { + const { + ocState: { ocAddress }, + ocDispatch, + } = useOc(); + + return ( + +
+
+ + + openLeaveOcModal(ocDispatch)}> + Leave Oversight Community + + + } + trigger={["click"]} + > + + +
+
+
+ ); +} diff --git a/src/App/components/ApIdActions/style.ts b/src/App/components/ApIdActions/style.ts new file mode 100644 index 00000000..a712afee --- /dev/null +++ b/src/App/components/ApIdActions/style.ts @@ -0,0 +1,65 @@ +import styled from "styled-components"; + +export const StyledOcIdActions = styled.div` + border: 1px solid var(--color-border); + border-radius: var(--border-radius); + background-color: white; + + h1.ant-typography { + font-size: var(--s1); + } + + img[alt="Actions button"] { + height: 20px; + } + + header { + padding: var(--s1); + display: flex; + align-items: center; + justify-content: space-between; + } + + & .address-actions-container { + display: flex; + + & > * { + margin: 0; + } + + & > * + * { + margin-left: var(--s1); + } + } +`; + +export const VotingRules = styled.div` + display: flex; + flex-direction: row; + + & span.ant-typography { + padding: var(--s-1) var(--s1); + color: var(--color-text-1ary); + font-size: 13px; + + &:first-child { + padding-right: 0; + font-weight: 600; + } + } +`; + +export const Separator = styled.hr` + margin: 0; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const VSeparator = styled.div` + border: none; + border-left: 1px solid var(--color-input-border); +`; + +export const ActionsButton = styled.img` + cursor: pointer; +`; diff --git a/src/App/components/ApMembers/index.tsx b/src/App/components/ApMembers/index.tsx new file mode 100644 index 00000000..cb6cbb8b --- /dev/null +++ b/src/App/components/ApMembers/index.tsx @@ -0,0 +1,85 @@ +import { Typography } from "antd"; +import { useEffect, useState } from "react"; +import { useError, useSdk } from "service"; + +//import { ApContractQuerier, EscrowResponse, EscrowStatus, MemberStatus } from "utils/arbiterPool"; +import { MemberCount, MemberCounts, MembersStack } from "./style"; + +const { Title, Text } = Typography; + +export default function ApMembers(): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { client, config, address }, + } = useSdk(); + const [numVoters, setNumVoters] = useState(0); + //const [membership, setMembership] = useState(); + + /* useEffect(() => { + (async function updateNumMembers() { + if (!client) return; + + try { + const ApContract = new ApContractQuerier(config, client); + const members = await ApContract.getAllVoters(); + + const memberEscrowPromises = members.map(({ addr }) => ApContract.getEscrow(addr)); + const memberEscrowResults = await Promise.allSettled(memberEscrowPromises); + const memberEscrowStatuses = memberEscrowResults + .filter((res): res is PromiseFulfilledResult => res.status === "fulfilled") + .filter((res): res is PromiseFulfilledResult => res.value !== null) + .map((res) => res.value); + + let numVoters = 0; + for (const escrow of memberEscrowStatuses) { + if (escrow.status.voting) { + ++numVoters; + } + } + + setNumVoters(numVoters); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [client, config, handleError]);*/ + + /* useEffect(() => { + (async function queryMembership() { + if (!client || !address) return; + + try { + const dsoContract = new ApContractQuerier(config, client); + const escrowResponse = await dsoContract.getEscrow(address); + + if (escrowResponse) { + setMembership(escrowResponse.status); + } else { + setMembership(undefined); + } + } catch (error) { + if (!(error instanceof Error)) return; + //handleError(error); + } + })(); + }, [address, client]);*/ + + return ( + + Member(s) + {/* {membership?.leaving ? You are in the process of leaving this Trusted Circle : null} + {membership?.pending ? ( + You need to deposit the required escrow to gain voting rights + ) : null} + {membership?.pending_paid ? You will become a voting member soon : null}*/} + + + {numVoters} + voting member(s) + {/* {membership?.voting ? (you) : null}*/} + + + + ); +} diff --git a/src/App/components/ApMembers/style.ts b/src/App/components/ApMembers/style.ts new file mode 100644 index 00000000..1d3db74e --- /dev/null +++ b/src/App/components/ApMembers/style.ts @@ -0,0 +1,51 @@ +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const MembersStack = styled(Stack)` + padding: var(--s1); + border: 1px solid var(--color-border); + border-radius: var(--border-radius); + background-color: white; + text-align: left; + + h2.ant-typography { + font-size: var(--s0); + } +`; + +export const MemberCounts = styled.div` + flex-grow: 1; + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-evenly; + gap: var(--s0); +`; + +export const MemberCount = styled.div` + padding: var(--s1); + display: flex; + flex-direction: column; + align-items: center; + flex-basis: 14rem; + min-height: 10rem; + border: 1px solid var(--color-border); + border-radius: var(--border-radius); + + &:first-child span.ant-typography:first-child { + color: var(--color-primary); + } + + span.ant-typography { + font-size: var(--s-1); + } + + span.ant-typography:first-child { + font-size: var(--s5); + font-weight: 500; + } + + span.ant-typography:nth-child(2) { + color: var(--color-text-1ary); + } +`; diff --git a/src/App/components/ApProposalDetailModal/components/ProposalAddOCMembers.tsx b/src/App/components/ApProposalDetailModal/components/ProposalAddOCMembers.tsx new file mode 100644 index 00000000..80ac2cee --- /dev/null +++ b/src/App/components/ApProposalDetailModal/components/ProposalAddOCMembers.tsx @@ -0,0 +1,18 @@ +import AddressList from "App/components/AddressList"; + +import { TextValue } from "../style"; + +interface ProposalAddOCMembersProps { + readonly proposalAddVotingMembers: readonly string[] | undefined; +} + +export default function ProposalAddOCMembers({ + proposalAddVotingMembers, +}: ProposalAddOCMembersProps): JSX.Element | null { + return proposalAddVotingMembers?.length ? ( + <> + Members to be added: + + + ) : null; +} diff --git a/src/App/components/ApProposalDetailModal/components/ProposalGrantEngagementPoints.tsx b/src/App/components/ApProposalDetailModal/components/ProposalGrantEngagementPoints.tsx new file mode 100644 index 00000000..fba60529 --- /dev/null +++ b/src/App/components/ApProposalDetailModal/components/ProposalGrantEngagementPoints.tsx @@ -0,0 +1,19 @@ +import AddressTag from "App/components/AddressTag"; +import { Engagement } from "utils/trustedCircle"; + +import { AddressField, TextLabel } from "../style"; + +interface ProposalGrantEngagementPointsProps { + readonly proposalGrantEngagement: Engagement | undefined; +} + +export default function ProposalGrantEngagementPoints({ + proposalGrantEngagement, +}: ProposalGrantEngagementPointsProps): JSX.Element | null { + return proposalGrantEngagement ? ( + + Grant {proposalGrantEngagement.points} Engagement Points to: + + + ) : null; +} diff --git a/src/App/components/ApProposalDetailModal/components/ProposalPunishOCMember.tsx b/src/App/components/ApProposalDetailModal/components/ProposalPunishOCMember.tsx new file mode 100644 index 00000000..946911a1 --- /dev/null +++ b/src/App/components/ApProposalDetailModal/components/ProposalPunishOCMember.tsx @@ -0,0 +1,119 @@ +import { Decimal } from "@cosmjs/math"; +import AddressList from "App/components/AddressList"; +import AddressTag from "App/components/AddressTag"; +import { useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { isValidAddress } from "utils/forms"; +import { OcContractQuerier } from "utils/oversightCommunity"; +import { Punishment } from "utils/trustedCircle"; + +import { AddressField, ChangedField, TextLabel, TextValue } from "../style"; + +interface ProposalPunishOCMemberProps { + readonly proposalPunishVotingMember: Punishment | undefined; +} + +export default function ProposalPunishOCMember({ + proposalPunishVotingMember, +}: ProposalPunishOCMemberProps): JSX.Element | null { + const memberToPunish = + proposalPunishVotingMember?.burn_escrow?.member || proposalPunishVotingMember?.distribute_escrow?.member; + + const kickOutMember = + proposalPunishVotingMember?.burn_escrow?.kick_out || + proposalPunishVotingMember?.distribute_escrow?.kick_out; + + const slashingPercentage = + proposalPunishVotingMember?.burn_escrow?.slashing_percentage || + proposalPunishVotingMember?.distribute_escrow?.slashing_percentage; + + const distributionList = proposalPunishVotingMember?.distribute_escrow?.distribution_list ?? []; + + const { handleError } = useError(); + const { + sdkState: { config, client }, + } = useSdk(); + const feeTokenDenom = config.coinMap[config.feeToken].denom || ""; + + const [memberEscrow, setMemberEscrow] = useState("0"); + const [toSlash, setToSlash] = useState("0"); + + useEffect(() => { + (async function updateMemberEscrow() { + if (!client || !memberToPunish) return; + + if (!isValidAddress(memberToPunish, config.addressPrefix)) { + setMemberEscrow("0"); + return; + } + + const ocContract = new OcContractQuerier(config, client); + + try { + const escrowResponse = await ocContract.getEscrow(memberToPunish); + if (!escrowResponse) throw new Error("No escrow found for user"); + + const decimals = config.coinMap[config.feeToken].fractionalDigits; + const userEscrowDecimal = Decimal.fromAtomics(escrowResponse.paid, decimals); + setMemberEscrow(userEscrowDecimal.toString()); + } catch (error) { + console.error(error); + setMemberEscrow("0"); + } + })(); + }, [client, config, memberToPunish]); + + useEffect(() => { + if (!slashingPercentage) return; + + try { + const slashingPercentageNumber = parseFloat(slashingPercentage); + const toSlash = ( + Decimal.fromUserInput( + memberEscrow, + config.coinMap[config.feeToken].fractionalDigits, + ).toFloatApproximation() * slashingPercentageNumber + ).toString(); + + setToSlash(toSlash); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + }, [config.coinMap, config.feeToken, handleError, memberEscrow, slashingPercentage]); + + if (!memberToPunish) return null; + + return ( + <> + + Member to punish: + + + {kickOutMember !== undefined ? ( + + + {kickOutMember + ? "The member WILL BE kicked out of the Trusted Circle" + : "The member WILL NOT BE kicked out of the Trusted Circle"} + + + ) : null} + {slashingPercentage?.length && slashingPercentage !== "0" ? ( + + {`Escrow to be slashed: ${ + parseFloat(slashingPercentage) * 100 + }% of ${memberEscrow} ${feeTokenDenom} = ${toSlash} ${feeTokenDenom}`} + + ) : null} + {distributionList.length ? ( + <> + The slashed escrow will be distributed to: + + + ) : ( + The slashed escrow will be burned + )} + + ); +} diff --git a/src/App/components/ApProposalDetailModal/components/ProposalPunishValidator.tsx b/src/App/components/ApProposalDetailModal/components/ProposalPunishValidator.tsx new file mode 100644 index 00000000..e01dccb9 --- /dev/null +++ b/src/App/components/ApProposalDetailModal/components/ProposalPunishValidator.tsx @@ -0,0 +1,51 @@ +import AddressTag from "App/components/AddressTag"; +import moment from "moment"; +import { ValidatorPunishment } from "utils/trustedCircle"; + +import { TextLabel } from "../style"; + +interface ProposalPunishValidatorProps { + readonly proposalPunishValidator: ValidatorPunishment | undefined; +} + +const todayDate = Math.round(new Date().getTime() / 1000); +// dateOffset required due to inacuraccy in actual release time +const dateOffset = 43200; + +export default function ProposalPunishValidator({ + proposalPunishValidator, +}: ProposalPunishValidatorProps): JSX.Element | null { + if (!proposalPunishValidator) return null; + + const dateInSeconds = proposalPunishValidator.jailing_duration?.duration + ? todayDate + proposalPunishValidator.jailing_duration.duration + dateOffset + : 0; + + return ( + <> + + Validator To be Punished: + + {proposalPunishValidator.jailing_duration?.forever ? ( + + Validator will be jailed forever + + ) : null} + {proposalPunishValidator.jailing_duration?.duration && + proposalPunishValidator.jailing_duration.duration !== 0 ? ( + + Validator will be jailed until:{" "} + + {moment.unix(dateInSeconds).local().format("DD/MM/YYYY")} + + + ) : null} + {proposalPunishValidator.portion && proposalPunishValidator.portion !== "0" ? ( + + Percentage to slash of funds and Distributed Points:{" "} + {parseFloat(proposalPunishValidator.portion) * 100}% + + ) : null} + + ); +} diff --git a/src/App/components/ApProposalDetailModal/components/ProposalUnjailValidator.tsx b/src/App/components/ApProposalDetailModal/components/ProposalUnjailValidator.tsx new file mode 100644 index 00000000..faa74aa8 --- /dev/null +++ b/src/App/components/ApProposalDetailModal/components/ProposalUnjailValidator.tsx @@ -0,0 +1,22 @@ +import AddressTag from "App/components/AddressTag"; +import { ValidatorUnjail } from "utils/trustedCircle"; + +import { TextLabel } from "../style"; + +interface ProposalUnjailValidatorProps { + readonly proposalUnjailValidator: ValidatorUnjail | undefined; +} + +export default function ProposalUnjailValidator({ + proposalUnjailValidator, +}: ProposalUnjailValidatorProps): JSX.Element | null { + if (!proposalUnjailValidator) return null; + + return ( + <> + + Validator To be Unjailed: + + + ); +} diff --git a/src/App/components/ApProposalDetailModal/index.tsx b/src/App/components/ApProposalDetailModal/index.tsx new file mode 100644 index 00000000..57e9ab86 --- /dev/null +++ b/src/App/components/ApProposalDetailModal/index.tsx @@ -0,0 +1,334 @@ +import { calculateFee, Coin } from "@cosmjs/stargate"; +import { Collapse } from "antd"; +import closeIcon from "App/assets/icons/cross.svg"; +import { ReactComponent as StatusExecutedIcon } from "App/assets/icons/status-executed-icon.svg"; +import { ReactComponent as StatusOpenIcon } from "App/assets/icons/status-open-icon.svg"; +import { ReactComponent as StatusPassedIcon } from "App/assets/icons/status-passed-icon.svg"; +import Button from "App/components/Button"; +import ShowTxResult, { TxResult } from "App/components/ShowTxResult"; +import Stack from "App/components/Stack/style"; +import { useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContract, ApContractQuerier, ProposalResponse, VoteInfo, VoteOption } from "utils/arbiterPool"; +import { getDisplayAmountFromFee } from "utils/currency"; +import { getErrorFromStackTrace } from "utils/errors"; + +import ButtonVote from "../ButtonVote"; +import VotesTable from "../VotesTable"; +import WarningBanner from "../WarningBanner"; +import { + ButtonGroup, + FeeWrapper, + ModalHeader, + Paragraph, + SectionWrapper, + Separator, + StyledCollapse, + StyledModal, + Text, + Title, +} from "./style"; + +interface APoolProposalDetailModalProps { + readonly isModalOpen: boolean; + readonly closeModal: () => void; + readonly proposalId: number | undefined; + readonly refreshProposals: () => void; +} + +export default function APoolProposalDetailModal({ + isModalOpen, + closeModal, + proposalId, + refreshProposals, +}: APoolProposalDetailModalProps): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { config, client, address, signingClient }, + } = useSdk(); + + const [submitting, setSubmitting] = useState(); + const [txResult, setTxResult] = useState(); + const [hasVoted, setHasVoted] = useState(false); + + const [txFee, setTxFee] = useState("0"); + const feeTokenDenom = config.coinMap[config.feeToken].denom || ""; + + const [proposal, setProposal] = useState(); + + const expiryTime = proposal + ? Number(typeof proposal.expires === "string" ? proposal.expires : proposal.expires.at_time) / 1000000 + : 0; + const isProposalNotExpired = expiryTime > Date.now(); + + //const { amount: nativeCoinToSend, to_addr: receiverAddress } = proposal?.proposal.send_proposal ?? {}; + const [isVotingMember, setVotingMember] = useState(false); + const [coinToSend, setCoinToSend] = useState(); + + const [isTableLoading, setTableLoading] = useState(false); + const [votes, setVotes] = useState([]); + useEffect(() => { + (async function queryVotes() { + if (!client || !proposalId) return; + + try { + const tcContract = new ApContractQuerier(config, client); + setTableLoading(true); + const votes = await tcContract.getAllVotes(proposalId); + setVotes(votes); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } finally { + setTableLoading(false); + } + })(); + }, [client, config, handleError, proposalId]); + + useEffect(() => { + if (!signingClient) return; + + try { + const fee = calculateFee(ApContract.GAS_PROPOSE, config.gasPrice); + const txFee = getDisplayAmountFromFee(fee, config); + setTxFee(txFee); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + }, [config, handleError, signingClient]); + + useEffect(() => { + (async function queryProposal() { + if (!client || !proposalId) return; + + try { + const arbiterPoolContractQuerier = new ApContractQuerier(config, client); + const proposal = await arbiterPoolContractQuerier.getProposal(proposalId); + setProposal(proposal); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [client, config, handleError, proposalId]); + + useEffect(() => { + (async function queryVoter() { + if (!address || !client || !proposalId) return; + + try { + const arbiterPoolContractQuerier = new ApContractQuerier(config, client); + const voter = await arbiterPoolContractQuerier.getVote(proposalId, address); + setHasVoted(voter.vote?.voter === address); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [address, client, config, handleError, proposalId]); + + useEffect(() => { + (async function queryMembership() { + if (!client || !address) return; + + try { + const arbiterPoolContractQuerier = new ApContractQuerier(config, client); + const isVotingMember = (await arbiterPoolContractQuerier.getVoters()).some( + (voter) => voter.addr === address, + ); + setVotingMember(isVotingMember); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [address, client, config, handleError]); + + function resetModal() { + closeModal(); + setTxResult(undefined); + refreshProposals(); + } + + async function submitVoteProposal(chosenVote: VoteOption) { + if (!signingClient || !address || !proposalId) return; + setSubmitting(chosenVote); + + try { + const cPoolContract = new ApContract(config, signingClient); + const transactionHash = await cPoolContract.voteProposal(address, proposalId, chosenVote); + + setTxResult({ + msg: `Voted proposal with ID ${proposalId}. Transaction ID: ${transactionHash}`, + }); + } catch (error) { + if (!(error instanceof Error)) return; + setTxResult({ error: getErrorFromStackTrace(error) }); + handleError(error); + } finally { + setSubmitting(undefined); + } + } + + function calculateTotalVotes(): number { + return (proposal?.votes.yes ?? 0) + (proposal?.votes.no ?? 0) + (proposal?.votes.abstain ?? 0); + } + + async function submitExecuteProposal() { + if (!signingClient || !address || !proposalId) return; + setSubmitting("executing"); + + try { + const arbiterPoolContract = new ApContract(config, signingClient); + const transactionHash = await arbiterPoolContract.executeProposal(address, proposalId); + + setTxResult({ + msg: `Executed proposal with ID ${proposalId}. Transaction ID: ${transactionHash}`, + }); + } catch (error) { + if (!(error instanceof Error)) return; + setTxResult({ error: getErrorFromStackTrace(error) }); + handleError(error); + } finally { + setSubmitting(undefined); + } + } + + const canUserVote = + address && + !hasVoted && + isProposalNotExpired && + isVotingMember && + (proposal?.status === "open" || proposal?.status === "passed"); + + return ( + + {txResult ? ( + + {txResult.error ? ( + + ) : null} + + + ) : ( + + + {proposal ? ( +
+ + NÂș {proposal.id} "{proposal.title}" + + {proposal?.status === "passed" ? : null} + {proposal?.status === "open" ? : null} + {proposal?.status === "executed" ? : null} +
+ ) : null} + {!submitting ? Close button resetModal()} /> : null} +
+ + {proposal ? ( + <> + + + + + Progress and results + + + Total voted: + + {calculateTotalVotes()} of {proposal.total_points} + + + + Yes: {proposal.votes.yes ?? 0} + + + No: {proposal.votes.no ?? 0} + + + Abstain: {proposal.votes.abstain ?? 0} + + + + } + > + + + + + + + {address && proposal?.status === "passed" ? ( + + ) : null} + + +

Transaction fee

+

{`~${txFee} ${feeTokenDenom}`}

+
+ submitVoteProposal("yes")} + > + Yes + + submitVoteProposal("no")} + > + No + + submitVoteProposal("abstain")} + > + Abstain + +
+
+ {!isVotingMember ? ( + + ) : null} + + ) : null} +
+ )} +
+ ); +} diff --git a/src/App/components/ApProposalDetailModal/style.ts b/src/App/components/ApProposalDetailModal/style.ts new file mode 100644 index 00000000..d15e8321 --- /dev/null +++ b/src/App/components/ApProposalDetailModal/style.ts @@ -0,0 +1,184 @@ +import { Collapse, Divider, Modal, Typography } from "antd"; +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const StyledModal = styled(Modal)` + & .ant-modal-content { + border-radius: 16px; + } + + ${({ bgTransparent }: { bgTransparent?: boolean }) => + bgTransparent && + ` + & .ant-modal-content { + background: none; + box-shadow: none; + } + `}; +`; + +export const TextLabel = styled(Typography.Text)` + && { + color: var(--color-text-1ary); + font-weight: 500; + } +`; + +export const TextValue = styled(Typography.Text)` + && { + color: var(--color-text-1ary); + white-space: pre-line; + } +`; + +export const AddressField = styled(Typography)` + margin-top: var(--s-1); + display: flex; + + & * + * { + margin-left: var(--s-2); + } +`; + +export const ChangedField = styled(Typography)` + margin-top: var(--s-1); + + & > * { + display: block; + } +`; + +export const FeeGroup = styled.div` + display: flex; + align-items: center; + flex-wrap: wrap; + + & > *:first-child { + margin-right: var(--s0); + } +`; + +export const Title = styled(Typography.Title)` + &.ant-typography { + color: #000; + font-weight: 500; + font-size: 30px; + } +`; + +export const Paragraph = styled.p` + margin-left: 50px; + & b { + margin-left: 5px; + } +`; + +export const Text = styled(Typography.Text)` + &.ant-typography { + color: #000; + font-weight: 500; + } +`; + +export const FormStack = styled(Stack)` + & .ant-btn { + align-self: flex-end; + } +`; + +export const ModalHeader = styled.header` + display: flex; + flex-direction: column; + flex-wrap: wrap; + align-items: flex-start; + justify-content: space-between; + + & div { + width: 100%; + display: flex; + align-items: center; + justify-content: space-between; + } + + & h1 { + font-size: var(--s3); + font-weight: 500; + line-height: 2.35rem; + } + + & span.ant-typography { + line-height: 28px; + color: #8692a6; + } + + & img { + position: absolute; + top: 0; + right: -40px; + cursor: pointer; + height: 1.25rem; + } +`; + +export const Separator = styled(Divider)` + margin: 2px; +`; + +export const SectionWrapper = styled.div` + display: flex; + align-items: center; + justify-content: space-between; +`; + +export const FeeWrapper = styled.div` + display: flex; + flex-direction: column; + margin-right: 10px; + align-items: flex-end; + min-width: 100px; +`; + +export const ParticipantsWrapper = styled.div` + display: flex; + flex-direction: column; + & p { + margin: 0; + } +`; + +export const ButtonGroup = styled.div` + margin-left: auto; + display: flex; + height: 82px; + align-items: center; + + & button { + height: 42px; + flex-basis: calc(50% - calc(var(--s1) / 2)); + } + + & button + button { + margin-left: var(--s1); + } + + & .ant-btn { + } +`; + +export const StyledCollapse = styled(Collapse)` + flex-basis: 100%; + + &.ant-collapse > .ant-collapse-item > .ant-collapse-header { + padding: 0; + display: flex; + align-items: center; + + & > div { + flex-basis: 100%; + } + } + + & .ant-collapse-content > .ant-collapse-content-box { + padding: 0; + } +`; diff --git a/src/App/components/ApVotingRules/index.tsx b/src/App/components/ApVotingRules/index.tsx new file mode 100644 index 00000000..70d3f899 --- /dev/null +++ b/src/App/components/ApVotingRules/index.tsx @@ -0,0 +1,59 @@ +import { Typography } from "antd"; +import { useEffect, useState } from "react"; +import { useError, useSdk } from "service"; +import { ApContractQuerier } from "utils/arbiterPool"; + +import { VotingRules, VSeparator } from "./style"; + +const { Text } = Typography; + +export default function ApVotingRules(): JSX.Element { + const { handleError } = useError(); + const { + sdkState: { config, client }, + } = useSdk(); + + const [quorum, setQuorum] = useState(); + const [threshold, setThreshold] = useState(); + const [votingDuration, setVotingDuration] = useState(); + const [allowEndEarly, setAllowEndEarly] = useState(); + + useEffect(() => { + (async function queryVotingRules() { + if (!client) return; + + try { + const apContract = new ApContractQuerier(config, client); + /* const apResponse = await apContract.getOc(); + const quorum = (parseFloat(apResponse.rules.quorum) * 100).toFixed(2).toString(); + const threshold = (parseFloat(apResponse.rules.threshold) * 100).toFixed(2).toString(); + const allowEndEarly = apResponse.rules.allow_end_early ? "Yes" : "No";*/ + + setQuorum(quorum); + setQuorum(quorum); + setThreshold(threshold); + //setVotingDuration(apResponse.rules.voting_period.toString()); + setAllowEndEarly(allowEndEarly); + } catch (error) { + if (!(error instanceof Error)) return; + handleError(error); + } + })(); + }, [client, config, handleError]); + + return ( + <> + + Voting rules: + Quorum: {quorum}% + + Threshold: {threshold}% + + Voting duration: {votingDuration} days + + Early passing: {allowEndEarly} + + + + ); +} diff --git a/src/App/components/ApVotingRules/style.ts b/src/App/components/ApVotingRules/style.ts new file mode 100644 index 00000000..a712afee --- /dev/null +++ b/src/App/components/ApVotingRules/style.ts @@ -0,0 +1,65 @@ +import styled from "styled-components"; + +export const StyledOcIdActions = styled.div` + border: 1px solid var(--color-border); + border-radius: var(--border-radius); + background-color: white; + + h1.ant-typography { + font-size: var(--s1); + } + + img[alt="Actions button"] { + height: 20px; + } + + header { + padding: var(--s1); + display: flex; + align-items: center; + justify-content: space-between; + } + + & .address-actions-container { + display: flex; + + & > * { + margin: 0; + } + + & > * + * { + margin-left: var(--s1); + } + } +`; + +export const VotingRules = styled.div` + display: flex; + flex-direction: row; + + & span.ant-typography { + padding: var(--s-1) var(--s1); + color: var(--color-text-1ary); + font-size: 13px; + + &:first-child { + padding-right: 0; + font-weight: 600; + } + } +`; + +export const Separator = styled.hr` + margin: 0; + border: none; + border-top: 1px solid var(--color-input-border); +`; + +export const VSeparator = styled.div` + border: none; + border-left: 1px solid var(--color-input-border); +`; + +export const ActionsButton = styled.img` + cursor: pointer; +`; diff --git a/src/App/components/NavSidebar/index.tsx b/src/App/components/NavSidebar/index.tsx index 6828f4f0..b212437d 100644 --- a/src/App/components/NavSidebar/index.tsx +++ b/src/App/components/NavSidebar/index.tsx @@ -75,6 +75,13 @@ export const NavSidebar: React.FC = () => { + + + + Arbiter Pool + + + diff --git a/src/App/index.tsx b/src/App/index.tsx index 56ba6a87..d557ee76 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -16,6 +16,7 @@ import TokensProvider from "service/tokens"; import ErrorFallback from "./components/ErrorFallback"; import { InformationMessage } from "./components/InformationMessage/style"; import LoadingSpinner from "./components/LoadingSpinner"; +import ApHome from "./pages/ApHome"; import CPoolHome from "./pages/CPoolHome"; import DocumentationPage from "./pages/DocumentationPage"; import ValidatorsHome from "./pages/ValidatorsHome"; @@ -65,6 +66,9 @@ export default function App(): JSX.Element { + + + diff --git a/src/App/pages/ApHome/index.tsx b/src/App/pages/ApHome/index.tsx new file mode 100644 index 00000000..23de0136 --- /dev/null +++ b/src/App/pages/ApHome/index.tsx @@ -0,0 +1,22 @@ +import { Typography } from "antd"; +import PageLayout from "App/components/PageLayout"; +import Stack from "App/components/Stack/style"; +import { lazy } from "react"; + +import { TextStack } from "./style"; + +const ArbiterPoolDetail = lazy(() => import("App/components/ApDetail")); +const { Title } = Typography; + +export default function ApHome(): JSX.Element | null { + return ( + + + + Arbiter Pool + + + + + ); +} diff --git a/src/App/pages/ApHome/style.ts b/src/App/pages/ApHome/style.ts new file mode 100644 index 00000000..ccf418c9 --- /dev/null +++ b/src/App/pages/ApHome/style.ts @@ -0,0 +1,12 @@ +import Stack from "App/components/Stack/style"; +import styled from "styled-components"; + +export const TextStack = styled(Stack)` + align-self: flex-start; + max-width: 80ch; + align-items: flex-start; + + & .ant-typography { + text-align: left; + } +`; diff --git a/src/App/paths.ts b/src/App/paths.ts index 6d698a86..6d5d0e2d 100644 --- a/src/App/paths.ts +++ b/src/App/paths.ts @@ -26,6 +26,9 @@ export const paths = { engagement: { prefix: "/engagement", }, + arbiterpool: { + prefix: "/arbiterpool", + }, validators: { prefix: "/validators", }, diff --git a/src/__tests__/integration/in-development/arbiterPool.test.ts b/src/__tests__/integration/in-development/arbiterPool.test.ts new file mode 100644 index 00000000..311e1b5b --- /dev/null +++ b/src/__tests__/integration/in-development/arbiterPool.test.ts @@ -0,0 +1,27 @@ +xdescribe("Arbiter Pool", () => { + it("Creates with new Dispute", () => { + // TODO + }); + + it("Add Arbiter Pool member(s) to hear dispute", () => { + // TODO + }); + + it("Remove Arbiter Pool member(s) from a dispute", () => { + // TODO + }); + + it("Create proposal `Add member(s)`", () => { + // TODO + }); + + it("Create proposal `Remove member(s)`", () => { + // TODO + }); + + it("Create proposal `Open Text Proposal`", () => { + // TODO + }); +}); + +export {}; diff --git a/src/codec/confio/poe/v1beta1/poe.ts b/src/codec/confio/poe/v1beta1/poe.ts index d14ee59b..4731c5d5 100644 --- a/src/codec/confio/poe/v1beta1/poe.ts +++ b/src/codec/confio/poe/v1beta1/poe.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; import { Coin } from "../../../cosmos/base/v1beta1/coin"; export const protobufPackage = "confio.poe.v1beta1"; @@ -17,6 +17,8 @@ export enum PoEContractType { OVERSIGHT_COMMUNITY_PROPOSALS = 7, COMMUNITY_POOL = 8, VALIDATOR_VOTING = 9, + ARBITER_POOL = 10, + ARBITER_POOL_VOTING = 11, UNRECOGNIZED = -1, } @@ -52,6 +54,12 @@ export function poEContractTypeFromJSON(object: any): PoEContractType { case 9: case "VALIDATOR_VOTING": return PoEContractType.VALIDATOR_VOTING; + case 10: + case "ARBITER_POOL": + return PoEContractType.ARBITER_POOL; + case 11: + case "ARBITER_POOL_VOTING": + return PoEContractType.ARBITER_POOL_VOTING; case -1: case "UNRECOGNIZED": default: @@ -81,6 +89,10 @@ export function poEContractTypeToJSON(object: PoEContractType): string { return "COMMUNITY_POOL"; case PoEContractType.VALIDATOR_VOTING: return "VALIDATOR_VOTING"; + case PoEContractType.ARBITER_POOL: + return "ARBITER_POOL"; + case PoEContractType.ARBITER_POOL_VOTING: + return "ARBITER_POOL_VOTING"; default: return "UNKNOWN"; } @@ -103,7 +115,9 @@ export interface Params { minDelegationAmounts: Coin[]; } -const baseParams: object = { historicalEntries: 0, initialValEngagementPoints: Long.UZERO }; +function createBaseParams(): Params { + return { historicalEntries: 0, initialValEngagementPoints: Long.UZERO, minDelegationAmounts: [] }; +} export const Params = { encode(message: Params, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -122,8 +136,7 @@ export const Params = { decode(input: _m0.Reader | Uint8Array, length?: number): Params { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseParams } as Params; - message.minDelegationAmounts = []; + const message = createBaseParams(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -145,29 +158,21 @@ export const Params = { }, fromJSON(object: any): Params { - const message = { ...baseParams } as Params; - message.minDelegationAmounts = []; - if (object.historicalEntries !== undefined && object.historicalEntries !== null) { - message.historicalEntries = Number(object.historicalEntries); - } else { - message.historicalEntries = 0; - } - if (object.initialValEngagementPoints !== undefined && object.initialValEngagementPoints !== null) { - message.initialValEngagementPoints = Long.fromString(object.initialValEngagementPoints); - } else { - message.initialValEngagementPoints = Long.UZERO; - } - if (object.minDelegationAmounts !== undefined && object.minDelegationAmounts !== null) { - for (const e of object.minDelegationAmounts) { - message.minDelegationAmounts.push(Coin.fromJSON(e)); - } - } - return message; + return { + historicalEntries: isSet(object.historicalEntries) ? Number(object.historicalEntries) : 0, + initialValEngagementPoints: isSet(object.initialValEngagementPoints) + ? Long.fromString(object.initialValEngagementPoints) + : Long.UZERO, + minDelegationAmounts: Array.isArray(object?.minDelegationAmounts) + ? object.minDelegationAmounts.map((e: any) => Coin.fromJSON(e)) + : [], + }; }, toJSON(message: Params): unknown { const obj: any = {}; - message.historicalEntries !== undefined && (obj.historicalEntries = message.historicalEntries); + message.historicalEntries !== undefined && + (obj.historicalEntries = Math.round(message.historicalEntries)); message.initialValEngagementPoints !== undefined && (obj.initialValEngagementPoints = (message.initialValEngagementPoints || Long.UZERO).toString()); if (message.minDelegationAmounts) { @@ -178,27 +183,24 @@ export const Params = { return obj; }, - fromPartial(object: DeepPartial): Params { - const message = { ...baseParams } as Params; + fromPartial, I>>(object: I): Params { + const message = createBaseParams(); message.historicalEntries = object.historicalEntries ?? 0; - if (object.initialValEngagementPoints !== undefined && object.initialValEngagementPoints !== null) { - message.initialValEngagementPoints = object.initialValEngagementPoints as Long; - } else { - message.initialValEngagementPoints = Long.UZERO; - } - message.minDelegationAmounts = []; - if (object.minDelegationAmounts !== undefined && object.minDelegationAmounts !== null) { - for (const e of object.minDelegationAmounts) { - message.minDelegationAmounts.push(Coin.fromPartial(e)); - } - } + message.initialValEngagementPoints = + object.initialValEngagementPoints !== undefined && object.initialValEngagementPoints !== null + ? Long.fromValue(object.initialValEngagementPoints) + : Long.UZERO; + message.minDelegationAmounts = object.minDelegationAmounts?.map((e) => Coin.fromPartial(e)) || []; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -207,7 +209,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/confio/poe/v1beta1/query.ts b/src/codec/confio/poe/v1beta1/query.ts index a63faf9e..0fb4b3a7 100644 --- a/src/codec/confio/poe/v1beta1/query.ts +++ b/src/codec/confio/poe/v1beta1/query.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; import { PoEContractType, poEContractTypeFromJSON, @@ -109,7 +109,9 @@ export interface QueryValidatorOutstandingRewardResponse { reward?: DecCoin; } -const baseQueryContractAddressRequest: object = { contractType: 0 }; +function createBaseQueryContractAddressRequest(): QueryContractAddressRequest { + return { contractType: 0 }; +} export const QueryContractAddressRequest = { encode(message: QueryContractAddressRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -122,7 +124,7 @@ export const QueryContractAddressRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryContractAddressRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryContractAddressRequest } as QueryContractAddressRequest; + const message = createBaseQueryContractAddressRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -138,13 +140,9 @@ export const QueryContractAddressRequest = { }, fromJSON(object: any): QueryContractAddressRequest { - const message = { ...baseQueryContractAddressRequest } as QueryContractAddressRequest; - if (object.contractType !== undefined && object.contractType !== null) { - message.contractType = poEContractTypeFromJSON(object.contractType); - } else { - message.contractType = 0; - } - return message; + return { + contractType: isSet(object.contractType) ? poEContractTypeFromJSON(object.contractType) : 0, + }; }, toJSON(message: QueryContractAddressRequest): unknown { @@ -153,14 +151,18 @@ export const QueryContractAddressRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryContractAddressRequest { - const message = { ...baseQueryContractAddressRequest } as QueryContractAddressRequest; + fromPartial, I>>( + object: I, + ): QueryContractAddressRequest { + const message = createBaseQueryContractAddressRequest(); message.contractType = object.contractType ?? 0; return message; }, }; -const baseQueryContractAddressResponse: object = { address: "" }; +function createBaseQueryContractAddressResponse(): QueryContractAddressResponse { + return { address: "" }; +} export const QueryContractAddressResponse = { encode(message: QueryContractAddressResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -173,7 +175,7 @@ export const QueryContractAddressResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryContractAddressResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryContractAddressResponse } as QueryContractAddressResponse; + const message = createBaseQueryContractAddressResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -189,13 +191,9 @@ export const QueryContractAddressResponse = { }, fromJSON(object: any): QueryContractAddressResponse { - const message = { ...baseQueryContractAddressResponse } as QueryContractAddressResponse; - if (object.address !== undefined && object.address !== null) { - message.address = String(object.address); - } else { - message.address = ""; - } - return message; + return { + address: isSet(object.address) ? String(object.address) : "", + }; }, toJSON(message: QueryContractAddressResponse): unknown { @@ -204,14 +202,18 @@ export const QueryContractAddressResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryContractAddressResponse { - const message = { ...baseQueryContractAddressResponse } as QueryContractAddressResponse; + fromPartial, I>>( + object: I, + ): QueryContractAddressResponse { + const message = createBaseQueryContractAddressResponse(); message.address = object.address ?? ""; return message; }, }; -const baseQueryUnbondingPeriodRequest: object = {}; +function createBaseQueryUnbondingPeriodRequest(): QueryUnbondingPeriodRequest { + return {}; +} export const QueryUnbondingPeriodRequest = { encode(_: QueryUnbondingPeriodRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -221,7 +223,7 @@ export const QueryUnbondingPeriodRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryUnbondingPeriodRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryUnbondingPeriodRequest } as QueryUnbondingPeriodRequest; + const message = createBaseQueryUnbondingPeriodRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -234,8 +236,7 @@ export const QueryUnbondingPeriodRequest = { }, fromJSON(_: any): QueryUnbondingPeriodRequest { - const message = { ...baseQueryUnbondingPeriodRequest } as QueryUnbondingPeriodRequest; - return message; + return {}; }, toJSON(_: QueryUnbondingPeriodRequest): unknown { @@ -243,13 +244,17 @@ export const QueryUnbondingPeriodRequest = { return obj; }, - fromPartial(_: DeepPartial): QueryUnbondingPeriodRequest { - const message = { ...baseQueryUnbondingPeriodRequest } as QueryUnbondingPeriodRequest; + fromPartial, I>>( + _: I, + ): QueryUnbondingPeriodRequest { + const message = createBaseQueryUnbondingPeriodRequest(); return message; }, }; -const baseQueryUnbondingPeriodResponse: object = {}; +function createBaseQueryUnbondingPeriodResponse(): QueryUnbondingPeriodResponse { + return { time: undefined }; +} export const QueryUnbondingPeriodResponse = { encode(message: QueryUnbondingPeriodResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -262,7 +267,7 @@ export const QueryUnbondingPeriodResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryUnbondingPeriodResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryUnbondingPeriodResponse } as QueryUnbondingPeriodResponse; + const message = createBaseQueryUnbondingPeriodResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -278,13 +283,9 @@ export const QueryUnbondingPeriodResponse = { }, fromJSON(object: any): QueryUnbondingPeriodResponse { - const message = { ...baseQueryUnbondingPeriodResponse } as QueryUnbondingPeriodResponse; - if (object.time !== undefined && object.time !== null) { - message.time = Duration.fromJSON(object.time); - } else { - message.time = undefined; - } - return message; + return { + time: isSet(object.time) ? Duration.fromJSON(object.time) : undefined, + }; }, toJSON(message: QueryUnbondingPeriodResponse): unknown { @@ -293,18 +294,19 @@ export const QueryUnbondingPeriodResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryUnbondingPeriodResponse { - const message = { ...baseQueryUnbondingPeriodResponse } as QueryUnbondingPeriodResponse; - if (object.time !== undefined && object.time !== null) { - message.time = Duration.fromPartial(object.time); - } else { - message.time = undefined; - } + fromPartial, I>>( + object: I, + ): QueryUnbondingPeriodResponse { + const message = createBaseQueryUnbondingPeriodResponse(); + message.time = + object.time !== undefined && object.time !== null ? Duration.fromPartial(object.time) : undefined; return message; }, }; -const baseQueryValidatorDelegationRequest: object = { validatorAddr: "" }; +function createBaseQueryValidatorDelegationRequest(): QueryValidatorDelegationRequest { + return { validatorAddr: "" }; +} export const QueryValidatorDelegationRequest = { encode(message: QueryValidatorDelegationRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -317,7 +319,7 @@ export const QueryValidatorDelegationRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorDelegationRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorDelegationRequest } as QueryValidatorDelegationRequest; + const message = createBaseQueryValidatorDelegationRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -333,13 +335,9 @@ export const QueryValidatorDelegationRequest = { }, fromJSON(object: any): QueryValidatorDelegationRequest { - const message = { ...baseQueryValidatorDelegationRequest } as QueryValidatorDelegationRequest; - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - return message; + return { + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + }; }, toJSON(message: QueryValidatorDelegationRequest): unknown { @@ -348,14 +346,18 @@ export const QueryValidatorDelegationRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorDelegationRequest { - const message = { ...baseQueryValidatorDelegationRequest } as QueryValidatorDelegationRequest; + fromPartial, I>>( + object: I, + ): QueryValidatorDelegationRequest { + const message = createBaseQueryValidatorDelegationRequest(); message.validatorAddr = object.validatorAddr ?? ""; return message; }, }; -const baseQueryValidatorDelegationResponse: object = {}; +function createBaseQueryValidatorDelegationResponse(): QueryValidatorDelegationResponse { + return { balance: undefined }; +} export const QueryValidatorDelegationResponse = { encode(message: QueryValidatorDelegationResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -368,7 +370,7 @@ export const QueryValidatorDelegationResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorDelegationResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorDelegationResponse } as QueryValidatorDelegationResponse; + const message = createBaseQueryValidatorDelegationResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -384,13 +386,9 @@ export const QueryValidatorDelegationResponse = { }, fromJSON(object: any): QueryValidatorDelegationResponse { - const message = { ...baseQueryValidatorDelegationResponse } as QueryValidatorDelegationResponse; - if (object.balance !== undefined && object.balance !== null) { - message.balance = Coin.fromJSON(object.balance); - } else { - message.balance = undefined; - } - return message; + return { + balance: isSet(object.balance) ? Coin.fromJSON(object.balance) : undefined, + }; }, toJSON(message: QueryValidatorDelegationResponse): unknown { @@ -400,18 +398,19 @@ export const QueryValidatorDelegationResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorDelegationResponse { - const message = { ...baseQueryValidatorDelegationResponse } as QueryValidatorDelegationResponse; - if (object.balance !== undefined && object.balance !== null) { - message.balance = Coin.fromPartial(object.balance); - } else { - message.balance = undefined; - } + fromPartial, I>>( + object: I, + ): QueryValidatorDelegationResponse { + const message = createBaseQueryValidatorDelegationResponse(); + message.balance = + object.balance !== undefined && object.balance !== null ? Coin.fromPartial(object.balance) : undefined; return message; }, }; -const baseQueryValidatorUnbondingDelegationsRequest: object = { validatorAddr: "" }; +function createBaseQueryValidatorUnbondingDelegationsRequest(): QueryValidatorUnbondingDelegationsRequest { + return { validatorAddr: "", pagination: undefined }; +} export const QueryValidatorUnbondingDelegationsRequest = { encode( @@ -430,9 +429,7 @@ export const QueryValidatorUnbondingDelegationsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorUnbondingDelegationsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryValidatorUnbondingDelegationsRequest, - } as QueryValidatorUnbondingDelegationsRequest; + const message = createBaseQueryValidatorUnbondingDelegationsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -451,20 +448,10 @@ export const QueryValidatorUnbondingDelegationsRequest = { }, fromJSON(object: any): QueryValidatorUnbondingDelegationsRequest { - const message = { - ...baseQueryValidatorUnbondingDelegationsRequest, - } as QueryValidatorUnbondingDelegationsRequest; - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorUnbondingDelegationsRequest): unknown { @@ -475,23 +462,22 @@ export const QueryValidatorUnbondingDelegationsRequest = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryValidatorUnbondingDelegationsRequest { - const message = { - ...baseQueryValidatorUnbondingDelegationsRequest, - } as QueryValidatorUnbondingDelegationsRequest; + const message = createBaseQueryValidatorUnbondingDelegationsRequest(); message.validatorAddr = object.validatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorUnbondingDelegationsResponse: object = {}; +function createBaseQueryValidatorUnbondingDelegationsResponse(): QueryValidatorUnbondingDelegationsResponse { + return { entries: [], pagination: undefined }; +} export const QueryValidatorUnbondingDelegationsResponse = { encode( @@ -510,10 +496,7 @@ export const QueryValidatorUnbondingDelegationsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorUnbondingDelegationsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryValidatorUnbondingDelegationsResponse, - } as QueryValidatorUnbondingDelegationsResponse; - message.entries = []; + const message = createBaseQueryValidatorUnbondingDelegationsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -532,21 +515,12 @@ export const QueryValidatorUnbondingDelegationsResponse = { }, fromJSON(object: any): QueryValidatorUnbondingDelegationsResponse { - const message = { - ...baseQueryValidatorUnbondingDelegationsResponse, - } as QueryValidatorUnbondingDelegationsResponse; - message.entries = []; - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(UnbondingDelegationEntry.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + entries: Array.isArray(object?.entries) + ? object.entries.map((e: any) => UnbondingDelegationEntry.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorUnbondingDelegationsResponse): unknown { @@ -561,28 +535,22 @@ export const QueryValidatorUnbondingDelegationsResponse = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryValidatorUnbondingDelegationsResponse { - const message = { - ...baseQueryValidatorUnbondingDelegationsResponse, - } as QueryValidatorUnbondingDelegationsResponse; - message.entries = []; - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(UnbondingDelegationEntry.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + const message = createBaseQueryValidatorUnbondingDelegationsResponse(); + message.entries = object.entries?.map((e) => UnbondingDelegationEntry.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorOutstandingRewardRequest: object = { validatorAddress: "" }; +function createBaseQueryValidatorOutstandingRewardRequest(): QueryValidatorOutstandingRewardRequest { + return { validatorAddress: "" }; +} export const QueryValidatorOutstandingRewardRequest = { encode( @@ -598,9 +566,7 @@ export const QueryValidatorOutstandingRewardRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorOutstandingRewardRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryValidatorOutstandingRewardRequest, - } as QueryValidatorOutstandingRewardRequest; + const message = createBaseQueryValidatorOutstandingRewardRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -616,15 +582,9 @@ export const QueryValidatorOutstandingRewardRequest = { }, fromJSON(object: any): QueryValidatorOutstandingRewardRequest { - const message = { - ...baseQueryValidatorOutstandingRewardRequest, - } as QueryValidatorOutstandingRewardRequest; - if (object.validatorAddress !== undefined && object.validatorAddress !== null) { - message.validatorAddress = String(object.validatorAddress); - } else { - message.validatorAddress = ""; - } - return message; + return { + validatorAddress: isSet(object.validatorAddress) ? String(object.validatorAddress) : "", + }; }, toJSON(message: QueryValidatorOutstandingRewardRequest): unknown { @@ -633,18 +593,18 @@ export const QueryValidatorOutstandingRewardRequest = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryValidatorOutstandingRewardRequest { - const message = { - ...baseQueryValidatorOutstandingRewardRequest, - } as QueryValidatorOutstandingRewardRequest; + const message = createBaseQueryValidatorOutstandingRewardRequest(); message.validatorAddress = object.validatorAddress ?? ""; return message; }, }; -const baseQueryValidatorOutstandingRewardResponse: object = {}; +function createBaseQueryValidatorOutstandingRewardResponse(): QueryValidatorOutstandingRewardResponse { + return { reward: undefined }; +} export const QueryValidatorOutstandingRewardResponse = { encode( @@ -660,9 +620,7 @@ export const QueryValidatorOutstandingRewardResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorOutstandingRewardResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryValidatorOutstandingRewardResponse, - } as QueryValidatorOutstandingRewardResponse; + const message = createBaseQueryValidatorOutstandingRewardResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -678,15 +636,9 @@ export const QueryValidatorOutstandingRewardResponse = { }, fromJSON(object: any): QueryValidatorOutstandingRewardResponse { - const message = { - ...baseQueryValidatorOutstandingRewardResponse, - } as QueryValidatorOutstandingRewardResponse; - if (object.reward !== undefined && object.reward !== null) { - message.reward = DecCoin.fromJSON(object.reward); - } else { - message.reward = undefined; - } - return message; + return { + reward: isSet(object.reward) ? DecCoin.fromJSON(object.reward) : undefined, + }; }, toJSON(message: QueryValidatorOutstandingRewardResponse): unknown { @@ -696,17 +648,12 @@ export const QueryValidatorOutstandingRewardResponse = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryValidatorOutstandingRewardResponse { - const message = { - ...baseQueryValidatorOutstandingRewardResponse, - } as QueryValidatorOutstandingRewardResponse; - if (object.reward !== undefined && object.reward !== null) { - message.reward = DecCoin.fromPartial(object.reward); - } else { - message.reward = undefined; - } + const message = createBaseQueryValidatorOutstandingRewardResponse(); + message.reward = + object.reward !== undefined && object.reward !== null ? DecCoin.fromPartial(object.reward) : undefined; return message; }, }; @@ -805,9 +752,12 @@ interface Rpc { request(service: string, method: string, data: Uint8Array): Promise; } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -816,7 +766,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/cosmos/base/query/v1beta1/pagination.ts b/src/codec/cosmos/base/query/v1beta1/pagination.ts index 65a6fcdd..db06d01c 100644 --- a/src/codec/cosmos/base/query/v1beta1/pagination.ts +++ b/src/codec/cosmos/base/query/v1beta1/pagination.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "cosmos.base.query.v1beta1"; @@ -38,6 +38,12 @@ export interface PageRequest { * is set. */ countTotal: boolean; + /** + * reverse is set to true if results are to be returned in the descending order. + * + * Since: cosmos-sdk 0.43 + */ + reverse: boolean; } /** @@ -62,7 +68,9 @@ export interface PageResponse { total: Long; } -const basePageRequest: object = { offset: Long.UZERO, limit: Long.UZERO, countTotal: false }; +function createBasePageRequest(): PageRequest { + return { key: new Uint8Array(), offset: Long.UZERO, limit: Long.UZERO, countTotal: false, reverse: false }; +} export const PageRequest = { encode(message: PageRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -78,14 +86,16 @@ export const PageRequest = { if (message.countTotal === true) { writer.uint32(32).bool(message.countTotal); } + if (message.reverse === true) { + writer.uint32(40).bool(message.reverse); + } return writer; }, decode(input: _m0.Reader | Uint8Array, length?: number): PageRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...basePageRequest } as PageRequest; - message.key = new Uint8Array(); + const message = createBasePageRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -101,6 +111,9 @@ export const PageRequest = { case 4: message.countTotal = reader.bool(); break; + case 5: + message.reverse = reader.bool(); + break; default: reader.skipType(tag & 7); break; @@ -110,27 +123,13 @@ export const PageRequest = { }, fromJSON(object: any): PageRequest { - const message = { ...basePageRequest } as PageRequest; - message.key = new Uint8Array(); - if (object.key !== undefined && object.key !== null) { - message.key = bytesFromBase64(object.key); - } - if (object.offset !== undefined && object.offset !== null) { - message.offset = Long.fromString(object.offset); - } else { - message.offset = Long.UZERO; - } - if (object.limit !== undefined && object.limit !== null) { - message.limit = Long.fromString(object.limit); - } else { - message.limit = Long.UZERO; - } - if (object.countTotal !== undefined && object.countTotal !== null) { - message.countTotal = Boolean(object.countTotal); - } else { - message.countTotal = false; - } - return message; + return { + key: isSet(object.key) ? bytesFromBase64(object.key) : new Uint8Array(), + offset: isSet(object.offset) ? Long.fromString(object.offset) : Long.UZERO, + limit: isSet(object.limit) ? Long.fromString(object.limit) : Long.UZERO, + countTotal: isSet(object.countTotal) ? Boolean(object.countTotal) : false, + reverse: isSet(object.reverse) ? Boolean(object.reverse) : false, + }; }, toJSON(message: PageRequest): unknown { @@ -140,28 +139,26 @@ export const PageRequest = { message.offset !== undefined && (obj.offset = (message.offset || Long.UZERO).toString()); message.limit !== undefined && (obj.limit = (message.limit || Long.UZERO).toString()); message.countTotal !== undefined && (obj.countTotal = message.countTotal); + message.reverse !== undefined && (obj.reverse = message.reverse); return obj; }, - fromPartial(object: DeepPartial): PageRequest { - const message = { ...basePageRequest } as PageRequest; + fromPartial, I>>(object: I): PageRequest { + const message = createBasePageRequest(); message.key = object.key ?? new Uint8Array(); - if (object.offset !== undefined && object.offset !== null) { - message.offset = object.offset as Long; - } else { - message.offset = Long.UZERO; - } - if (object.limit !== undefined && object.limit !== null) { - message.limit = object.limit as Long; - } else { - message.limit = Long.UZERO; - } + message.offset = + object.offset !== undefined && object.offset !== null ? Long.fromValue(object.offset) : Long.UZERO; + message.limit = + object.limit !== undefined && object.limit !== null ? Long.fromValue(object.limit) : Long.UZERO; message.countTotal = object.countTotal ?? false; + message.reverse = object.reverse ?? false; return message; }, }; -const basePageResponse: object = { total: Long.UZERO }; +function createBasePageResponse(): PageResponse { + return { nextKey: new Uint8Array(), total: Long.UZERO }; +} export const PageResponse = { encode(message: PageResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -177,8 +174,7 @@ export const PageResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): PageResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...basePageResponse } as PageResponse; - message.nextKey = new Uint8Array(); + const message = createBasePageResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -197,17 +193,10 @@ export const PageResponse = { }, fromJSON(object: any): PageResponse { - const message = { ...basePageResponse } as PageResponse; - message.nextKey = new Uint8Array(); - if (object.nextKey !== undefined && object.nextKey !== null) { - message.nextKey = bytesFromBase64(object.nextKey); - } - if (object.total !== undefined && object.total !== null) { - message.total = Long.fromString(object.total); - } else { - message.total = Long.UZERO; - } - return message; + return { + nextKey: isSet(object.nextKey) ? bytesFromBase64(object.nextKey) : new Uint8Array(), + total: isSet(object.total) ? Long.fromString(object.total) : Long.UZERO, + }; }, toJSON(message: PageResponse): unknown { @@ -218,14 +207,11 @@ export const PageResponse = { return obj; }, - fromPartial(object: DeepPartial): PageResponse { - const message = { ...basePageResponse } as PageResponse; + fromPartial, I>>(object: I): PageResponse { + const message = createBasePageResponse(); message.nextKey = object.nextKey ?? new Uint8Array(); - if (object.total !== undefined && object.total !== null) { - message.total = object.total as Long; - } else { - message.total = Long.UZERO; - } + message.total = + object.total !== undefined && object.total !== null ? Long.fromValue(object.total) : Long.UZERO; return message; }, }; @@ -256,15 +242,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -273,7 +262,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/cosmos/base/v1beta1/coin.ts b/src/codec/cosmos/base/v1beta1/coin.ts index c9ee32f6..6eb6476c 100644 --- a/src/codec/cosmos/base/v1beta1/coin.ts +++ b/src/codec/cosmos/base/v1beta1/coin.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "cosmos.base.v1beta1"; @@ -36,7 +36,9 @@ export interface DecProto { dec: string; } -const baseCoin: object = { denom: "", amount: "" }; +function createBaseCoin(): Coin { + return { denom: "", amount: "" }; +} export const Coin = { encode(message: Coin, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -52,7 +54,7 @@ export const Coin = { decode(input: _m0.Reader | Uint8Array, length?: number): Coin { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCoin } as Coin; + const message = createBaseCoin(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -71,18 +73,10 @@ export const Coin = { }, fromJSON(object: any): Coin { - const message = { ...baseCoin } as Coin; - if (object.denom !== undefined && object.denom !== null) { - message.denom = String(object.denom); - } else { - message.denom = ""; - } - if (object.amount !== undefined && object.amount !== null) { - message.amount = String(object.amount); - } else { - message.amount = ""; - } - return message; + return { + denom: isSet(object.denom) ? String(object.denom) : "", + amount: isSet(object.amount) ? String(object.amount) : "", + }; }, toJSON(message: Coin): unknown { @@ -92,15 +86,17 @@ export const Coin = { return obj; }, - fromPartial(object: DeepPartial): Coin { - const message = { ...baseCoin } as Coin; + fromPartial, I>>(object: I): Coin { + const message = createBaseCoin(); message.denom = object.denom ?? ""; message.amount = object.amount ?? ""; return message; }, }; -const baseDecCoin: object = { denom: "", amount: "" }; +function createBaseDecCoin(): DecCoin { + return { denom: "", amount: "" }; +} export const DecCoin = { encode(message: DecCoin, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -116,7 +112,7 @@ export const DecCoin = { decode(input: _m0.Reader | Uint8Array, length?: number): DecCoin { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDecCoin } as DecCoin; + const message = createBaseDecCoin(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -135,18 +131,10 @@ export const DecCoin = { }, fromJSON(object: any): DecCoin { - const message = { ...baseDecCoin } as DecCoin; - if (object.denom !== undefined && object.denom !== null) { - message.denom = String(object.denom); - } else { - message.denom = ""; - } - if (object.amount !== undefined && object.amount !== null) { - message.amount = String(object.amount); - } else { - message.amount = ""; - } - return message; + return { + denom: isSet(object.denom) ? String(object.denom) : "", + amount: isSet(object.amount) ? String(object.amount) : "", + }; }, toJSON(message: DecCoin): unknown { @@ -156,15 +144,17 @@ export const DecCoin = { return obj; }, - fromPartial(object: DeepPartial): DecCoin { - const message = { ...baseDecCoin } as DecCoin; + fromPartial, I>>(object: I): DecCoin { + const message = createBaseDecCoin(); message.denom = object.denom ?? ""; message.amount = object.amount ?? ""; return message; }, }; -const baseIntProto: object = { int: "" }; +function createBaseIntProto(): IntProto { + return { int: "" }; +} export const IntProto = { encode(message: IntProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -177,7 +167,7 @@ export const IntProto = { decode(input: _m0.Reader | Uint8Array, length?: number): IntProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseIntProto } as IntProto; + const message = createBaseIntProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -193,13 +183,9 @@ export const IntProto = { }, fromJSON(object: any): IntProto { - const message = { ...baseIntProto } as IntProto; - if (object.int !== undefined && object.int !== null) { - message.int = String(object.int); - } else { - message.int = ""; - } - return message; + return { + int: isSet(object.int) ? String(object.int) : "", + }; }, toJSON(message: IntProto): unknown { @@ -208,14 +194,16 @@ export const IntProto = { return obj; }, - fromPartial(object: DeepPartial): IntProto { - const message = { ...baseIntProto } as IntProto; + fromPartial, I>>(object: I): IntProto { + const message = createBaseIntProto(); message.int = object.int ?? ""; return message; }, }; -const baseDecProto: object = { dec: "" }; +function createBaseDecProto(): DecProto { + return { dec: "" }; +} export const DecProto = { encode(message: DecProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -228,7 +216,7 @@ export const DecProto = { decode(input: _m0.Reader | Uint8Array, length?: number): DecProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDecProto } as DecProto; + const message = createBaseDecProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -244,13 +232,9 @@ export const DecProto = { }, fromJSON(object: any): DecProto { - const message = { ...baseDecProto } as DecProto; - if (object.dec !== undefined && object.dec !== null) { - message.dec = String(object.dec); - } else { - message.dec = ""; - } - return message; + return { + dec: isSet(object.dec) ? String(object.dec) : "", + }; }, toJSON(message: DecProto): unknown { @@ -259,16 +243,19 @@ export const DecProto = { return obj; }, - fromPartial(object: DeepPartial): DecProto { - const message = { ...baseDecProto } as DecProto; + fromPartial, I>>(object: I): DecProto { + const message = createBaseDecProto(); message.dec = object.dec ?? ""; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -277,7 +264,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/cosmos/staking/v1beta1/query.ts b/src/codec/cosmos/staking/v1beta1/query.ts index ed91a492..95e750cc 100644 --- a/src/codec/cosmos/staking/v1beta1/query.ts +++ b/src/codec/cosmos/staking/v1beta1/query.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; import { PageRequest, PageResponse } from "../../../cosmos/base/query/v1beta1/pagination"; import { Validator, @@ -264,7 +264,9 @@ export interface QueryParamsResponse { params?: Params; } -const baseQueryValidatorsRequest: object = { status: "" }; +function createBaseQueryValidatorsRequest(): QueryValidatorsRequest { + return { status: "", pagination: undefined }; +} export const QueryValidatorsRequest = { encode(message: QueryValidatorsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -280,7 +282,7 @@ export const QueryValidatorsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorsRequest } as QueryValidatorsRequest; + const message = createBaseQueryValidatorsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -299,18 +301,10 @@ export const QueryValidatorsRequest = { }, fromJSON(object: any): QueryValidatorsRequest { - const message = { ...baseQueryValidatorsRequest } as QueryValidatorsRequest; - if (object.status !== undefined && object.status !== null) { - message.status = String(object.status); - } else { - message.status = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + status: isSet(object.status) ? String(object.status) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorsRequest): unknown { @@ -321,19 +315,20 @@ export const QueryValidatorsRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorsRequest { - const message = { ...baseQueryValidatorsRequest } as QueryValidatorsRequest; + fromPartial, I>>(object: I): QueryValidatorsRequest { + const message = createBaseQueryValidatorsRequest(); message.status = object.status ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorsResponse: object = {}; +function createBaseQueryValidatorsResponse(): QueryValidatorsResponse { + return { validators: [], pagination: undefined }; +} export const QueryValidatorsResponse = { encode(message: QueryValidatorsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -349,8 +344,7 @@ export const QueryValidatorsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorsResponse } as QueryValidatorsResponse; - message.validators = []; + const message = createBaseQueryValidatorsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -369,19 +363,12 @@ export const QueryValidatorsResponse = { }, fromJSON(object: any): QueryValidatorsResponse { - const message = { ...baseQueryValidatorsResponse } as QueryValidatorsResponse; - message.validators = []; - if (object.validators !== undefined && object.validators !== null) { - for (const e of object.validators) { - message.validators.push(Validator.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + validators: Array.isArray(object?.validators) + ? object.validators.map((e: any) => Validator.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorsResponse): unknown { @@ -396,24 +383,20 @@ export const QueryValidatorsResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorsResponse { - const message = { ...baseQueryValidatorsResponse } as QueryValidatorsResponse; - message.validators = []; - if (object.validators !== undefined && object.validators !== null) { - for (const e of object.validators) { - message.validators.push(Validator.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + fromPartial, I>>(object: I): QueryValidatorsResponse { + const message = createBaseQueryValidatorsResponse(); + message.validators = object.validators?.map((e) => Validator.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorRequest: object = { validatorAddr: "" }; +function createBaseQueryValidatorRequest(): QueryValidatorRequest { + return { validatorAddr: "" }; +} export const QueryValidatorRequest = { encode(message: QueryValidatorRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -426,7 +409,7 @@ export const QueryValidatorRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorRequest } as QueryValidatorRequest; + const message = createBaseQueryValidatorRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -442,13 +425,9 @@ export const QueryValidatorRequest = { }, fromJSON(object: any): QueryValidatorRequest { - const message = { ...baseQueryValidatorRequest } as QueryValidatorRequest; - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - return message; + return { + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + }; }, toJSON(message: QueryValidatorRequest): unknown { @@ -457,14 +436,16 @@ export const QueryValidatorRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorRequest { - const message = { ...baseQueryValidatorRequest } as QueryValidatorRequest; + fromPartial, I>>(object: I): QueryValidatorRequest { + const message = createBaseQueryValidatorRequest(); message.validatorAddr = object.validatorAddr ?? ""; return message; }, }; -const baseQueryValidatorResponse: object = {}; +function createBaseQueryValidatorResponse(): QueryValidatorResponse { + return { validator: undefined }; +} export const QueryValidatorResponse = { encode(message: QueryValidatorResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -477,7 +458,7 @@ export const QueryValidatorResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorResponse } as QueryValidatorResponse; + const message = createBaseQueryValidatorResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -493,13 +474,9 @@ export const QueryValidatorResponse = { }, fromJSON(object: any): QueryValidatorResponse { - const message = { ...baseQueryValidatorResponse } as QueryValidatorResponse; - if (object.validator !== undefined && object.validator !== null) { - message.validator = Validator.fromJSON(object.validator); - } else { - message.validator = undefined; - } - return message; + return { + validator: isSet(object.validator) ? Validator.fromJSON(object.validator) : undefined, + }; }, toJSON(message: QueryValidatorResponse): unknown { @@ -509,18 +486,19 @@ export const QueryValidatorResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorResponse { - const message = { ...baseQueryValidatorResponse } as QueryValidatorResponse; - if (object.validator !== undefined && object.validator !== null) { - message.validator = Validator.fromPartial(object.validator); - } else { - message.validator = undefined; - } + fromPartial, I>>(object: I): QueryValidatorResponse { + const message = createBaseQueryValidatorResponse(); + message.validator = + object.validator !== undefined && object.validator !== null + ? Validator.fromPartial(object.validator) + : undefined; return message; }, }; -const baseQueryValidatorDelegationsRequest: object = { validatorAddr: "" }; +function createBaseQueryValidatorDelegationsRequest(): QueryValidatorDelegationsRequest { + return { validatorAddr: "", pagination: undefined }; +} export const QueryValidatorDelegationsRequest = { encode(message: QueryValidatorDelegationsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -536,7 +514,7 @@ export const QueryValidatorDelegationsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorDelegationsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorDelegationsRequest } as QueryValidatorDelegationsRequest; + const message = createBaseQueryValidatorDelegationsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -555,18 +533,10 @@ export const QueryValidatorDelegationsRequest = { }, fromJSON(object: any): QueryValidatorDelegationsRequest { - const message = { ...baseQueryValidatorDelegationsRequest } as QueryValidatorDelegationsRequest; - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorDelegationsRequest): unknown { @@ -577,19 +547,22 @@ export const QueryValidatorDelegationsRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorDelegationsRequest { - const message = { ...baseQueryValidatorDelegationsRequest } as QueryValidatorDelegationsRequest; + fromPartial, I>>( + object: I, + ): QueryValidatorDelegationsRequest { + const message = createBaseQueryValidatorDelegationsRequest(); message.validatorAddr = object.validatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorDelegationsResponse: object = {}; +function createBaseQueryValidatorDelegationsResponse(): QueryValidatorDelegationsResponse { + return { delegationResponses: [], pagination: undefined }; +} export const QueryValidatorDelegationsResponse = { encode(message: QueryValidatorDelegationsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -605,8 +578,7 @@ export const QueryValidatorDelegationsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorDelegationsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryValidatorDelegationsResponse } as QueryValidatorDelegationsResponse; - message.delegationResponses = []; + const message = createBaseQueryValidatorDelegationsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -625,19 +597,12 @@ export const QueryValidatorDelegationsResponse = { }, fromJSON(object: any): QueryValidatorDelegationsResponse { - const message = { ...baseQueryValidatorDelegationsResponse } as QueryValidatorDelegationsResponse; - message.delegationResponses = []; - if (object.delegationResponses !== undefined && object.delegationResponses !== null) { - for (const e of object.delegationResponses) { - message.delegationResponses.push(DelegationResponse.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + delegationResponses: Array.isArray(object?.delegationResponses) + ? object.delegationResponses.map((e: any) => DelegationResponse.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorDelegationsResponse): unknown { @@ -654,24 +619,23 @@ export const QueryValidatorDelegationsResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryValidatorDelegationsResponse { - const message = { ...baseQueryValidatorDelegationsResponse } as QueryValidatorDelegationsResponse; - message.delegationResponses = []; - if (object.delegationResponses !== undefined && object.delegationResponses !== null) { - for (const e of object.delegationResponses) { - message.delegationResponses.push(DelegationResponse.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + fromPartial, I>>( + object: I, + ): QueryValidatorDelegationsResponse { + const message = createBaseQueryValidatorDelegationsResponse(); + message.delegationResponses = + object.delegationResponses?.map((e) => DelegationResponse.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorUnbondingDelegationsRequest: object = { validatorAddr: "" }; +function createBaseQueryValidatorUnbondingDelegationsRequest(): QueryValidatorUnbondingDelegationsRequest { + return { validatorAddr: "", pagination: undefined }; +} export const QueryValidatorUnbondingDelegationsRequest = { encode( @@ -690,9 +654,7 @@ export const QueryValidatorUnbondingDelegationsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorUnbondingDelegationsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryValidatorUnbondingDelegationsRequest, - } as QueryValidatorUnbondingDelegationsRequest; + const message = createBaseQueryValidatorUnbondingDelegationsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -711,20 +673,10 @@ export const QueryValidatorUnbondingDelegationsRequest = { }, fromJSON(object: any): QueryValidatorUnbondingDelegationsRequest { - const message = { - ...baseQueryValidatorUnbondingDelegationsRequest, - } as QueryValidatorUnbondingDelegationsRequest; - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorUnbondingDelegationsRequest): unknown { @@ -735,23 +687,22 @@ export const QueryValidatorUnbondingDelegationsRequest = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryValidatorUnbondingDelegationsRequest { - const message = { - ...baseQueryValidatorUnbondingDelegationsRequest, - } as QueryValidatorUnbondingDelegationsRequest; + const message = createBaseQueryValidatorUnbondingDelegationsRequest(); message.validatorAddr = object.validatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryValidatorUnbondingDelegationsResponse: object = {}; +function createBaseQueryValidatorUnbondingDelegationsResponse(): QueryValidatorUnbondingDelegationsResponse { + return { unbondingResponses: [], pagination: undefined }; +} export const QueryValidatorUnbondingDelegationsResponse = { encode( @@ -770,10 +721,7 @@ export const QueryValidatorUnbondingDelegationsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryValidatorUnbondingDelegationsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryValidatorUnbondingDelegationsResponse, - } as QueryValidatorUnbondingDelegationsResponse; - message.unbondingResponses = []; + const message = createBaseQueryValidatorUnbondingDelegationsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -792,21 +740,12 @@ export const QueryValidatorUnbondingDelegationsResponse = { }, fromJSON(object: any): QueryValidatorUnbondingDelegationsResponse { - const message = { - ...baseQueryValidatorUnbondingDelegationsResponse, - } as QueryValidatorUnbondingDelegationsResponse; - message.unbondingResponses = []; - if (object.unbondingResponses !== undefined && object.unbondingResponses !== null) { - for (const e of object.unbondingResponses) { - message.unbondingResponses.push(UnbondingDelegation.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + unbondingResponses: Array.isArray(object?.unbondingResponses) + ? object.unbondingResponses.map((e: any) => UnbondingDelegation.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryValidatorUnbondingDelegationsResponse): unknown { @@ -823,28 +762,23 @@ export const QueryValidatorUnbondingDelegationsResponse = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryValidatorUnbondingDelegationsResponse { - const message = { - ...baseQueryValidatorUnbondingDelegationsResponse, - } as QueryValidatorUnbondingDelegationsResponse; - message.unbondingResponses = []; - if (object.unbondingResponses !== undefined && object.unbondingResponses !== null) { - for (const e of object.unbondingResponses) { - message.unbondingResponses.push(UnbondingDelegation.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + const message = createBaseQueryValidatorUnbondingDelegationsResponse(); + message.unbondingResponses = + object.unbondingResponses?.map((e) => UnbondingDelegation.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegationRequest: object = { delegatorAddr: "", validatorAddr: "" }; +function createBaseQueryDelegationRequest(): QueryDelegationRequest { + return { delegatorAddr: "", validatorAddr: "" }; +} export const QueryDelegationRequest = { encode(message: QueryDelegationRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -860,7 +794,7 @@ export const QueryDelegationRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegationRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegationRequest } as QueryDelegationRequest; + const message = createBaseQueryDelegationRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -879,18 +813,10 @@ export const QueryDelegationRequest = { }, fromJSON(object: any): QueryDelegationRequest { - const message = { ...baseQueryDelegationRequest } as QueryDelegationRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + }; }, toJSON(message: QueryDelegationRequest): unknown { @@ -900,15 +826,17 @@ export const QueryDelegationRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegationRequest { - const message = { ...baseQueryDelegationRequest } as QueryDelegationRequest; + fromPartial, I>>(object: I): QueryDelegationRequest { + const message = createBaseQueryDelegationRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; message.validatorAddr = object.validatorAddr ?? ""; return message; }, }; -const baseQueryDelegationResponse: object = {}; +function createBaseQueryDelegationResponse(): QueryDelegationResponse { + return { delegationResponse: undefined }; +} export const QueryDelegationResponse = { encode(message: QueryDelegationResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -921,7 +849,7 @@ export const QueryDelegationResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegationResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegationResponse } as QueryDelegationResponse; + const message = createBaseQueryDelegationResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -937,13 +865,11 @@ export const QueryDelegationResponse = { }, fromJSON(object: any): QueryDelegationResponse { - const message = { ...baseQueryDelegationResponse } as QueryDelegationResponse; - if (object.delegationResponse !== undefined && object.delegationResponse !== null) { - message.delegationResponse = DelegationResponse.fromJSON(object.delegationResponse); - } else { - message.delegationResponse = undefined; - } - return message; + return { + delegationResponse: isSet(object.delegationResponse) + ? DelegationResponse.fromJSON(object.delegationResponse) + : undefined, + }; }, toJSON(message: QueryDelegationResponse): unknown { @@ -955,18 +881,19 @@ export const QueryDelegationResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegationResponse { - const message = { ...baseQueryDelegationResponse } as QueryDelegationResponse; - if (object.delegationResponse !== undefined && object.delegationResponse !== null) { - message.delegationResponse = DelegationResponse.fromPartial(object.delegationResponse); - } else { - message.delegationResponse = undefined; - } + fromPartial, I>>(object: I): QueryDelegationResponse { + const message = createBaseQueryDelegationResponse(); + message.delegationResponse = + object.delegationResponse !== undefined && object.delegationResponse !== null + ? DelegationResponse.fromPartial(object.delegationResponse) + : undefined; return message; }, }; -const baseQueryUnbondingDelegationRequest: object = { delegatorAddr: "", validatorAddr: "" }; +function createBaseQueryUnbondingDelegationRequest(): QueryUnbondingDelegationRequest { + return { delegatorAddr: "", validatorAddr: "" }; +} export const QueryUnbondingDelegationRequest = { encode(message: QueryUnbondingDelegationRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -982,7 +909,7 @@ export const QueryUnbondingDelegationRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryUnbondingDelegationRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryUnbondingDelegationRequest } as QueryUnbondingDelegationRequest; + const message = createBaseQueryUnbondingDelegationRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1001,18 +928,10 @@ export const QueryUnbondingDelegationRequest = { }, fromJSON(object: any): QueryUnbondingDelegationRequest { - const message = { ...baseQueryUnbondingDelegationRequest } as QueryUnbondingDelegationRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + }; }, toJSON(message: QueryUnbondingDelegationRequest): unknown { @@ -1022,15 +941,19 @@ export const QueryUnbondingDelegationRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryUnbondingDelegationRequest { - const message = { ...baseQueryUnbondingDelegationRequest } as QueryUnbondingDelegationRequest; + fromPartial, I>>( + object: I, + ): QueryUnbondingDelegationRequest { + const message = createBaseQueryUnbondingDelegationRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; message.validatorAddr = object.validatorAddr ?? ""; return message; }, }; -const baseQueryUnbondingDelegationResponse: object = {}; +function createBaseQueryUnbondingDelegationResponse(): QueryUnbondingDelegationResponse { + return { unbond: undefined }; +} export const QueryUnbondingDelegationResponse = { encode(message: QueryUnbondingDelegationResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1043,7 +966,7 @@ export const QueryUnbondingDelegationResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryUnbondingDelegationResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryUnbondingDelegationResponse } as QueryUnbondingDelegationResponse; + const message = createBaseQueryUnbondingDelegationResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1059,13 +982,9 @@ export const QueryUnbondingDelegationResponse = { }, fromJSON(object: any): QueryUnbondingDelegationResponse { - const message = { ...baseQueryUnbondingDelegationResponse } as QueryUnbondingDelegationResponse; - if (object.unbond !== undefined && object.unbond !== null) { - message.unbond = UnbondingDelegation.fromJSON(object.unbond); - } else { - message.unbond = undefined; - } - return message; + return { + unbond: isSet(object.unbond) ? UnbondingDelegation.fromJSON(object.unbond) : undefined, + }; }, toJSON(message: QueryUnbondingDelegationResponse): unknown { @@ -1075,18 +994,21 @@ export const QueryUnbondingDelegationResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryUnbondingDelegationResponse { - const message = { ...baseQueryUnbondingDelegationResponse } as QueryUnbondingDelegationResponse; - if (object.unbond !== undefined && object.unbond !== null) { - message.unbond = UnbondingDelegation.fromPartial(object.unbond); - } else { - message.unbond = undefined; - } + fromPartial, I>>( + object: I, + ): QueryUnbondingDelegationResponse { + const message = createBaseQueryUnbondingDelegationResponse(); + message.unbond = + object.unbond !== undefined && object.unbond !== null + ? UnbondingDelegation.fromPartial(object.unbond) + : undefined; return message; }, }; -const baseQueryDelegatorDelegationsRequest: object = { delegatorAddr: "" }; +function createBaseQueryDelegatorDelegationsRequest(): QueryDelegatorDelegationsRequest { + return { delegatorAddr: "", pagination: undefined }; +} export const QueryDelegatorDelegationsRequest = { encode(message: QueryDelegatorDelegationsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1102,7 +1024,7 @@ export const QueryDelegatorDelegationsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorDelegationsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegatorDelegationsRequest } as QueryDelegatorDelegationsRequest; + const message = createBaseQueryDelegatorDelegationsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1121,18 +1043,10 @@ export const QueryDelegatorDelegationsRequest = { }, fromJSON(object: any): QueryDelegatorDelegationsRequest { - const message = { ...baseQueryDelegatorDelegationsRequest } as QueryDelegatorDelegationsRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryDelegatorDelegationsRequest): unknown { @@ -1143,19 +1057,22 @@ export const QueryDelegatorDelegationsRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegatorDelegationsRequest { - const message = { ...baseQueryDelegatorDelegationsRequest } as QueryDelegatorDelegationsRequest; + fromPartial, I>>( + object: I, + ): QueryDelegatorDelegationsRequest { + const message = createBaseQueryDelegatorDelegationsRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegatorDelegationsResponse: object = {}; +function createBaseQueryDelegatorDelegationsResponse(): QueryDelegatorDelegationsResponse { + return { delegationResponses: [], pagination: undefined }; +} export const QueryDelegatorDelegationsResponse = { encode(message: QueryDelegatorDelegationsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1171,8 +1088,7 @@ export const QueryDelegatorDelegationsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorDelegationsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegatorDelegationsResponse } as QueryDelegatorDelegationsResponse; - message.delegationResponses = []; + const message = createBaseQueryDelegatorDelegationsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1191,19 +1107,12 @@ export const QueryDelegatorDelegationsResponse = { }, fromJSON(object: any): QueryDelegatorDelegationsResponse { - const message = { ...baseQueryDelegatorDelegationsResponse } as QueryDelegatorDelegationsResponse; - message.delegationResponses = []; - if (object.delegationResponses !== undefined && object.delegationResponses !== null) { - for (const e of object.delegationResponses) { - message.delegationResponses.push(DelegationResponse.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + delegationResponses: Array.isArray(object?.delegationResponses) + ? object.delegationResponses.map((e: any) => DelegationResponse.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryDelegatorDelegationsResponse): unknown { @@ -1220,24 +1129,23 @@ export const QueryDelegatorDelegationsResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegatorDelegationsResponse { - const message = { ...baseQueryDelegatorDelegationsResponse } as QueryDelegatorDelegationsResponse; - message.delegationResponses = []; - if (object.delegationResponses !== undefined && object.delegationResponses !== null) { - for (const e of object.delegationResponses) { - message.delegationResponses.push(DelegationResponse.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + fromPartial, I>>( + object: I, + ): QueryDelegatorDelegationsResponse { + const message = createBaseQueryDelegatorDelegationsResponse(); + message.delegationResponses = + object.delegationResponses?.map((e) => DelegationResponse.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegatorUnbondingDelegationsRequest: object = { delegatorAddr: "" }; +function createBaseQueryDelegatorUnbondingDelegationsRequest(): QueryDelegatorUnbondingDelegationsRequest { + return { delegatorAddr: "", pagination: undefined }; +} export const QueryDelegatorUnbondingDelegationsRequest = { encode( @@ -1256,9 +1164,7 @@ export const QueryDelegatorUnbondingDelegationsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorUnbondingDelegationsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryDelegatorUnbondingDelegationsRequest, - } as QueryDelegatorUnbondingDelegationsRequest; + const message = createBaseQueryDelegatorUnbondingDelegationsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1277,20 +1183,10 @@ export const QueryDelegatorUnbondingDelegationsRequest = { }, fromJSON(object: any): QueryDelegatorUnbondingDelegationsRequest { - const message = { - ...baseQueryDelegatorUnbondingDelegationsRequest, - } as QueryDelegatorUnbondingDelegationsRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryDelegatorUnbondingDelegationsRequest): unknown { @@ -1301,23 +1197,22 @@ export const QueryDelegatorUnbondingDelegationsRequest = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryDelegatorUnbondingDelegationsRequest { - const message = { - ...baseQueryDelegatorUnbondingDelegationsRequest, - } as QueryDelegatorUnbondingDelegationsRequest; + const message = createBaseQueryDelegatorUnbondingDelegationsRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegatorUnbondingDelegationsResponse: object = {}; +function createBaseQueryDelegatorUnbondingDelegationsResponse(): QueryDelegatorUnbondingDelegationsResponse { + return { unbondingResponses: [], pagination: undefined }; +} export const QueryDelegatorUnbondingDelegationsResponse = { encode( @@ -1336,10 +1231,7 @@ export const QueryDelegatorUnbondingDelegationsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorUnbondingDelegationsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseQueryDelegatorUnbondingDelegationsResponse, - } as QueryDelegatorUnbondingDelegationsResponse; - message.unbondingResponses = []; + const message = createBaseQueryDelegatorUnbondingDelegationsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1358,21 +1250,12 @@ export const QueryDelegatorUnbondingDelegationsResponse = { }, fromJSON(object: any): QueryDelegatorUnbondingDelegationsResponse { - const message = { - ...baseQueryDelegatorUnbondingDelegationsResponse, - } as QueryDelegatorUnbondingDelegationsResponse; - message.unbondingResponses = []; - if (object.unbondingResponses !== undefined && object.unbondingResponses !== null) { - for (const e of object.unbondingResponses) { - message.unbondingResponses.push(UnbondingDelegation.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + unbondingResponses: Array.isArray(object?.unbondingResponses) + ? object.unbondingResponses.map((e: any) => UnbondingDelegation.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryDelegatorUnbondingDelegationsResponse): unknown { @@ -1389,32 +1272,23 @@ export const QueryDelegatorUnbondingDelegationsResponse = { return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): QueryDelegatorUnbondingDelegationsResponse { - const message = { - ...baseQueryDelegatorUnbondingDelegationsResponse, - } as QueryDelegatorUnbondingDelegationsResponse; - message.unbondingResponses = []; - if (object.unbondingResponses !== undefined && object.unbondingResponses !== null) { - for (const e of object.unbondingResponses) { - message.unbondingResponses.push(UnbondingDelegation.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + const message = createBaseQueryDelegatorUnbondingDelegationsResponse(); + message.unbondingResponses = + object.unbondingResponses?.map((e) => UnbondingDelegation.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryRedelegationsRequest: object = { - delegatorAddr: "", - srcValidatorAddr: "", - dstValidatorAddr: "", -}; +function createBaseQueryRedelegationsRequest(): QueryRedelegationsRequest { + return { delegatorAddr: "", srcValidatorAddr: "", dstValidatorAddr: "", pagination: undefined }; +} export const QueryRedelegationsRequest = { encode(message: QueryRedelegationsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1436,7 +1310,7 @@ export const QueryRedelegationsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryRedelegationsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryRedelegationsRequest } as QueryRedelegationsRequest; + const message = createBaseQueryRedelegationsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1461,28 +1335,12 @@ export const QueryRedelegationsRequest = { }, fromJSON(object: any): QueryRedelegationsRequest { - const message = { ...baseQueryRedelegationsRequest } as QueryRedelegationsRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.srcValidatorAddr !== undefined && object.srcValidatorAddr !== null) { - message.srcValidatorAddr = String(object.srcValidatorAddr); - } else { - message.srcValidatorAddr = ""; - } - if (object.dstValidatorAddr !== undefined && object.dstValidatorAddr !== null) { - message.dstValidatorAddr = String(object.dstValidatorAddr); - } else { - message.dstValidatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + srcValidatorAddr: isSet(object.srcValidatorAddr) ? String(object.srcValidatorAddr) : "", + dstValidatorAddr: isSet(object.dstValidatorAddr) ? String(object.dstValidatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryRedelegationsRequest): unknown { @@ -1495,21 +1353,24 @@ export const QueryRedelegationsRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryRedelegationsRequest { - const message = { ...baseQueryRedelegationsRequest } as QueryRedelegationsRequest; + fromPartial, I>>( + object: I, + ): QueryRedelegationsRequest { + const message = createBaseQueryRedelegationsRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; message.srcValidatorAddr = object.srcValidatorAddr ?? ""; message.dstValidatorAddr = object.dstValidatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryRedelegationsResponse: object = {}; +function createBaseQueryRedelegationsResponse(): QueryRedelegationsResponse { + return { redelegationResponses: [], pagination: undefined }; +} export const QueryRedelegationsResponse = { encode(message: QueryRedelegationsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1525,8 +1386,7 @@ export const QueryRedelegationsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryRedelegationsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryRedelegationsResponse } as QueryRedelegationsResponse; - message.redelegationResponses = []; + const message = createBaseQueryRedelegationsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1545,19 +1405,12 @@ export const QueryRedelegationsResponse = { }, fromJSON(object: any): QueryRedelegationsResponse { - const message = { ...baseQueryRedelegationsResponse } as QueryRedelegationsResponse; - message.redelegationResponses = []; - if (object.redelegationResponses !== undefined && object.redelegationResponses !== null) { - for (const e of object.redelegationResponses) { - message.redelegationResponses.push(RedelegationResponse.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + redelegationResponses: Array.isArray(object?.redelegationResponses) + ? object.redelegationResponses.map((e: any) => RedelegationResponse.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryRedelegationsResponse): unknown { @@ -1574,24 +1427,23 @@ export const QueryRedelegationsResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryRedelegationsResponse { - const message = { ...baseQueryRedelegationsResponse } as QueryRedelegationsResponse; - message.redelegationResponses = []; - if (object.redelegationResponses !== undefined && object.redelegationResponses !== null) { - for (const e of object.redelegationResponses) { - message.redelegationResponses.push(RedelegationResponse.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + fromPartial, I>>( + object: I, + ): QueryRedelegationsResponse { + const message = createBaseQueryRedelegationsResponse(); + message.redelegationResponses = + object.redelegationResponses?.map((e) => RedelegationResponse.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegatorValidatorsRequest: object = { delegatorAddr: "" }; +function createBaseQueryDelegatorValidatorsRequest(): QueryDelegatorValidatorsRequest { + return { delegatorAddr: "", pagination: undefined }; +} export const QueryDelegatorValidatorsRequest = { encode(message: QueryDelegatorValidatorsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1607,7 +1459,7 @@ export const QueryDelegatorValidatorsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorValidatorsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegatorValidatorsRequest } as QueryDelegatorValidatorsRequest; + const message = createBaseQueryDelegatorValidatorsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1626,18 +1478,10 @@ export const QueryDelegatorValidatorsRequest = { }, fromJSON(object: any): QueryDelegatorValidatorsRequest { - const message = { ...baseQueryDelegatorValidatorsRequest } as QueryDelegatorValidatorsRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + pagination: isSet(object.pagination) ? PageRequest.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryDelegatorValidatorsRequest): unknown { @@ -1648,19 +1492,22 @@ export const QueryDelegatorValidatorsRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegatorValidatorsRequest { - const message = { ...baseQueryDelegatorValidatorsRequest } as QueryDelegatorValidatorsRequest; + fromPartial, I>>( + object: I, + ): QueryDelegatorValidatorsRequest { + const message = createBaseQueryDelegatorValidatorsRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageRequest.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegatorValidatorsResponse: object = {}; +function createBaseQueryDelegatorValidatorsResponse(): QueryDelegatorValidatorsResponse { + return { validators: [], pagination: undefined }; +} export const QueryDelegatorValidatorsResponse = { encode(message: QueryDelegatorValidatorsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1676,8 +1523,7 @@ export const QueryDelegatorValidatorsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorValidatorsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegatorValidatorsResponse } as QueryDelegatorValidatorsResponse; - message.validators = []; + const message = createBaseQueryDelegatorValidatorsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1696,19 +1542,12 @@ export const QueryDelegatorValidatorsResponse = { }, fromJSON(object: any): QueryDelegatorValidatorsResponse { - const message = { ...baseQueryDelegatorValidatorsResponse } as QueryDelegatorValidatorsResponse; - message.validators = []; - if (object.validators !== undefined && object.validators !== null) { - for (const e of object.validators) { - message.validators.push(Validator.fromJSON(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromJSON(object.pagination); - } else { - message.pagination = undefined; - } - return message; + return { + validators: Array.isArray(object?.validators) + ? object.validators.map((e: any) => Validator.fromJSON(e)) + : [], + pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined, + }; }, toJSON(message: QueryDelegatorValidatorsResponse): unknown { @@ -1723,24 +1562,22 @@ export const QueryDelegatorValidatorsResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegatorValidatorsResponse { - const message = { ...baseQueryDelegatorValidatorsResponse } as QueryDelegatorValidatorsResponse; - message.validators = []; - if (object.validators !== undefined && object.validators !== null) { - for (const e of object.validators) { - message.validators.push(Validator.fromPartial(e)); - } - } - if (object.pagination !== undefined && object.pagination !== null) { - message.pagination = PageResponse.fromPartial(object.pagination); - } else { - message.pagination = undefined; - } + fromPartial, I>>( + object: I, + ): QueryDelegatorValidatorsResponse { + const message = createBaseQueryDelegatorValidatorsResponse(); + message.validators = object.validators?.map((e) => Validator.fromPartial(e)) || []; + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined; return message; }, }; -const baseQueryDelegatorValidatorRequest: object = { delegatorAddr: "", validatorAddr: "" }; +function createBaseQueryDelegatorValidatorRequest(): QueryDelegatorValidatorRequest { + return { delegatorAddr: "", validatorAddr: "" }; +} export const QueryDelegatorValidatorRequest = { encode(message: QueryDelegatorValidatorRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1756,7 +1593,7 @@ export const QueryDelegatorValidatorRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorValidatorRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegatorValidatorRequest } as QueryDelegatorValidatorRequest; + const message = createBaseQueryDelegatorValidatorRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1775,18 +1612,10 @@ export const QueryDelegatorValidatorRequest = { }, fromJSON(object: any): QueryDelegatorValidatorRequest { - const message = { ...baseQueryDelegatorValidatorRequest } as QueryDelegatorValidatorRequest; - if (object.delegatorAddr !== undefined && object.delegatorAddr !== null) { - message.delegatorAddr = String(object.delegatorAddr); - } else { - message.delegatorAddr = ""; - } - if (object.validatorAddr !== undefined && object.validatorAddr !== null) { - message.validatorAddr = String(object.validatorAddr); - } else { - message.validatorAddr = ""; - } - return message; + return { + delegatorAddr: isSet(object.delegatorAddr) ? String(object.delegatorAddr) : "", + validatorAddr: isSet(object.validatorAddr) ? String(object.validatorAddr) : "", + }; }, toJSON(message: QueryDelegatorValidatorRequest): unknown { @@ -1796,15 +1625,19 @@ export const QueryDelegatorValidatorRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegatorValidatorRequest { - const message = { ...baseQueryDelegatorValidatorRequest } as QueryDelegatorValidatorRequest; + fromPartial, I>>( + object: I, + ): QueryDelegatorValidatorRequest { + const message = createBaseQueryDelegatorValidatorRequest(); message.delegatorAddr = object.delegatorAddr ?? ""; message.validatorAddr = object.validatorAddr ?? ""; return message; }, }; -const baseQueryDelegatorValidatorResponse: object = {}; +function createBaseQueryDelegatorValidatorResponse(): QueryDelegatorValidatorResponse { + return { validator: undefined }; +} export const QueryDelegatorValidatorResponse = { encode(message: QueryDelegatorValidatorResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1817,7 +1650,7 @@ export const QueryDelegatorValidatorResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryDelegatorValidatorResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryDelegatorValidatorResponse } as QueryDelegatorValidatorResponse; + const message = createBaseQueryDelegatorValidatorResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1833,13 +1666,9 @@ export const QueryDelegatorValidatorResponse = { }, fromJSON(object: any): QueryDelegatorValidatorResponse { - const message = { ...baseQueryDelegatorValidatorResponse } as QueryDelegatorValidatorResponse; - if (object.validator !== undefined && object.validator !== null) { - message.validator = Validator.fromJSON(object.validator); - } else { - message.validator = undefined; - } - return message; + return { + validator: isSet(object.validator) ? Validator.fromJSON(object.validator) : undefined, + }; }, toJSON(message: QueryDelegatorValidatorResponse): unknown { @@ -1849,18 +1678,21 @@ export const QueryDelegatorValidatorResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryDelegatorValidatorResponse { - const message = { ...baseQueryDelegatorValidatorResponse } as QueryDelegatorValidatorResponse; - if (object.validator !== undefined && object.validator !== null) { - message.validator = Validator.fromPartial(object.validator); - } else { - message.validator = undefined; - } + fromPartial, I>>( + object: I, + ): QueryDelegatorValidatorResponse { + const message = createBaseQueryDelegatorValidatorResponse(); + message.validator = + object.validator !== undefined && object.validator !== null + ? Validator.fromPartial(object.validator) + : undefined; return message; }, }; -const baseQueryHistoricalInfoRequest: object = { height: Long.ZERO }; +function createBaseQueryHistoricalInfoRequest(): QueryHistoricalInfoRequest { + return { height: Long.ZERO }; +} export const QueryHistoricalInfoRequest = { encode(message: QueryHistoricalInfoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1873,7 +1705,7 @@ export const QueryHistoricalInfoRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryHistoricalInfoRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryHistoricalInfoRequest } as QueryHistoricalInfoRequest; + const message = createBaseQueryHistoricalInfoRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1889,13 +1721,9 @@ export const QueryHistoricalInfoRequest = { }, fromJSON(object: any): QueryHistoricalInfoRequest { - const message = { ...baseQueryHistoricalInfoRequest } as QueryHistoricalInfoRequest; - if (object.height !== undefined && object.height !== null) { - message.height = Long.fromString(object.height); - } else { - message.height = Long.ZERO; - } - return message; + return { + height: isSet(object.height) ? Long.fromString(object.height) : Long.ZERO, + }; }, toJSON(message: QueryHistoricalInfoRequest): unknown { @@ -1904,18 +1732,19 @@ export const QueryHistoricalInfoRequest = { return obj; }, - fromPartial(object: DeepPartial): QueryHistoricalInfoRequest { - const message = { ...baseQueryHistoricalInfoRequest } as QueryHistoricalInfoRequest; - if (object.height !== undefined && object.height !== null) { - message.height = object.height as Long; - } else { - message.height = Long.ZERO; - } + fromPartial, I>>( + object: I, + ): QueryHistoricalInfoRequest { + const message = createBaseQueryHistoricalInfoRequest(); + message.height = + object.height !== undefined && object.height !== null ? Long.fromValue(object.height) : Long.ZERO; return message; }, }; -const baseQueryHistoricalInfoResponse: object = {}; +function createBaseQueryHistoricalInfoResponse(): QueryHistoricalInfoResponse { + return { hist: undefined }; +} export const QueryHistoricalInfoResponse = { encode(message: QueryHistoricalInfoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1928,7 +1757,7 @@ export const QueryHistoricalInfoResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryHistoricalInfoResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryHistoricalInfoResponse } as QueryHistoricalInfoResponse; + const message = createBaseQueryHistoricalInfoResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1944,13 +1773,9 @@ export const QueryHistoricalInfoResponse = { }, fromJSON(object: any): QueryHistoricalInfoResponse { - const message = { ...baseQueryHistoricalInfoResponse } as QueryHistoricalInfoResponse; - if (object.hist !== undefined && object.hist !== null) { - message.hist = HistoricalInfo.fromJSON(object.hist); - } else { - message.hist = undefined; - } - return message; + return { + hist: isSet(object.hist) ? HistoricalInfo.fromJSON(object.hist) : undefined, + }; }, toJSON(message: QueryHistoricalInfoResponse): unknown { @@ -1959,18 +1784,19 @@ export const QueryHistoricalInfoResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryHistoricalInfoResponse { - const message = { ...baseQueryHistoricalInfoResponse } as QueryHistoricalInfoResponse; - if (object.hist !== undefined && object.hist !== null) { - message.hist = HistoricalInfo.fromPartial(object.hist); - } else { - message.hist = undefined; - } + fromPartial, I>>( + object: I, + ): QueryHistoricalInfoResponse { + const message = createBaseQueryHistoricalInfoResponse(); + message.hist = + object.hist !== undefined && object.hist !== null ? HistoricalInfo.fromPartial(object.hist) : undefined; return message; }, }; -const baseQueryPoolRequest: object = {}; +function createBaseQueryPoolRequest(): QueryPoolRequest { + return {}; +} export const QueryPoolRequest = { encode(_: QueryPoolRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1980,7 +1806,7 @@ export const QueryPoolRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryPoolRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryPoolRequest } as QueryPoolRequest; + const message = createBaseQueryPoolRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1993,8 +1819,7 @@ export const QueryPoolRequest = { }, fromJSON(_: any): QueryPoolRequest { - const message = { ...baseQueryPoolRequest } as QueryPoolRequest; - return message; + return {}; }, toJSON(_: QueryPoolRequest): unknown { @@ -2002,13 +1827,15 @@ export const QueryPoolRequest = { return obj; }, - fromPartial(_: DeepPartial): QueryPoolRequest { - const message = { ...baseQueryPoolRequest } as QueryPoolRequest; + fromPartial, I>>(_: I): QueryPoolRequest { + const message = createBaseQueryPoolRequest(); return message; }, }; -const baseQueryPoolResponse: object = {}; +function createBaseQueryPoolResponse(): QueryPoolResponse { + return { pool: undefined }; +} export const QueryPoolResponse = { encode(message: QueryPoolResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2021,7 +1848,7 @@ export const QueryPoolResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryPoolResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryPoolResponse } as QueryPoolResponse; + const message = createBaseQueryPoolResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2037,13 +1864,9 @@ export const QueryPoolResponse = { }, fromJSON(object: any): QueryPoolResponse { - const message = { ...baseQueryPoolResponse } as QueryPoolResponse; - if (object.pool !== undefined && object.pool !== null) { - message.pool = Pool.fromJSON(object.pool); - } else { - message.pool = undefined; - } - return message; + return { + pool: isSet(object.pool) ? Pool.fromJSON(object.pool) : undefined, + }; }, toJSON(message: QueryPoolResponse): unknown { @@ -2052,18 +1875,17 @@ export const QueryPoolResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryPoolResponse { - const message = { ...baseQueryPoolResponse } as QueryPoolResponse; - if (object.pool !== undefined && object.pool !== null) { - message.pool = Pool.fromPartial(object.pool); - } else { - message.pool = undefined; - } + fromPartial, I>>(object: I): QueryPoolResponse { + const message = createBaseQueryPoolResponse(); + message.pool = + object.pool !== undefined && object.pool !== null ? Pool.fromPartial(object.pool) : undefined; return message; }, }; -const baseQueryParamsRequest: object = {}; +function createBaseQueryParamsRequest(): QueryParamsRequest { + return {}; +} export const QueryParamsRequest = { encode(_: QueryParamsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2073,7 +1895,7 @@ export const QueryParamsRequest = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryParamsRequest { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryParamsRequest } as QueryParamsRequest; + const message = createBaseQueryParamsRequest(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2086,8 +1908,7 @@ export const QueryParamsRequest = { }, fromJSON(_: any): QueryParamsRequest { - const message = { ...baseQueryParamsRequest } as QueryParamsRequest; - return message; + return {}; }, toJSON(_: QueryParamsRequest): unknown { @@ -2095,13 +1916,15 @@ export const QueryParamsRequest = { return obj; }, - fromPartial(_: DeepPartial): QueryParamsRequest { - const message = { ...baseQueryParamsRequest } as QueryParamsRequest; + fromPartial, I>>(_: I): QueryParamsRequest { + const message = createBaseQueryParamsRequest(); return message; }, }; -const baseQueryParamsResponse: object = {}; +function createBaseQueryParamsResponse(): QueryParamsResponse { + return { params: undefined }; +} export const QueryParamsResponse = { encode(message: QueryParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2114,7 +1937,7 @@ export const QueryParamsResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): QueryParamsResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseQueryParamsResponse } as QueryParamsResponse; + const message = createBaseQueryParamsResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2130,13 +1953,9 @@ export const QueryParamsResponse = { }, fromJSON(object: any): QueryParamsResponse { - const message = { ...baseQueryParamsResponse } as QueryParamsResponse; - if (object.params !== undefined && object.params !== null) { - message.params = Params.fromJSON(object.params); - } else { - message.params = undefined; - } - return message; + return { + params: isSet(object.params) ? Params.fromJSON(object.params) : undefined, + }; }, toJSON(message: QueryParamsResponse): unknown { @@ -2145,13 +1964,10 @@ export const QueryParamsResponse = { return obj; }, - fromPartial(object: DeepPartial): QueryParamsResponse { - const message = { ...baseQueryParamsResponse } as QueryParamsResponse; - if (object.params !== undefined && object.params !== null) { - message.params = Params.fromPartial(object.params); - } else { - message.params = undefined; - } + fromPartial, I>>(object: I): QueryParamsResponse { + const message = createBaseQueryParamsResponse(); + message.params = + object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined; return message; }, }; @@ -2320,9 +2136,12 @@ interface Rpc { request(service: string, method: string, data: Uint8Array): Promise; } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -2331,7 +2150,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/cosmos/staking/v1beta1/staking.ts b/src/codec/cosmos/staking/v1beta1/staking.ts index 70860217..42ae2497 100644 --- a/src/codec/cosmos/staking/v1beta1/staking.ts +++ b/src/codec/cosmos/staking/v1beta1/staking.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; import { Header } from "../../../tendermint/types/types"; import { Any } from "../../../google/protobuf/any"; import { Duration } from "../../../google/protobuf/duration"; @@ -294,7 +294,9 @@ export interface Pool { bondedTokens: string; } -const baseHistoricalInfo: object = {}; +function createBaseHistoricalInfo(): HistoricalInfo { + return { header: undefined, valset: [] }; +} export const HistoricalInfo = { encode(message: HistoricalInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -310,8 +312,7 @@ export const HistoricalInfo = { decode(input: _m0.Reader | Uint8Array, length?: number): HistoricalInfo { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseHistoricalInfo } as HistoricalInfo; - message.valset = []; + const message = createBaseHistoricalInfo(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -330,19 +331,10 @@ export const HistoricalInfo = { }, fromJSON(object: any): HistoricalInfo { - const message = { ...baseHistoricalInfo } as HistoricalInfo; - message.valset = []; - if (object.header !== undefined && object.header !== null) { - message.header = Header.fromJSON(object.header); - } else { - message.header = undefined; - } - if (object.valset !== undefined && object.valset !== null) { - for (const e of object.valset) { - message.valset.push(Validator.fromJSON(e)); - } - } - return message; + return { + header: isSet(object.header) ? Header.fromJSON(object.header) : undefined, + valset: Array.isArray(object?.valset) ? object.valset.map((e: any) => Validator.fromJSON(e)) : [], + }; }, toJSON(message: HistoricalInfo): unknown { @@ -356,24 +348,18 @@ export const HistoricalInfo = { return obj; }, - fromPartial(object: DeepPartial): HistoricalInfo { - const message = { ...baseHistoricalInfo } as HistoricalInfo; - if (object.header !== undefined && object.header !== null) { - message.header = Header.fromPartial(object.header); - } else { - message.header = undefined; - } - message.valset = []; - if (object.valset !== undefined && object.valset !== null) { - for (const e of object.valset) { - message.valset.push(Validator.fromPartial(e)); - } - } + fromPartial, I>>(object: I): HistoricalInfo { + const message = createBaseHistoricalInfo(); + message.header = + object.header !== undefined && object.header !== null ? Header.fromPartial(object.header) : undefined; + message.valset = object.valset?.map((e) => Validator.fromPartial(e)) || []; return message; }, }; -const baseCommissionRates: object = { rate: "", maxRate: "", maxChangeRate: "" }; +function createBaseCommissionRates(): CommissionRates { + return { rate: "", maxRate: "", maxChangeRate: "" }; +} export const CommissionRates = { encode(message: CommissionRates, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -392,7 +378,7 @@ export const CommissionRates = { decode(input: _m0.Reader | Uint8Array, length?: number): CommissionRates { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCommissionRates } as CommissionRates; + const message = createBaseCommissionRates(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -414,23 +400,11 @@ export const CommissionRates = { }, fromJSON(object: any): CommissionRates { - const message = { ...baseCommissionRates } as CommissionRates; - if (object.rate !== undefined && object.rate !== null) { - message.rate = String(object.rate); - } else { - message.rate = ""; - } - if (object.maxRate !== undefined && object.maxRate !== null) { - message.maxRate = String(object.maxRate); - } else { - message.maxRate = ""; - } - if (object.maxChangeRate !== undefined && object.maxChangeRate !== null) { - message.maxChangeRate = String(object.maxChangeRate); - } else { - message.maxChangeRate = ""; - } - return message; + return { + rate: isSet(object.rate) ? String(object.rate) : "", + maxRate: isSet(object.maxRate) ? String(object.maxRate) : "", + maxChangeRate: isSet(object.maxChangeRate) ? String(object.maxChangeRate) : "", + }; }, toJSON(message: CommissionRates): unknown { @@ -441,8 +415,8 @@ export const CommissionRates = { return obj; }, - fromPartial(object: DeepPartial): CommissionRates { - const message = { ...baseCommissionRates } as CommissionRates; + fromPartial, I>>(object: I): CommissionRates { + const message = createBaseCommissionRates(); message.rate = object.rate ?? ""; message.maxRate = object.maxRate ?? ""; message.maxChangeRate = object.maxChangeRate ?? ""; @@ -450,7 +424,9 @@ export const CommissionRates = { }, }; -const baseCommission: object = {}; +function createBaseCommission(): Commission { + return { commissionRates: undefined, updateTime: undefined }; +} export const Commission = { encode(message: Commission, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -466,7 +442,7 @@ export const Commission = { decode(input: _m0.Reader | Uint8Array, length?: number): Commission { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCommission } as Commission; + const message = createBaseCommission(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -485,18 +461,12 @@ export const Commission = { }, fromJSON(object: any): Commission { - const message = { ...baseCommission } as Commission; - if (object.commissionRates !== undefined && object.commissionRates !== null) { - message.commissionRates = CommissionRates.fromJSON(object.commissionRates); - } else { - message.commissionRates = undefined; - } - if (object.updateTime !== undefined && object.updateTime !== null) { - message.updateTime = fromJsonTimestamp(object.updateTime); - } else { - message.updateTime = undefined; - } - return message; + return { + commissionRates: isSet(object.commissionRates) + ? CommissionRates.fromJSON(object.commissionRates) + : undefined, + updateTime: isSet(object.updateTime) ? fromJsonTimestamp(object.updateTime) : undefined, + }; }, toJSON(message: Commission): unknown { @@ -509,19 +479,20 @@ export const Commission = { return obj; }, - fromPartial(object: DeepPartial): Commission { - const message = { ...baseCommission } as Commission; - if (object.commissionRates !== undefined && object.commissionRates !== null) { - message.commissionRates = CommissionRates.fromPartial(object.commissionRates); - } else { - message.commissionRates = undefined; - } + fromPartial, I>>(object: I): Commission { + const message = createBaseCommission(); + message.commissionRates = + object.commissionRates !== undefined && object.commissionRates !== null + ? CommissionRates.fromPartial(object.commissionRates) + : undefined; message.updateTime = object.updateTime ?? undefined; return message; }, }; -const baseDescription: object = { moniker: "", identity: "", website: "", securityContact: "", details: "" }; +function createBaseDescription(): Description { + return { moniker: "", identity: "", website: "", securityContact: "", details: "" }; +} export const Description = { encode(message: Description, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -546,7 +517,7 @@ export const Description = { decode(input: _m0.Reader | Uint8Array, length?: number): Description { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDescription } as Description; + const message = createBaseDescription(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -574,33 +545,13 @@ export const Description = { }, fromJSON(object: any): Description { - const message = { ...baseDescription } as Description; - if (object.moniker !== undefined && object.moniker !== null) { - message.moniker = String(object.moniker); - } else { - message.moniker = ""; - } - if (object.identity !== undefined && object.identity !== null) { - message.identity = String(object.identity); - } else { - message.identity = ""; - } - if (object.website !== undefined && object.website !== null) { - message.website = String(object.website); - } else { - message.website = ""; - } - if (object.securityContact !== undefined && object.securityContact !== null) { - message.securityContact = String(object.securityContact); - } else { - message.securityContact = ""; - } - if (object.details !== undefined && object.details !== null) { - message.details = String(object.details); - } else { - message.details = ""; - } - return message; + return { + moniker: isSet(object.moniker) ? String(object.moniker) : "", + identity: isSet(object.identity) ? String(object.identity) : "", + website: isSet(object.website) ? String(object.website) : "", + securityContact: isSet(object.securityContact) ? String(object.securityContact) : "", + details: isSet(object.details) ? String(object.details) : "", + }; }, toJSON(message: Description): unknown { @@ -613,8 +564,8 @@ export const Description = { return obj; }, - fromPartial(object: DeepPartial): Description { - const message = { ...baseDescription } as Description; + fromPartial, I>>(object: I): Description { + const message = createBaseDescription(); message.moniker = object.moniker ?? ""; message.identity = object.identity ?? ""; message.website = object.website ?? ""; @@ -624,15 +575,21 @@ export const Description = { }, }; -const baseValidator: object = { - operatorAddress: "", - jailed: false, - status: 0, - tokens: "", - delegatorShares: "", - unbondingHeight: Long.ZERO, - minSelfDelegation: "", -}; +function createBaseValidator(): Validator { + return { + operatorAddress: "", + consensusPubkey: undefined, + jailed: false, + status: 0, + tokens: "", + delegatorShares: "", + description: undefined, + unbondingHeight: Long.ZERO, + unbondingTime: undefined, + commission: undefined, + minSelfDelegation: "", + }; +} export const Validator = { encode(message: Validator, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -675,7 +632,7 @@ export const Validator = { decode(input: _m0.Reader | Uint8Array, length?: number): Validator { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseValidator } as Validator; + const message = createBaseValidator(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -721,63 +678,19 @@ export const Validator = { }, fromJSON(object: any): Validator { - const message = { ...baseValidator } as Validator; - if (object.operatorAddress !== undefined && object.operatorAddress !== null) { - message.operatorAddress = String(object.operatorAddress); - } else { - message.operatorAddress = ""; - } - if (object.consensusPubkey !== undefined && object.consensusPubkey !== null) { - message.consensusPubkey = Any.fromJSON(object.consensusPubkey); - } else { - message.consensusPubkey = undefined; - } - if (object.jailed !== undefined && object.jailed !== null) { - message.jailed = Boolean(object.jailed); - } else { - message.jailed = false; - } - if (object.status !== undefined && object.status !== null) { - message.status = bondStatusFromJSON(object.status); - } else { - message.status = 0; - } - if (object.tokens !== undefined && object.tokens !== null) { - message.tokens = String(object.tokens); - } else { - message.tokens = ""; - } - if (object.delegatorShares !== undefined && object.delegatorShares !== null) { - message.delegatorShares = String(object.delegatorShares); - } else { - message.delegatorShares = ""; - } - if (object.description !== undefined && object.description !== null) { - message.description = Description.fromJSON(object.description); - } else { - message.description = undefined; - } - if (object.unbondingHeight !== undefined && object.unbondingHeight !== null) { - message.unbondingHeight = Long.fromString(object.unbondingHeight); - } else { - message.unbondingHeight = Long.ZERO; - } - if (object.unbondingTime !== undefined && object.unbondingTime !== null) { - message.unbondingTime = fromJsonTimestamp(object.unbondingTime); - } else { - message.unbondingTime = undefined; - } - if (object.commission !== undefined && object.commission !== null) { - message.commission = Commission.fromJSON(object.commission); - } else { - message.commission = undefined; - } - if (object.minSelfDelegation !== undefined && object.minSelfDelegation !== null) { - message.minSelfDelegation = String(object.minSelfDelegation); - } else { - message.minSelfDelegation = ""; - } - return message; + return { + operatorAddress: isSet(object.operatorAddress) ? String(object.operatorAddress) : "", + consensusPubkey: isSet(object.consensusPubkey) ? Any.fromJSON(object.consensusPubkey) : undefined, + jailed: isSet(object.jailed) ? Boolean(object.jailed) : false, + status: isSet(object.status) ? bondStatusFromJSON(object.status) : 0, + tokens: isSet(object.tokens) ? String(object.tokens) : "", + delegatorShares: isSet(object.delegatorShares) ? String(object.delegatorShares) : "", + description: isSet(object.description) ? Description.fromJSON(object.description) : undefined, + unbondingHeight: isSet(object.unbondingHeight) ? Long.fromString(object.unbondingHeight) : Long.ZERO, + unbondingTime: isSet(object.unbondingTime) ? fromJsonTimestamp(object.unbondingTime) : undefined, + commission: isSet(object.commission) ? Commission.fromJSON(object.commission) : undefined, + minSelfDelegation: isSet(object.minSelfDelegation) ? String(object.minSelfDelegation) : "", + }; }, toJSON(message: Validator): unknown { @@ -800,40 +713,38 @@ export const Validator = { return obj; }, - fromPartial(object: DeepPartial): Validator { - const message = { ...baseValidator } as Validator; + fromPartial, I>>(object: I): Validator { + const message = createBaseValidator(); message.operatorAddress = object.operatorAddress ?? ""; - if (object.consensusPubkey !== undefined && object.consensusPubkey !== null) { - message.consensusPubkey = Any.fromPartial(object.consensusPubkey); - } else { - message.consensusPubkey = undefined; - } + message.consensusPubkey = + object.consensusPubkey !== undefined && object.consensusPubkey !== null + ? Any.fromPartial(object.consensusPubkey) + : undefined; message.jailed = object.jailed ?? false; message.status = object.status ?? 0; message.tokens = object.tokens ?? ""; message.delegatorShares = object.delegatorShares ?? ""; - if (object.description !== undefined && object.description !== null) { - message.description = Description.fromPartial(object.description); - } else { - message.description = undefined; - } - if (object.unbondingHeight !== undefined && object.unbondingHeight !== null) { - message.unbondingHeight = object.unbondingHeight as Long; - } else { - message.unbondingHeight = Long.ZERO; - } + message.description = + object.description !== undefined && object.description !== null + ? Description.fromPartial(object.description) + : undefined; + message.unbondingHeight = + object.unbondingHeight !== undefined && object.unbondingHeight !== null + ? Long.fromValue(object.unbondingHeight) + : Long.ZERO; message.unbondingTime = object.unbondingTime ?? undefined; - if (object.commission !== undefined && object.commission !== null) { - message.commission = Commission.fromPartial(object.commission); - } else { - message.commission = undefined; - } + message.commission = + object.commission !== undefined && object.commission !== null + ? Commission.fromPartial(object.commission) + : undefined; message.minSelfDelegation = object.minSelfDelegation ?? ""; return message; }, }; -const baseValAddresses: object = { addresses: "" }; +function createBaseValAddresses(): ValAddresses { + return { addresses: [] }; +} export const ValAddresses = { encode(message: ValAddresses, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -846,8 +757,7 @@ export const ValAddresses = { decode(input: _m0.Reader | Uint8Array, length?: number): ValAddresses { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseValAddresses } as ValAddresses; - message.addresses = []; + const message = createBaseValAddresses(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -863,14 +773,9 @@ export const ValAddresses = { }, fromJSON(object: any): ValAddresses { - const message = { ...baseValAddresses } as ValAddresses; - message.addresses = []; - if (object.addresses !== undefined && object.addresses !== null) { - for (const e of object.addresses) { - message.addresses.push(String(e)); - } - } - return message; + return { + addresses: Array.isArray(object?.addresses) ? object.addresses.map((e: any) => String(e)) : [], + }; }, toJSON(message: ValAddresses): unknown { @@ -883,19 +788,16 @@ export const ValAddresses = { return obj; }, - fromPartial(object: DeepPartial): ValAddresses { - const message = { ...baseValAddresses } as ValAddresses; - message.addresses = []; - if (object.addresses !== undefined && object.addresses !== null) { - for (const e of object.addresses) { - message.addresses.push(e); - } - } + fromPartial, I>>(object: I): ValAddresses { + const message = createBaseValAddresses(); + message.addresses = object.addresses?.map((e) => e) || []; return message; }, }; -const baseDVPair: object = { delegatorAddress: "", validatorAddress: "" }; +function createBaseDVPair(): DVPair { + return { delegatorAddress: "", validatorAddress: "" }; +} export const DVPair = { encode(message: DVPair, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -911,7 +813,7 @@ export const DVPair = { decode(input: _m0.Reader | Uint8Array, length?: number): DVPair { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDVPair } as DVPair; + const message = createBaseDVPair(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -930,18 +832,10 @@ export const DVPair = { }, fromJSON(object: any): DVPair { - const message = { ...baseDVPair } as DVPair; - if (object.delegatorAddress !== undefined && object.delegatorAddress !== null) { - message.delegatorAddress = String(object.delegatorAddress); - } else { - message.delegatorAddress = ""; - } - if (object.validatorAddress !== undefined && object.validatorAddress !== null) { - message.validatorAddress = String(object.validatorAddress); - } else { - message.validatorAddress = ""; - } - return message; + return { + delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", + validatorAddress: isSet(object.validatorAddress) ? String(object.validatorAddress) : "", + }; }, toJSON(message: DVPair): unknown { @@ -951,15 +845,17 @@ export const DVPair = { return obj; }, - fromPartial(object: DeepPartial): DVPair { - const message = { ...baseDVPair } as DVPair; + fromPartial, I>>(object: I): DVPair { + const message = createBaseDVPair(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorAddress = object.validatorAddress ?? ""; return message; }, }; -const baseDVPairs: object = {}; +function createBaseDVPairs(): DVPairs { + return { pairs: [] }; +} export const DVPairs = { encode(message: DVPairs, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -972,8 +868,7 @@ export const DVPairs = { decode(input: _m0.Reader | Uint8Array, length?: number): DVPairs { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDVPairs } as DVPairs; - message.pairs = []; + const message = createBaseDVPairs(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -989,14 +884,9 @@ export const DVPairs = { }, fromJSON(object: any): DVPairs { - const message = { ...baseDVPairs } as DVPairs; - message.pairs = []; - if (object.pairs !== undefined && object.pairs !== null) { - for (const e of object.pairs) { - message.pairs.push(DVPair.fromJSON(e)); - } - } - return message; + return { + pairs: Array.isArray(object?.pairs) ? object.pairs.map((e: any) => DVPair.fromJSON(e)) : [], + }; }, toJSON(message: DVPairs): unknown { @@ -1009,19 +899,16 @@ export const DVPairs = { return obj; }, - fromPartial(object: DeepPartial): DVPairs { - const message = { ...baseDVPairs } as DVPairs; - message.pairs = []; - if (object.pairs !== undefined && object.pairs !== null) { - for (const e of object.pairs) { - message.pairs.push(DVPair.fromPartial(e)); - } - } + fromPartial, I>>(object: I): DVPairs { + const message = createBaseDVPairs(); + message.pairs = object.pairs?.map((e) => DVPair.fromPartial(e)) || []; return message; }, }; -const baseDVVTriplet: object = { delegatorAddress: "", validatorSrcAddress: "", validatorDstAddress: "" }; +function createBaseDVVTriplet(): DVVTriplet { + return { delegatorAddress: "", validatorSrcAddress: "", validatorDstAddress: "" }; +} export const DVVTriplet = { encode(message: DVVTriplet, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1040,7 +927,7 @@ export const DVVTriplet = { decode(input: _m0.Reader | Uint8Array, length?: number): DVVTriplet { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDVVTriplet } as DVVTriplet; + const message = createBaseDVVTriplet(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1062,23 +949,11 @@ export const DVVTriplet = { }, fromJSON(object: any): DVVTriplet { - const message = { ...baseDVVTriplet } as DVVTriplet; - if (object.delegatorAddress !== undefined && object.delegatorAddress !== null) { - message.delegatorAddress = String(object.delegatorAddress); - } else { - message.delegatorAddress = ""; - } - if (object.validatorSrcAddress !== undefined && object.validatorSrcAddress !== null) { - message.validatorSrcAddress = String(object.validatorSrcAddress); - } else { - message.validatorSrcAddress = ""; - } - if (object.validatorDstAddress !== undefined && object.validatorDstAddress !== null) { - message.validatorDstAddress = String(object.validatorDstAddress); - } else { - message.validatorDstAddress = ""; - } - return message; + return { + delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", + validatorSrcAddress: isSet(object.validatorSrcAddress) ? String(object.validatorSrcAddress) : "", + validatorDstAddress: isSet(object.validatorDstAddress) ? String(object.validatorDstAddress) : "", + }; }, toJSON(message: DVVTriplet): unknown { @@ -1089,8 +964,8 @@ export const DVVTriplet = { return obj; }, - fromPartial(object: DeepPartial): DVVTriplet { - const message = { ...baseDVVTriplet } as DVVTriplet; + fromPartial, I>>(object: I): DVVTriplet { + const message = createBaseDVVTriplet(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorSrcAddress = object.validatorSrcAddress ?? ""; message.validatorDstAddress = object.validatorDstAddress ?? ""; @@ -1098,7 +973,9 @@ export const DVVTriplet = { }, }; -const baseDVVTriplets: object = {}; +function createBaseDVVTriplets(): DVVTriplets { + return { triplets: [] }; +} export const DVVTriplets = { encode(message: DVVTriplets, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1111,8 +988,7 @@ export const DVVTriplets = { decode(input: _m0.Reader | Uint8Array, length?: number): DVVTriplets { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDVVTriplets } as DVVTriplets; - message.triplets = []; + const message = createBaseDVVTriplets(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1128,14 +1004,11 @@ export const DVVTriplets = { }, fromJSON(object: any): DVVTriplets { - const message = { ...baseDVVTriplets } as DVVTriplets; - message.triplets = []; - if (object.triplets !== undefined && object.triplets !== null) { - for (const e of object.triplets) { - message.triplets.push(DVVTriplet.fromJSON(e)); - } - } - return message; + return { + triplets: Array.isArray(object?.triplets) + ? object.triplets.map((e: any) => DVVTriplet.fromJSON(e)) + : [], + }; }, toJSON(message: DVVTriplets): unknown { @@ -1148,19 +1021,16 @@ export const DVVTriplets = { return obj; }, - fromPartial(object: DeepPartial): DVVTriplets { - const message = { ...baseDVVTriplets } as DVVTriplets; - message.triplets = []; - if (object.triplets !== undefined && object.triplets !== null) { - for (const e of object.triplets) { - message.triplets.push(DVVTriplet.fromPartial(e)); - } - } + fromPartial, I>>(object: I): DVVTriplets { + const message = createBaseDVVTriplets(); + message.triplets = object.triplets?.map((e) => DVVTriplet.fromPartial(e)) || []; return message; }, }; -const baseDelegation: object = { delegatorAddress: "", validatorAddress: "", shares: "" }; +function createBaseDelegation(): Delegation { + return { delegatorAddress: "", validatorAddress: "", shares: "" }; +} export const Delegation = { encode(message: Delegation, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1179,7 +1049,7 @@ export const Delegation = { decode(input: _m0.Reader | Uint8Array, length?: number): Delegation { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDelegation } as Delegation; + const message = createBaseDelegation(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1201,23 +1071,11 @@ export const Delegation = { }, fromJSON(object: any): Delegation { - const message = { ...baseDelegation } as Delegation; - if (object.delegatorAddress !== undefined && object.delegatorAddress !== null) { - message.delegatorAddress = String(object.delegatorAddress); - } else { - message.delegatorAddress = ""; - } - if (object.validatorAddress !== undefined && object.validatorAddress !== null) { - message.validatorAddress = String(object.validatorAddress); - } else { - message.validatorAddress = ""; - } - if (object.shares !== undefined && object.shares !== null) { - message.shares = String(object.shares); - } else { - message.shares = ""; - } - return message; + return { + delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", + validatorAddress: isSet(object.validatorAddress) ? String(object.validatorAddress) : "", + shares: isSet(object.shares) ? String(object.shares) : "", + }; }, toJSON(message: Delegation): unknown { @@ -1228,8 +1086,8 @@ export const Delegation = { return obj; }, - fromPartial(object: DeepPartial): Delegation { - const message = { ...baseDelegation } as Delegation; + fromPartial, I>>(object: I): Delegation { + const message = createBaseDelegation(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorAddress = object.validatorAddress ?? ""; message.shares = object.shares ?? ""; @@ -1237,7 +1095,9 @@ export const Delegation = { }, }; -const baseUnbondingDelegation: object = { delegatorAddress: "", validatorAddress: "" }; +function createBaseUnbondingDelegation(): UnbondingDelegation { + return { delegatorAddress: "", validatorAddress: "", entries: [] }; +} export const UnbondingDelegation = { encode(message: UnbondingDelegation, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1256,8 +1116,7 @@ export const UnbondingDelegation = { decode(input: _m0.Reader | Uint8Array, length?: number): UnbondingDelegation { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseUnbondingDelegation } as UnbondingDelegation; - message.entries = []; + const message = createBaseUnbondingDelegation(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1279,24 +1138,13 @@ export const UnbondingDelegation = { }, fromJSON(object: any): UnbondingDelegation { - const message = { ...baseUnbondingDelegation } as UnbondingDelegation; - message.entries = []; - if (object.delegatorAddress !== undefined && object.delegatorAddress !== null) { - message.delegatorAddress = String(object.delegatorAddress); - } else { - message.delegatorAddress = ""; - } - if (object.validatorAddress !== undefined && object.validatorAddress !== null) { - message.validatorAddress = String(object.validatorAddress); - } else { - message.validatorAddress = ""; - } - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(UnbondingDelegationEntry.fromJSON(e)); - } - } - return message; + return { + delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", + validatorAddress: isSet(object.validatorAddress) ? String(object.validatorAddress) : "", + entries: Array.isArray(object?.entries) + ? object.entries.map((e: any) => UnbondingDelegationEntry.fromJSON(e)) + : [], + }; }, toJSON(message: UnbondingDelegation): unknown { @@ -1311,21 +1159,18 @@ export const UnbondingDelegation = { return obj; }, - fromPartial(object: DeepPartial): UnbondingDelegation { - const message = { ...baseUnbondingDelegation } as UnbondingDelegation; + fromPartial, I>>(object: I): UnbondingDelegation { + const message = createBaseUnbondingDelegation(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorAddress = object.validatorAddress ?? ""; - message.entries = []; - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(UnbondingDelegationEntry.fromPartial(e)); - } - } + message.entries = object.entries?.map((e) => UnbondingDelegationEntry.fromPartial(e)) || []; return message; }, }; -const baseUnbondingDelegationEntry: object = { creationHeight: Long.ZERO, initialBalance: "", balance: "" }; +function createBaseUnbondingDelegationEntry(): UnbondingDelegationEntry { + return { creationHeight: Long.ZERO, completionTime: undefined, initialBalance: "", balance: "" }; +} export const UnbondingDelegationEntry = { encode(message: UnbondingDelegationEntry, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1347,7 +1192,7 @@ export const UnbondingDelegationEntry = { decode(input: _m0.Reader | Uint8Array, length?: number): UnbondingDelegationEntry { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseUnbondingDelegationEntry } as UnbondingDelegationEntry; + const message = createBaseUnbondingDelegationEntry(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1372,28 +1217,12 @@ export const UnbondingDelegationEntry = { }, fromJSON(object: any): UnbondingDelegationEntry { - const message = { ...baseUnbondingDelegationEntry } as UnbondingDelegationEntry; - if (object.creationHeight !== undefined && object.creationHeight !== null) { - message.creationHeight = Long.fromString(object.creationHeight); - } else { - message.creationHeight = Long.ZERO; - } - if (object.completionTime !== undefined && object.completionTime !== null) { - message.completionTime = fromJsonTimestamp(object.completionTime); - } else { - message.completionTime = undefined; - } - if (object.initialBalance !== undefined && object.initialBalance !== null) { - message.initialBalance = String(object.initialBalance); - } else { - message.initialBalance = ""; - } - if (object.balance !== undefined && object.balance !== null) { - message.balance = String(object.balance); - } else { - message.balance = ""; - } - return message; + return { + creationHeight: isSet(object.creationHeight) ? Long.fromString(object.creationHeight) : Long.ZERO, + completionTime: isSet(object.completionTime) ? fromJsonTimestamp(object.completionTime) : undefined, + initialBalance: isSet(object.initialBalance) ? String(object.initialBalance) : "", + balance: isSet(object.balance) ? String(object.balance) : "", + }; }, toJSON(message: UnbondingDelegationEntry): unknown { @@ -1406,13 +1235,14 @@ export const UnbondingDelegationEntry = { return obj; }, - fromPartial(object: DeepPartial): UnbondingDelegationEntry { - const message = { ...baseUnbondingDelegationEntry } as UnbondingDelegationEntry; - if (object.creationHeight !== undefined && object.creationHeight !== null) { - message.creationHeight = object.creationHeight as Long; - } else { - message.creationHeight = Long.ZERO; - } + fromPartial, I>>( + object: I, + ): UnbondingDelegationEntry { + const message = createBaseUnbondingDelegationEntry(); + message.creationHeight = + object.creationHeight !== undefined && object.creationHeight !== null + ? Long.fromValue(object.creationHeight) + : Long.ZERO; message.completionTime = object.completionTime ?? undefined; message.initialBalance = object.initialBalance ?? ""; message.balance = object.balance ?? ""; @@ -1420,7 +1250,9 @@ export const UnbondingDelegationEntry = { }, }; -const baseRedelegationEntry: object = { creationHeight: Long.ZERO, initialBalance: "", sharesDst: "" }; +function createBaseRedelegationEntry(): RedelegationEntry { + return { creationHeight: Long.ZERO, completionTime: undefined, initialBalance: "", sharesDst: "" }; +} export const RedelegationEntry = { encode(message: RedelegationEntry, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1442,7 +1274,7 @@ export const RedelegationEntry = { decode(input: _m0.Reader | Uint8Array, length?: number): RedelegationEntry { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseRedelegationEntry } as RedelegationEntry; + const message = createBaseRedelegationEntry(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1467,28 +1299,12 @@ export const RedelegationEntry = { }, fromJSON(object: any): RedelegationEntry { - const message = { ...baseRedelegationEntry } as RedelegationEntry; - if (object.creationHeight !== undefined && object.creationHeight !== null) { - message.creationHeight = Long.fromString(object.creationHeight); - } else { - message.creationHeight = Long.ZERO; - } - if (object.completionTime !== undefined && object.completionTime !== null) { - message.completionTime = fromJsonTimestamp(object.completionTime); - } else { - message.completionTime = undefined; - } - if (object.initialBalance !== undefined && object.initialBalance !== null) { - message.initialBalance = String(object.initialBalance); - } else { - message.initialBalance = ""; - } - if (object.sharesDst !== undefined && object.sharesDst !== null) { - message.sharesDst = String(object.sharesDst); - } else { - message.sharesDst = ""; - } - return message; + return { + creationHeight: isSet(object.creationHeight) ? Long.fromString(object.creationHeight) : Long.ZERO, + completionTime: isSet(object.completionTime) ? fromJsonTimestamp(object.completionTime) : undefined, + initialBalance: isSet(object.initialBalance) ? String(object.initialBalance) : "", + sharesDst: isSet(object.sharesDst) ? String(object.sharesDst) : "", + }; }, toJSON(message: RedelegationEntry): unknown { @@ -1501,13 +1317,12 @@ export const RedelegationEntry = { return obj; }, - fromPartial(object: DeepPartial): RedelegationEntry { - const message = { ...baseRedelegationEntry } as RedelegationEntry; - if (object.creationHeight !== undefined && object.creationHeight !== null) { - message.creationHeight = object.creationHeight as Long; - } else { - message.creationHeight = Long.ZERO; - } + fromPartial, I>>(object: I): RedelegationEntry { + const message = createBaseRedelegationEntry(); + message.creationHeight = + object.creationHeight !== undefined && object.creationHeight !== null + ? Long.fromValue(object.creationHeight) + : Long.ZERO; message.completionTime = object.completionTime ?? undefined; message.initialBalance = object.initialBalance ?? ""; message.sharesDst = object.sharesDst ?? ""; @@ -1515,7 +1330,9 @@ export const RedelegationEntry = { }, }; -const baseRedelegation: object = { delegatorAddress: "", validatorSrcAddress: "", validatorDstAddress: "" }; +function createBaseRedelegation(): Redelegation { + return { delegatorAddress: "", validatorSrcAddress: "", validatorDstAddress: "", entries: [] }; +} export const Redelegation = { encode(message: Redelegation, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1537,8 +1354,7 @@ export const Redelegation = { decode(input: _m0.Reader | Uint8Array, length?: number): Redelegation { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseRedelegation } as Redelegation; - message.entries = []; + const message = createBaseRedelegation(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1563,29 +1379,14 @@ export const Redelegation = { }, fromJSON(object: any): Redelegation { - const message = { ...baseRedelegation } as Redelegation; - message.entries = []; - if (object.delegatorAddress !== undefined && object.delegatorAddress !== null) { - message.delegatorAddress = String(object.delegatorAddress); - } else { - message.delegatorAddress = ""; - } - if (object.validatorSrcAddress !== undefined && object.validatorSrcAddress !== null) { - message.validatorSrcAddress = String(object.validatorSrcAddress); - } else { - message.validatorSrcAddress = ""; - } - if (object.validatorDstAddress !== undefined && object.validatorDstAddress !== null) { - message.validatorDstAddress = String(object.validatorDstAddress); - } else { - message.validatorDstAddress = ""; - } - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(RedelegationEntry.fromJSON(e)); - } - } - return message; + return { + delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", + validatorSrcAddress: isSet(object.validatorSrcAddress) ? String(object.validatorSrcAddress) : "", + validatorDstAddress: isSet(object.validatorDstAddress) ? String(object.validatorDstAddress) : "", + entries: Array.isArray(object?.entries) + ? object.entries.map((e: any) => RedelegationEntry.fromJSON(e)) + : [], + }; }, toJSON(message: Redelegation): unknown { @@ -1601,22 +1402,19 @@ export const Redelegation = { return obj; }, - fromPartial(object: DeepPartial): Redelegation { - const message = { ...baseRedelegation } as Redelegation; + fromPartial, I>>(object: I): Redelegation { + const message = createBaseRedelegation(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorSrcAddress = object.validatorSrcAddress ?? ""; message.validatorDstAddress = object.validatorDstAddress ?? ""; - message.entries = []; - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(RedelegationEntry.fromPartial(e)); - } - } + message.entries = object.entries?.map((e) => RedelegationEntry.fromPartial(e)) || []; return message; }, }; -const baseParams: object = { maxValidators: 0, maxEntries: 0, historicalEntries: 0, bondDenom: "" }; +function createBaseParams(): Params { + return { unbondingTime: undefined, maxValidators: 0, maxEntries: 0, historicalEntries: 0, bondDenom: "" }; +} export const Params = { encode(message: Params, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1641,7 +1439,7 @@ export const Params = { decode(input: _m0.Reader | Uint8Array, length?: number): Params { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseParams } as Params; + const message = createBaseParams(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1669,53 +1467,33 @@ export const Params = { }, fromJSON(object: any): Params { - const message = { ...baseParams } as Params; - if (object.unbondingTime !== undefined && object.unbondingTime !== null) { - message.unbondingTime = Duration.fromJSON(object.unbondingTime); - } else { - message.unbondingTime = undefined; - } - if (object.maxValidators !== undefined && object.maxValidators !== null) { - message.maxValidators = Number(object.maxValidators); - } else { - message.maxValidators = 0; - } - if (object.maxEntries !== undefined && object.maxEntries !== null) { - message.maxEntries = Number(object.maxEntries); - } else { - message.maxEntries = 0; - } - if (object.historicalEntries !== undefined && object.historicalEntries !== null) { - message.historicalEntries = Number(object.historicalEntries); - } else { - message.historicalEntries = 0; - } - if (object.bondDenom !== undefined && object.bondDenom !== null) { - message.bondDenom = String(object.bondDenom); - } else { - message.bondDenom = ""; - } - return message; + return { + unbondingTime: isSet(object.unbondingTime) ? Duration.fromJSON(object.unbondingTime) : undefined, + maxValidators: isSet(object.maxValidators) ? Number(object.maxValidators) : 0, + maxEntries: isSet(object.maxEntries) ? Number(object.maxEntries) : 0, + historicalEntries: isSet(object.historicalEntries) ? Number(object.historicalEntries) : 0, + bondDenom: isSet(object.bondDenom) ? String(object.bondDenom) : "", + }; }, toJSON(message: Params): unknown { const obj: any = {}; message.unbondingTime !== undefined && (obj.unbondingTime = message.unbondingTime ? Duration.toJSON(message.unbondingTime) : undefined); - message.maxValidators !== undefined && (obj.maxValidators = message.maxValidators); - message.maxEntries !== undefined && (obj.maxEntries = message.maxEntries); - message.historicalEntries !== undefined && (obj.historicalEntries = message.historicalEntries); + message.maxValidators !== undefined && (obj.maxValidators = Math.round(message.maxValidators)); + message.maxEntries !== undefined && (obj.maxEntries = Math.round(message.maxEntries)); + message.historicalEntries !== undefined && + (obj.historicalEntries = Math.round(message.historicalEntries)); message.bondDenom !== undefined && (obj.bondDenom = message.bondDenom); return obj; }, - fromPartial(object: DeepPartial): Params { - const message = { ...baseParams } as Params; - if (object.unbondingTime !== undefined && object.unbondingTime !== null) { - message.unbondingTime = Duration.fromPartial(object.unbondingTime); - } else { - message.unbondingTime = undefined; - } + fromPartial, I>>(object: I): Params { + const message = createBaseParams(); + message.unbondingTime = + object.unbondingTime !== undefined && object.unbondingTime !== null + ? Duration.fromPartial(object.unbondingTime) + : undefined; message.maxValidators = object.maxValidators ?? 0; message.maxEntries = object.maxEntries ?? 0; message.historicalEntries = object.historicalEntries ?? 0; @@ -1724,7 +1502,9 @@ export const Params = { }, }; -const baseDelegationResponse: object = {}; +function createBaseDelegationResponse(): DelegationResponse { + return { delegation: undefined, balance: undefined }; +} export const DelegationResponse = { encode(message: DelegationResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1740,7 +1520,7 @@ export const DelegationResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): DelegationResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDelegationResponse } as DelegationResponse; + const message = createBaseDelegationResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1759,18 +1539,10 @@ export const DelegationResponse = { }, fromJSON(object: any): DelegationResponse { - const message = { ...baseDelegationResponse } as DelegationResponse; - if (object.delegation !== undefined && object.delegation !== null) { - message.delegation = Delegation.fromJSON(object.delegation); - } else { - message.delegation = undefined; - } - if (object.balance !== undefined && object.balance !== null) { - message.balance = Coin.fromJSON(object.balance); - } else { - message.balance = undefined; - } - return message; + return { + delegation: isSet(object.delegation) ? Delegation.fromJSON(object.delegation) : undefined, + balance: isSet(object.balance) ? Coin.fromJSON(object.balance) : undefined, + }; }, toJSON(message: DelegationResponse): unknown { @@ -1782,23 +1554,21 @@ export const DelegationResponse = { return obj; }, - fromPartial(object: DeepPartial): DelegationResponse { - const message = { ...baseDelegationResponse } as DelegationResponse; - if (object.delegation !== undefined && object.delegation !== null) { - message.delegation = Delegation.fromPartial(object.delegation); - } else { - message.delegation = undefined; - } - if (object.balance !== undefined && object.balance !== null) { - message.balance = Coin.fromPartial(object.balance); - } else { - message.balance = undefined; - } + fromPartial, I>>(object: I): DelegationResponse { + const message = createBaseDelegationResponse(); + message.delegation = + object.delegation !== undefined && object.delegation !== null + ? Delegation.fromPartial(object.delegation) + : undefined; + message.balance = + object.balance !== undefined && object.balance !== null ? Coin.fromPartial(object.balance) : undefined; return message; }, }; -const baseRedelegationEntryResponse: object = { balance: "" }; +function createBaseRedelegationEntryResponse(): RedelegationEntryResponse { + return { redelegationEntry: undefined, balance: "" }; +} export const RedelegationEntryResponse = { encode(message: RedelegationEntryResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1814,7 +1584,7 @@ export const RedelegationEntryResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): RedelegationEntryResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseRedelegationEntryResponse } as RedelegationEntryResponse; + const message = createBaseRedelegationEntryResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1833,18 +1603,12 @@ export const RedelegationEntryResponse = { }, fromJSON(object: any): RedelegationEntryResponse { - const message = { ...baseRedelegationEntryResponse } as RedelegationEntryResponse; - if (object.redelegationEntry !== undefined && object.redelegationEntry !== null) { - message.redelegationEntry = RedelegationEntry.fromJSON(object.redelegationEntry); - } else { - message.redelegationEntry = undefined; - } - if (object.balance !== undefined && object.balance !== null) { - message.balance = String(object.balance); - } else { - message.balance = ""; - } - return message; + return { + redelegationEntry: isSet(object.redelegationEntry) + ? RedelegationEntry.fromJSON(object.redelegationEntry) + : undefined, + balance: isSet(object.balance) ? String(object.balance) : "", + }; }, toJSON(message: RedelegationEntryResponse): unknown { @@ -1857,19 +1621,22 @@ export const RedelegationEntryResponse = { return obj; }, - fromPartial(object: DeepPartial): RedelegationEntryResponse { - const message = { ...baseRedelegationEntryResponse } as RedelegationEntryResponse; - if (object.redelegationEntry !== undefined && object.redelegationEntry !== null) { - message.redelegationEntry = RedelegationEntry.fromPartial(object.redelegationEntry); - } else { - message.redelegationEntry = undefined; - } + fromPartial, I>>( + object: I, + ): RedelegationEntryResponse { + const message = createBaseRedelegationEntryResponse(); + message.redelegationEntry = + object.redelegationEntry !== undefined && object.redelegationEntry !== null + ? RedelegationEntry.fromPartial(object.redelegationEntry) + : undefined; message.balance = object.balance ?? ""; return message; }, }; -const baseRedelegationResponse: object = {}; +function createBaseRedelegationResponse(): RedelegationResponse { + return { redelegation: undefined, entries: [] }; +} export const RedelegationResponse = { encode(message: RedelegationResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1885,8 +1652,7 @@ export const RedelegationResponse = { decode(input: _m0.Reader | Uint8Array, length?: number): RedelegationResponse { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseRedelegationResponse } as RedelegationResponse; - message.entries = []; + const message = createBaseRedelegationResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1905,19 +1671,12 @@ export const RedelegationResponse = { }, fromJSON(object: any): RedelegationResponse { - const message = { ...baseRedelegationResponse } as RedelegationResponse; - message.entries = []; - if (object.redelegation !== undefined && object.redelegation !== null) { - message.redelegation = Redelegation.fromJSON(object.redelegation); - } else { - message.redelegation = undefined; - } - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(RedelegationEntryResponse.fromJSON(e)); - } - } - return message; + return { + redelegation: isSet(object.redelegation) ? Redelegation.fromJSON(object.redelegation) : undefined, + entries: Array.isArray(object?.entries) + ? object.entries.map((e: any) => RedelegationEntryResponse.fromJSON(e)) + : [], + }; }, toJSON(message: RedelegationResponse): unknown { @@ -1932,24 +1691,20 @@ export const RedelegationResponse = { return obj; }, - fromPartial(object: DeepPartial): RedelegationResponse { - const message = { ...baseRedelegationResponse } as RedelegationResponse; - if (object.redelegation !== undefined && object.redelegation !== null) { - message.redelegation = Redelegation.fromPartial(object.redelegation); - } else { - message.redelegation = undefined; - } - message.entries = []; - if (object.entries !== undefined && object.entries !== null) { - for (const e of object.entries) { - message.entries.push(RedelegationEntryResponse.fromPartial(e)); - } - } + fromPartial, I>>(object: I): RedelegationResponse { + const message = createBaseRedelegationResponse(); + message.redelegation = + object.redelegation !== undefined && object.redelegation !== null + ? Redelegation.fromPartial(object.redelegation) + : undefined; + message.entries = object.entries?.map((e) => RedelegationEntryResponse.fromPartial(e)) || []; return message; }, }; -const basePool: object = { notBondedTokens: "", bondedTokens: "" }; +function createBasePool(): Pool { + return { notBondedTokens: "", bondedTokens: "" }; +} export const Pool = { encode(message: Pool, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1965,7 +1720,7 @@ export const Pool = { decode(input: _m0.Reader | Uint8Array, length?: number): Pool { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...basePool } as Pool; + const message = createBasePool(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1984,18 +1739,10 @@ export const Pool = { }, fromJSON(object: any): Pool { - const message = { ...basePool } as Pool; - if (object.notBondedTokens !== undefined && object.notBondedTokens !== null) { - message.notBondedTokens = String(object.notBondedTokens); - } else { - message.notBondedTokens = ""; - } - if (object.bondedTokens !== undefined && object.bondedTokens !== null) { - message.bondedTokens = String(object.bondedTokens); - } else { - message.bondedTokens = ""; - } - return message; + return { + notBondedTokens: isSet(object.notBondedTokens) ? String(object.notBondedTokens) : "", + bondedTokens: isSet(object.bondedTokens) ? String(object.bondedTokens) : "", + }; }, toJSON(message: Pool): unknown { @@ -2005,17 +1752,20 @@ export const Pool = { return obj; }, - fromPartial(object: DeepPartial): Pool { - const message = { ...basePool } as Pool; + fromPartial, I>>(object: I): Pool { + const message = createBasePool(); message.notBondedTokens = object.notBondedTokens ?? ""; message.bondedTokens = object.bondedTokens ?? ""; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -2024,6 +1774,11 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + function toTimestamp(date: Date): Timestamp { const seconds = numberToLong(date.getTime() / 1_000); const nanos = (date.getTime() % 1_000) * 1_000_000; @@ -2054,3 +1809,7 @@ if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/cosmos_proto/cosmos.ts b/src/codec/cosmos_proto/cosmos.ts index be41366a..4c2f49d0 100644 --- a/src/codec/cosmos_proto/cosmos.ts +++ b/src/codec/cosmos_proto/cosmos.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "cosmos_proto"; diff --git a/src/codec/gogoproto/gogo.ts b/src/codec/gogoproto/gogo.ts index 2f8cdcc0..2d66a277 100644 --- a/src/codec/gogoproto/gogo.ts +++ b/src/codec/gogoproto/gogo.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "gogoproto"; diff --git a/src/codec/google/api/annotations.ts b/src/codec/google/api/annotations.ts index b0b6729f..6e6ca014 100644 --- a/src/codec/google/api/annotations.ts +++ b/src/codec/google/api/annotations.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "google.api"; diff --git a/src/codec/google/api/http.ts b/src/codec/google/api/http.ts index b85361de..7254f666 100644 --- a/src/codec/google/api/http.ts +++ b/src/codec/google/api/http.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "google.api"; @@ -299,7 +299,9 @@ export interface CustomHttpPattern { path: string; } -const baseHttp: object = { fullyDecodeReservedExpansion: false }; +function createBaseHttp(): Http { + return { rules: [], fullyDecodeReservedExpansion: false }; +} export const Http = { encode(message: Http, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -315,8 +317,7 @@ export const Http = { decode(input: _m0.Reader | Uint8Array, length?: number): Http { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseHttp } as Http; - message.rules = []; + const message = createBaseHttp(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -335,19 +336,12 @@ export const Http = { }, fromJSON(object: any): Http { - const message = { ...baseHttp } as Http; - message.rules = []; - if (object.rules !== undefined && object.rules !== null) { - for (const e of object.rules) { - message.rules.push(HttpRule.fromJSON(e)); - } - } - if (object.fullyDecodeReservedExpansion !== undefined && object.fullyDecodeReservedExpansion !== null) { - message.fullyDecodeReservedExpansion = Boolean(object.fullyDecodeReservedExpansion); - } else { - message.fullyDecodeReservedExpansion = false; - } - return message; + return { + rules: Array.isArray(object?.rules) ? object.rules.map((e: any) => HttpRule.fromJSON(e)) : [], + fullyDecodeReservedExpansion: isSet(object.fullyDecodeReservedExpansion) + ? Boolean(object.fullyDecodeReservedExpansion) + : false, + }; }, toJSON(message: Http): unknown { @@ -362,20 +356,28 @@ export const Http = { return obj; }, - fromPartial(object: DeepPartial): Http { - const message = { ...baseHttp } as Http; - message.rules = []; - if (object.rules !== undefined && object.rules !== null) { - for (const e of object.rules) { - message.rules.push(HttpRule.fromPartial(e)); - } - } + fromPartial, I>>(object: I): Http { + const message = createBaseHttp(); + message.rules = object.rules?.map((e) => HttpRule.fromPartial(e)) || []; message.fullyDecodeReservedExpansion = object.fullyDecodeReservedExpansion ?? false; return message; }, }; -const baseHttpRule: object = { selector: "", body: "", responseBody: "" }; +function createBaseHttpRule(): HttpRule { + return { + selector: "", + get: undefined, + put: undefined, + post: undefined, + delete: undefined, + patch: undefined, + custom: undefined, + body: "", + responseBody: "", + additionalBindings: [], + }; +} export const HttpRule = { encode(message: HttpRule, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -415,8 +417,7 @@ export const HttpRule = { decode(input: _m0.Reader | Uint8Array, length?: number): HttpRule { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseHttpRule } as HttpRule; - message.additionalBindings = []; + const message = createBaseHttpRule(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -459,59 +460,20 @@ export const HttpRule = { }, fromJSON(object: any): HttpRule { - const message = { ...baseHttpRule } as HttpRule; - message.additionalBindings = []; - if (object.selector !== undefined && object.selector !== null) { - message.selector = String(object.selector); - } else { - message.selector = ""; - } - if (object.get !== undefined && object.get !== null) { - message.get = String(object.get); - } else { - message.get = undefined; - } - if (object.put !== undefined && object.put !== null) { - message.put = String(object.put); - } else { - message.put = undefined; - } - if (object.post !== undefined && object.post !== null) { - message.post = String(object.post); - } else { - message.post = undefined; - } - if (object.delete !== undefined && object.delete !== null) { - message.delete = String(object.delete); - } else { - message.delete = undefined; - } - if (object.patch !== undefined && object.patch !== null) { - message.patch = String(object.patch); - } else { - message.patch = undefined; - } - if (object.custom !== undefined && object.custom !== null) { - message.custom = CustomHttpPattern.fromJSON(object.custom); - } else { - message.custom = undefined; - } - if (object.body !== undefined && object.body !== null) { - message.body = String(object.body); - } else { - message.body = ""; - } - if (object.responseBody !== undefined && object.responseBody !== null) { - message.responseBody = String(object.responseBody); - } else { - message.responseBody = ""; - } - if (object.additionalBindings !== undefined && object.additionalBindings !== null) { - for (const e of object.additionalBindings) { - message.additionalBindings.push(HttpRule.fromJSON(e)); - } - } - return message; + return { + selector: isSet(object.selector) ? String(object.selector) : "", + get: isSet(object.get) ? String(object.get) : undefined, + put: isSet(object.put) ? String(object.put) : undefined, + post: isSet(object.post) ? String(object.post) : undefined, + delete: isSet(object.delete) ? String(object.delete) : undefined, + patch: isSet(object.patch) ? String(object.patch) : undefined, + custom: isSet(object.custom) ? CustomHttpPattern.fromJSON(object.custom) : undefined, + body: isSet(object.body) ? String(object.body) : "", + responseBody: isSet(object.responseBody) ? String(object.responseBody) : "", + additionalBindings: Array.isArray(object?.additionalBindings) + ? object.additionalBindings.map((e: any) => HttpRule.fromJSON(e)) + : [], + }; }, toJSON(message: HttpRule): unknown { @@ -534,32 +496,28 @@ export const HttpRule = { return obj; }, - fromPartial(object: DeepPartial): HttpRule { - const message = { ...baseHttpRule } as HttpRule; + fromPartial, I>>(object: I): HttpRule { + const message = createBaseHttpRule(); message.selector = object.selector ?? ""; message.get = object.get ?? undefined; message.put = object.put ?? undefined; message.post = object.post ?? undefined; message.delete = object.delete ?? undefined; message.patch = object.patch ?? undefined; - if (object.custom !== undefined && object.custom !== null) { - message.custom = CustomHttpPattern.fromPartial(object.custom); - } else { - message.custom = undefined; - } + message.custom = + object.custom !== undefined && object.custom !== null + ? CustomHttpPattern.fromPartial(object.custom) + : undefined; message.body = object.body ?? ""; message.responseBody = object.responseBody ?? ""; - message.additionalBindings = []; - if (object.additionalBindings !== undefined && object.additionalBindings !== null) { - for (const e of object.additionalBindings) { - message.additionalBindings.push(HttpRule.fromPartial(e)); - } - } + message.additionalBindings = object.additionalBindings?.map((e) => HttpRule.fromPartial(e)) || []; return message; }, }; -const baseCustomHttpPattern: object = { kind: "", path: "" }; +function createBaseCustomHttpPattern(): CustomHttpPattern { + return { kind: "", path: "" }; +} export const CustomHttpPattern = { encode(message: CustomHttpPattern, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -575,7 +533,7 @@ export const CustomHttpPattern = { decode(input: _m0.Reader | Uint8Array, length?: number): CustomHttpPattern { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCustomHttpPattern } as CustomHttpPattern; + const message = createBaseCustomHttpPattern(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -594,18 +552,10 @@ export const CustomHttpPattern = { }, fromJSON(object: any): CustomHttpPattern { - const message = { ...baseCustomHttpPattern } as CustomHttpPattern; - if (object.kind !== undefined && object.kind !== null) { - message.kind = String(object.kind); - } else { - message.kind = ""; - } - if (object.path !== undefined && object.path !== null) { - message.path = String(object.path); - } else { - message.path = ""; - } - return message; + return { + kind: isSet(object.kind) ? String(object.kind) : "", + path: isSet(object.path) ? String(object.path) : "", + }; }, toJSON(message: CustomHttpPattern): unknown { @@ -615,17 +565,20 @@ export const CustomHttpPattern = { return obj; }, - fromPartial(object: DeepPartial): CustomHttpPattern { - const message = { ...baseCustomHttpPattern } as CustomHttpPattern; + fromPartial, I>>(object: I): CustomHttpPattern { + const message = createBaseCustomHttpPattern(); message.kind = object.kind ?? ""; message.path = object.path ?? ""; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -634,7 +587,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/google/protobuf/any.ts b/src/codec/google/protobuf/any.ts index e5944f5a..a8cd3bd9 100644 --- a/src/codec/google/protobuf/any.ts +++ b/src/codec/google/protobuf/any.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "google.protobuf"; @@ -120,7 +120,9 @@ export interface Any { value: Uint8Array; } -const baseAny: object = { typeUrl: "" }; +function createBaseAny(): Any { + return { typeUrl: "", value: new Uint8Array() }; +} export const Any = { encode(message: Any, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -136,8 +138,7 @@ export const Any = { decode(input: _m0.Reader | Uint8Array, length?: number): Any { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseAny } as Any; - message.value = new Uint8Array(); + const message = createBaseAny(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -156,17 +157,10 @@ export const Any = { }, fromJSON(object: any): Any { - const message = { ...baseAny } as Any; - message.value = new Uint8Array(); - if (object.typeUrl !== undefined && object.typeUrl !== null) { - message.typeUrl = String(object.typeUrl); - } else { - message.typeUrl = ""; - } - if (object.value !== undefined && object.value !== null) { - message.value = bytesFromBase64(object.value); - } - return message; + return { + typeUrl: isSet(object.typeUrl) ? String(object.typeUrl) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(), + }; }, toJSON(message: Any): unknown { @@ -177,8 +171,8 @@ export const Any = { return obj; }, - fromPartial(object: DeepPartial): Any { - const message = { ...baseAny } as Any; + fromPartial, I>>(object: I): Any { + const message = createBaseAny(); message.typeUrl = object.typeUrl ?? ""; message.value = object.value ?? new Uint8Array(); return message; @@ -211,15 +205,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -228,7 +225,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/google/protobuf/descriptor.ts b/src/codec/google/protobuf/descriptor.ts index 8165e69c..dfda506b 100644 --- a/src/codec/google/protobuf/descriptor.ts +++ b/src/codec/google/protobuf/descriptor.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "google.protobuf"; @@ -1112,7 +1112,9 @@ export interface GeneratedCodeInfo_Annotation { end: number; } -const baseFileDescriptorSet: object = {}; +function createBaseFileDescriptorSet(): FileDescriptorSet { + return { file: [] }; +} export const FileDescriptorSet = { encode(message: FileDescriptorSet, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1125,8 +1127,7 @@ export const FileDescriptorSet = { decode(input: _m0.Reader | Uint8Array, length?: number): FileDescriptorSet { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseFileDescriptorSet } as FileDescriptorSet; - message.file = []; + const message = createBaseFileDescriptorSet(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1142,14 +1143,9 @@ export const FileDescriptorSet = { }, fromJSON(object: any): FileDescriptorSet { - const message = { ...baseFileDescriptorSet } as FileDescriptorSet; - message.file = []; - if (object.file !== undefined && object.file !== null) { - for (const e of object.file) { - message.file.push(FileDescriptorProto.fromJSON(e)); - } - } - return message; + return { + file: Array.isArray(object?.file) ? object.file.map((e: any) => FileDescriptorProto.fromJSON(e)) : [], + }; }, toJSON(message: FileDescriptorSet): unknown { @@ -1162,26 +1158,29 @@ export const FileDescriptorSet = { return obj; }, - fromPartial(object: DeepPartial): FileDescriptorSet { - const message = { ...baseFileDescriptorSet } as FileDescriptorSet; - message.file = []; - if (object.file !== undefined && object.file !== null) { - for (const e of object.file) { - message.file.push(FileDescriptorProto.fromPartial(e)); - } - } + fromPartial, I>>(object: I): FileDescriptorSet { + const message = createBaseFileDescriptorSet(); + message.file = object.file?.map((e) => FileDescriptorProto.fromPartial(e)) || []; return message; }, }; -const baseFileDescriptorProto: object = { - name: "", - package: "", - dependency: "", - publicDependency: 0, - weakDependency: 0, - syntax: "", -}; +function createBaseFileDescriptorProto(): FileDescriptorProto { + return { + name: "", + package: "", + dependency: [], + publicDependency: [], + weakDependency: [], + messageType: [], + enumType: [], + service: [], + extension: [], + options: undefined, + sourceCodeInfo: undefined, + syntax: "", + }; +} export const FileDescriptorProto = { encode(message: FileDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1231,14 +1230,7 @@ export const FileDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): FileDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseFileDescriptorProto } as FileDescriptorProto; - message.dependency = []; - message.publicDependency = []; - message.weakDependency = []; - message.messageType = []; - message.enumType = []; - message.service = []; - message.extension = []; + const message = createBaseFileDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1301,75 +1293,34 @@ export const FileDescriptorProto = { }, fromJSON(object: any): FileDescriptorProto { - const message = { ...baseFileDescriptorProto } as FileDescriptorProto; - message.dependency = []; - message.publicDependency = []; - message.weakDependency = []; - message.messageType = []; - message.enumType = []; - message.service = []; - message.extension = []; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.package !== undefined && object.package !== null) { - message.package = String(object.package); - } else { - message.package = ""; - } - if (object.dependency !== undefined && object.dependency !== null) { - for (const e of object.dependency) { - message.dependency.push(String(e)); - } - } - if (object.publicDependency !== undefined && object.publicDependency !== null) { - for (const e of object.publicDependency) { - message.publicDependency.push(Number(e)); - } - } - if (object.weakDependency !== undefined && object.weakDependency !== null) { - for (const e of object.weakDependency) { - message.weakDependency.push(Number(e)); - } - } - if (object.messageType !== undefined && object.messageType !== null) { - for (const e of object.messageType) { - message.messageType.push(DescriptorProto.fromJSON(e)); - } - } - if (object.enumType !== undefined && object.enumType !== null) { - for (const e of object.enumType) { - message.enumType.push(EnumDescriptorProto.fromJSON(e)); - } - } - if (object.service !== undefined && object.service !== null) { - for (const e of object.service) { - message.service.push(ServiceDescriptorProto.fromJSON(e)); - } - } - if (object.extension !== undefined && object.extension !== null) { - for (const e of object.extension) { - message.extension.push(FieldDescriptorProto.fromJSON(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = FileOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - if (object.sourceCodeInfo !== undefined && object.sourceCodeInfo !== null) { - message.sourceCodeInfo = SourceCodeInfo.fromJSON(object.sourceCodeInfo); - } else { - message.sourceCodeInfo = undefined; - } - if (object.syntax !== undefined && object.syntax !== null) { - message.syntax = String(object.syntax); - } else { - message.syntax = ""; - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + package: isSet(object.package) ? String(object.package) : "", + dependency: Array.isArray(object?.dependency) ? object.dependency.map((e: any) => String(e)) : [], + publicDependency: Array.isArray(object?.publicDependency) + ? object.publicDependency.map((e: any) => Number(e)) + : [], + weakDependency: Array.isArray(object?.weakDependency) + ? object.weakDependency.map((e: any) => Number(e)) + : [], + messageType: Array.isArray(object?.messageType) + ? object.messageType.map((e: any) => DescriptorProto.fromJSON(e)) + : [], + enumType: Array.isArray(object?.enumType) + ? object.enumType.map((e: any) => EnumDescriptorProto.fromJSON(e)) + : [], + service: Array.isArray(object?.service) + ? object.service.map((e: any) => ServiceDescriptorProto.fromJSON(e)) + : [], + extension: Array.isArray(object?.extension) + ? object.extension.map((e: any) => FieldDescriptorProto.fromJSON(e)) + : [], + options: isSet(object.options) ? FileOptions.fromJSON(object.options) : undefined, + sourceCodeInfo: isSet(object.sourceCodeInfo) + ? SourceCodeInfo.fromJSON(object.sourceCodeInfo) + : undefined, + syntax: isSet(object.syntax) ? String(object.syntax) : "", + }; }, toJSON(message: FileDescriptorProto): unknown { @@ -1382,12 +1333,12 @@ export const FileDescriptorProto = { obj.dependency = []; } if (message.publicDependency) { - obj.publicDependency = message.publicDependency.map((e) => e); + obj.publicDependency = message.publicDependency.map((e) => Math.round(e)); } else { obj.publicDependency = []; } if (message.weakDependency) { - obj.weakDependency = message.weakDependency.map((e) => e); + obj.weakDependency = message.weakDependency.map((e) => Math.round(e)); } else { obj.weakDependency = []; } @@ -1421,68 +1372,44 @@ export const FileDescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): FileDescriptorProto { - const message = { ...baseFileDescriptorProto } as FileDescriptorProto; + fromPartial, I>>(object: I): FileDescriptorProto { + const message = createBaseFileDescriptorProto(); message.name = object.name ?? ""; message.package = object.package ?? ""; - message.dependency = []; - if (object.dependency !== undefined && object.dependency !== null) { - for (const e of object.dependency) { - message.dependency.push(e); - } - } - message.publicDependency = []; - if (object.publicDependency !== undefined && object.publicDependency !== null) { - for (const e of object.publicDependency) { - message.publicDependency.push(e); - } - } - message.weakDependency = []; - if (object.weakDependency !== undefined && object.weakDependency !== null) { - for (const e of object.weakDependency) { - message.weakDependency.push(e); - } - } - message.messageType = []; - if (object.messageType !== undefined && object.messageType !== null) { - for (const e of object.messageType) { - message.messageType.push(DescriptorProto.fromPartial(e)); - } - } - message.enumType = []; - if (object.enumType !== undefined && object.enumType !== null) { - for (const e of object.enumType) { - message.enumType.push(EnumDescriptorProto.fromPartial(e)); - } - } - message.service = []; - if (object.service !== undefined && object.service !== null) { - for (const e of object.service) { - message.service.push(ServiceDescriptorProto.fromPartial(e)); - } - } - message.extension = []; - if (object.extension !== undefined && object.extension !== null) { - for (const e of object.extension) { - message.extension.push(FieldDescriptorProto.fromPartial(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = FileOptions.fromPartial(object.options); - } else { - message.options = undefined; - } - if (object.sourceCodeInfo !== undefined && object.sourceCodeInfo !== null) { - message.sourceCodeInfo = SourceCodeInfo.fromPartial(object.sourceCodeInfo); - } else { - message.sourceCodeInfo = undefined; - } + message.dependency = object.dependency?.map((e) => e) || []; + message.publicDependency = object.publicDependency?.map((e) => e) || []; + message.weakDependency = object.weakDependency?.map((e) => e) || []; + message.messageType = object.messageType?.map((e) => DescriptorProto.fromPartial(e)) || []; + message.enumType = object.enumType?.map((e) => EnumDescriptorProto.fromPartial(e)) || []; + message.service = object.service?.map((e) => ServiceDescriptorProto.fromPartial(e)) || []; + message.extension = object.extension?.map((e) => FieldDescriptorProto.fromPartial(e)) || []; + message.options = + object.options !== undefined && object.options !== null + ? FileOptions.fromPartial(object.options) + : undefined; + message.sourceCodeInfo = + object.sourceCodeInfo !== undefined && object.sourceCodeInfo !== null + ? SourceCodeInfo.fromPartial(object.sourceCodeInfo) + : undefined; message.syntax = object.syntax ?? ""; return message; }, }; -const baseDescriptorProto: object = { name: "", reservedName: "" }; +function createBaseDescriptorProto(): DescriptorProto { + return { + name: "", + field: [], + extension: [], + nestedType: [], + enumType: [], + extensionRange: [], + oneofDecl: [], + options: undefined, + reservedRange: [], + reservedName: [], + }; +} export const DescriptorProto = { encode(message: DescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1522,15 +1449,7 @@ export const DescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): DescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDescriptorProto } as DescriptorProto; - message.field = []; - message.extension = []; - message.nestedType = []; - message.enumType = []; - message.extensionRange = []; - message.oneofDecl = []; - message.reservedRange = []; - message.reservedName = []; + const message = createBaseDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1573,66 +1492,32 @@ export const DescriptorProto = { }, fromJSON(object: any): DescriptorProto { - const message = { ...baseDescriptorProto } as DescriptorProto; - message.field = []; - message.extension = []; - message.nestedType = []; - message.enumType = []; - message.extensionRange = []; - message.oneofDecl = []; - message.reservedRange = []; - message.reservedName = []; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.field !== undefined && object.field !== null) { - for (const e of object.field) { - message.field.push(FieldDescriptorProto.fromJSON(e)); - } - } - if (object.extension !== undefined && object.extension !== null) { - for (const e of object.extension) { - message.extension.push(FieldDescriptorProto.fromJSON(e)); - } - } - if (object.nestedType !== undefined && object.nestedType !== null) { - for (const e of object.nestedType) { - message.nestedType.push(DescriptorProto.fromJSON(e)); - } - } - if (object.enumType !== undefined && object.enumType !== null) { - for (const e of object.enumType) { - message.enumType.push(EnumDescriptorProto.fromJSON(e)); - } - } - if (object.extensionRange !== undefined && object.extensionRange !== null) { - for (const e of object.extensionRange) { - message.extensionRange.push(DescriptorProto_ExtensionRange.fromJSON(e)); - } - } - if (object.oneofDecl !== undefined && object.oneofDecl !== null) { - for (const e of object.oneofDecl) { - message.oneofDecl.push(OneofDescriptorProto.fromJSON(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = MessageOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - if (object.reservedRange !== undefined && object.reservedRange !== null) { - for (const e of object.reservedRange) { - message.reservedRange.push(DescriptorProto_ReservedRange.fromJSON(e)); - } - } - if (object.reservedName !== undefined && object.reservedName !== null) { - for (const e of object.reservedName) { - message.reservedName.push(String(e)); - } - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + field: Array.isArray(object?.field) + ? object.field.map((e: any) => FieldDescriptorProto.fromJSON(e)) + : [], + extension: Array.isArray(object?.extension) + ? object.extension.map((e: any) => FieldDescriptorProto.fromJSON(e)) + : [], + nestedType: Array.isArray(object?.nestedType) + ? object.nestedType.map((e: any) => DescriptorProto.fromJSON(e)) + : [], + enumType: Array.isArray(object?.enumType) + ? object.enumType.map((e: any) => EnumDescriptorProto.fromJSON(e)) + : [], + extensionRange: Array.isArray(object?.extensionRange) + ? object.extensionRange.map((e: any) => DescriptorProto_ExtensionRange.fromJSON(e)) + : [], + oneofDecl: Array.isArray(object?.oneofDecl) + ? object.oneofDecl.map((e: any) => OneofDescriptorProto.fromJSON(e)) + : [], + options: isSet(object.options) ? MessageOptions.fromJSON(object.options) : undefined, + reservedRange: Array.isArray(object?.reservedRange) + ? object.reservedRange.map((e: any) => DescriptorProto_ReservedRange.fromJSON(e)) + : [], + reservedName: Array.isArray(object?.reservedName) ? object.reservedName.map((e: any) => String(e)) : [], + }; }, toJSON(message: DescriptorProto): unknown { @@ -1687,67 +1572,30 @@ export const DescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): DescriptorProto { - const message = { ...baseDescriptorProto } as DescriptorProto; + fromPartial, I>>(object: I): DescriptorProto { + const message = createBaseDescriptorProto(); message.name = object.name ?? ""; - message.field = []; - if (object.field !== undefined && object.field !== null) { - for (const e of object.field) { - message.field.push(FieldDescriptorProto.fromPartial(e)); - } - } - message.extension = []; - if (object.extension !== undefined && object.extension !== null) { - for (const e of object.extension) { - message.extension.push(FieldDescriptorProto.fromPartial(e)); - } - } - message.nestedType = []; - if (object.nestedType !== undefined && object.nestedType !== null) { - for (const e of object.nestedType) { - message.nestedType.push(DescriptorProto.fromPartial(e)); - } - } - message.enumType = []; - if (object.enumType !== undefined && object.enumType !== null) { - for (const e of object.enumType) { - message.enumType.push(EnumDescriptorProto.fromPartial(e)); - } - } - message.extensionRange = []; - if (object.extensionRange !== undefined && object.extensionRange !== null) { - for (const e of object.extensionRange) { - message.extensionRange.push(DescriptorProto_ExtensionRange.fromPartial(e)); - } - } - message.oneofDecl = []; - if (object.oneofDecl !== undefined && object.oneofDecl !== null) { - for (const e of object.oneofDecl) { - message.oneofDecl.push(OneofDescriptorProto.fromPartial(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = MessageOptions.fromPartial(object.options); - } else { - message.options = undefined; - } - message.reservedRange = []; - if (object.reservedRange !== undefined && object.reservedRange !== null) { - for (const e of object.reservedRange) { - message.reservedRange.push(DescriptorProto_ReservedRange.fromPartial(e)); - } - } - message.reservedName = []; - if (object.reservedName !== undefined && object.reservedName !== null) { - for (const e of object.reservedName) { - message.reservedName.push(e); - } - } + message.field = object.field?.map((e) => FieldDescriptorProto.fromPartial(e)) || []; + message.extension = object.extension?.map((e) => FieldDescriptorProto.fromPartial(e)) || []; + message.nestedType = object.nestedType?.map((e) => DescriptorProto.fromPartial(e)) || []; + message.enumType = object.enumType?.map((e) => EnumDescriptorProto.fromPartial(e)) || []; + message.extensionRange = + object.extensionRange?.map((e) => DescriptorProto_ExtensionRange.fromPartial(e)) || []; + message.oneofDecl = object.oneofDecl?.map((e) => OneofDescriptorProto.fromPartial(e)) || []; + message.options = + object.options !== undefined && object.options !== null + ? MessageOptions.fromPartial(object.options) + : undefined; + message.reservedRange = + object.reservedRange?.map((e) => DescriptorProto_ReservedRange.fromPartial(e)) || []; + message.reservedName = object.reservedName?.map((e) => e) || []; return message; }, }; -const baseDescriptorProto_ExtensionRange: object = { start: 0, end: 0 }; +function createBaseDescriptorProto_ExtensionRange(): DescriptorProto_ExtensionRange { + return { start: 0, end: 0, options: undefined }; +} export const DescriptorProto_ExtensionRange = { encode(message: DescriptorProto_ExtensionRange, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1766,7 +1614,7 @@ export const DescriptorProto_ExtensionRange = { decode(input: _m0.Reader | Uint8Array, length?: number): DescriptorProto_ExtensionRange { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDescriptorProto_ExtensionRange } as DescriptorProto_ExtensionRange; + const message = createBaseDescriptorProto_ExtensionRange(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1788,48 +1636,39 @@ export const DescriptorProto_ExtensionRange = { }, fromJSON(object: any): DescriptorProto_ExtensionRange { - const message = { ...baseDescriptorProto_ExtensionRange } as DescriptorProto_ExtensionRange; - if (object.start !== undefined && object.start !== null) { - message.start = Number(object.start); - } else { - message.start = 0; - } - if (object.end !== undefined && object.end !== null) { - message.end = Number(object.end); - } else { - message.end = 0; - } - if (object.options !== undefined && object.options !== null) { - message.options = ExtensionRangeOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - return message; + return { + start: isSet(object.start) ? Number(object.start) : 0, + end: isSet(object.end) ? Number(object.end) : 0, + options: isSet(object.options) ? ExtensionRangeOptions.fromJSON(object.options) : undefined, + }; }, toJSON(message: DescriptorProto_ExtensionRange): unknown { const obj: any = {}; - message.start !== undefined && (obj.start = message.start); - message.end !== undefined && (obj.end = message.end); + message.start !== undefined && (obj.start = Math.round(message.start)); + message.end !== undefined && (obj.end = Math.round(message.end)); message.options !== undefined && (obj.options = message.options ? ExtensionRangeOptions.toJSON(message.options) : undefined); return obj; }, - fromPartial(object: DeepPartial): DescriptorProto_ExtensionRange { - const message = { ...baseDescriptorProto_ExtensionRange } as DescriptorProto_ExtensionRange; + fromPartial, I>>( + object: I, + ): DescriptorProto_ExtensionRange { + const message = createBaseDescriptorProto_ExtensionRange(); message.start = object.start ?? 0; message.end = object.end ?? 0; - if (object.options !== undefined && object.options !== null) { - message.options = ExtensionRangeOptions.fromPartial(object.options); - } else { - message.options = undefined; - } + message.options = + object.options !== undefined && object.options !== null + ? ExtensionRangeOptions.fromPartial(object.options) + : undefined; return message; }, }; -const baseDescriptorProto_ReservedRange: object = { start: 0, end: 0 }; +function createBaseDescriptorProto_ReservedRange(): DescriptorProto_ReservedRange { + return { start: 0, end: 0 }; +} export const DescriptorProto_ReservedRange = { encode(message: DescriptorProto_ReservedRange, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1845,7 +1684,7 @@ export const DescriptorProto_ReservedRange = { decode(input: _m0.Reader | Uint8Array, length?: number): DescriptorProto_ReservedRange { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDescriptorProto_ReservedRange } as DescriptorProto_ReservedRange; + const message = createBaseDescriptorProto_ReservedRange(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1864,36 +1703,32 @@ export const DescriptorProto_ReservedRange = { }, fromJSON(object: any): DescriptorProto_ReservedRange { - const message = { ...baseDescriptorProto_ReservedRange } as DescriptorProto_ReservedRange; - if (object.start !== undefined && object.start !== null) { - message.start = Number(object.start); - } else { - message.start = 0; - } - if (object.end !== undefined && object.end !== null) { - message.end = Number(object.end); - } else { - message.end = 0; - } - return message; + return { + start: isSet(object.start) ? Number(object.start) : 0, + end: isSet(object.end) ? Number(object.end) : 0, + }; }, toJSON(message: DescriptorProto_ReservedRange): unknown { const obj: any = {}; - message.start !== undefined && (obj.start = message.start); - message.end !== undefined && (obj.end = message.end); + message.start !== undefined && (obj.start = Math.round(message.start)); + message.end !== undefined && (obj.end = Math.round(message.end)); return obj; }, - fromPartial(object: DeepPartial): DescriptorProto_ReservedRange { - const message = { ...baseDescriptorProto_ReservedRange } as DescriptorProto_ReservedRange; + fromPartial, I>>( + object: I, + ): DescriptorProto_ReservedRange { + const message = createBaseDescriptorProto_ReservedRange(); message.start = object.start ?? 0; message.end = object.end ?? 0; return message; }, }; -const baseExtensionRangeOptions: object = {}; +function createBaseExtensionRangeOptions(): ExtensionRangeOptions { + return { uninterpretedOption: [] }; +} export const ExtensionRangeOptions = { encode(message: ExtensionRangeOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1906,8 +1741,7 @@ export const ExtensionRangeOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): ExtensionRangeOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseExtensionRangeOptions } as ExtensionRangeOptions; - message.uninterpretedOption = []; + const message = createBaseExtensionRangeOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1923,14 +1757,11 @@ export const ExtensionRangeOptions = { }, fromJSON(object: any): ExtensionRangeOptions { - const message = { ...baseExtensionRangeOptions } as ExtensionRangeOptions; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: ExtensionRangeOptions): unknown { @@ -1945,30 +1776,29 @@ export const ExtensionRangeOptions = { return obj; }, - fromPartial(object: DeepPartial): ExtensionRangeOptions { - const message = { ...baseExtensionRangeOptions } as ExtensionRangeOptions; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + fromPartial, I>>(object: I): ExtensionRangeOptions { + const message = createBaseExtensionRangeOptions(); + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseFieldDescriptorProto: object = { - name: "", - number: 0, - label: 1, - type: 1, - typeName: "", - extendee: "", - defaultValue: "", - oneofIndex: 0, - jsonName: "", - proto3Optional: false, -}; +function createBaseFieldDescriptorProto(): FieldDescriptorProto { + return { + name: "", + number: 0, + label: 1, + type: 1, + typeName: "", + extendee: "", + defaultValue: "", + oneofIndex: 0, + jsonName: "", + options: undefined, + proto3Optional: false, + }; +} export const FieldDescriptorProto = { encode(message: FieldDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2011,7 +1841,7 @@ export const FieldDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): FieldDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseFieldDescriptorProto } as FieldDescriptorProto; + const message = createBaseFieldDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2057,75 +1887,31 @@ export const FieldDescriptorProto = { }, fromJSON(object: any): FieldDescriptorProto { - const message = { ...baseFieldDescriptorProto } as FieldDescriptorProto; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.number !== undefined && object.number !== null) { - message.number = Number(object.number); - } else { - message.number = 0; - } - if (object.label !== undefined && object.label !== null) { - message.label = fieldDescriptorProto_LabelFromJSON(object.label); - } else { - message.label = 1; - } - if (object.type !== undefined && object.type !== null) { - message.type = fieldDescriptorProto_TypeFromJSON(object.type); - } else { - message.type = 1; - } - if (object.typeName !== undefined && object.typeName !== null) { - message.typeName = String(object.typeName); - } else { - message.typeName = ""; - } - if (object.extendee !== undefined && object.extendee !== null) { - message.extendee = String(object.extendee); - } else { - message.extendee = ""; - } - if (object.defaultValue !== undefined && object.defaultValue !== null) { - message.defaultValue = String(object.defaultValue); - } else { - message.defaultValue = ""; - } - if (object.oneofIndex !== undefined && object.oneofIndex !== null) { - message.oneofIndex = Number(object.oneofIndex); - } else { - message.oneofIndex = 0; - } - if (object.jsonName !== undefined && object.jsonName !== null) { - message.jsonName = String(object.jsonName); - } else { - message.jsonName = ""; - } - if (object.options !== undefined && object.options !== null) { - message.options = FieldOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - if (object.proto3Optional !== undefined && object.proto3Optional !== null) { - message.proto3Optional = Boolean(object.proto3Optional); - } else { - message.proto3Optional = false; - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + number: isSet(object.number) ? Number(object.number) : 0, + label: isSet(object.label) ? fieldDescriptorProto_LabelFromJSON(object.label) : 1, + type: isSet(object.type) ? fieldDescriptorProto_TypeFromJSON(object.type) : 1, + typeName: isSet(object.typeName) ? String(object.typeName) : "", + extendee: isSet(object.extendee) ? String(object.extendee) : "", + defaultValue: isSet(object.defaultValue) ? String(object.defaultValue) : "", + oneofIndex: isSet(object.oneofIndex) ? Number(object.oneofIndex) : 0, + jsonName: isSet(object.jsonName) ? String(object.jsonName) : "", + options: isSet(object.options) ? FieldOptions.fromJSON(object.options) : undefined, + proto3Optional: isSet(object.proto3Optional) ? Boolean(object.proto3Optional) : false, + }; }, toJSON(message: FieldDescriptorProto): unknown { const obj: any = {}; message.name !== undefined && (obj.name = message.name); - message.number !== undefined && (obj.number = message.number); + message.number !== undefined && (obj.number = Math.round(message.number)); message.label !== undefined && (obj.label = fieldDescriptorProto_LabelToJSON(message.label)); message.type !== undefined && (obj.type = fieldDescriptorProto_TypeToJSON(message.type)); message.typeName !== undefined && (obj.typeName = message.typeName); message.extendee !== undefined && (obj.extendee = message.extendee); message.defaultValue !== undefined && (obj.defaultValue = message.defaultValue); - message.oneofIndex !== undefined && (obj.oneofIndex = message.oneofIndex); + message.oneofIndex !== undefined && (obj.oneofIndex = Math.round(message.oneofIndex)); message.jsonName !== undefined && (obj.jsonName = message.jsonName); message.options !== undefined && (obj.options = message.options ? FieldOptions.toJSON(message.options) : undefined); @@ -2133,8 +1919,8 @@ export const FieldDescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): FieldDescriptorProto { - const message = { ...baseFieldDescriptorProto } as FieldDescriptorProto; + fromPartial, I>>(object: I): FieldDescriptorProto { + const message = createBaseFieldDescriptorProto(); message.name = object.name ?? ""; message.number = object.number ?? 0; message.label = object.label ?? 1; @@ -2144,17 +1930,18 @@ export const FieldDescriptorProto = { message.defaultValue = object.defaultValue ?? ""; message.oneofIndex = object.oneofIndex ?? 0; message.jsonName = object.jsonName ?? ""; - if (object.options !== undefined && object.options !== null) { - message.options = FieldOptions.fromPartial(object.options); - } else { - message.options = undefined; - } + message.options = + object.options !== undefined && object.options !== null + ? FieldOptions.fromPartial(object.options) + : undefined; message.proto3Optional = object.proto3Optional ?? false; return message; }, }; -const baseOneofDescriptorProto: object = { name: "" }; +function createBaseOneofDescriptorProto(): OneofDescriptorProto { + return { name: "", options: undefined }; +} export const OneofDescriptorProto = { encode(message: OneofDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2170,7 +1957,7 @@ export const OneofDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): OneofDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseOneofDescriptorProto } as OneofDescriptorProto; + const message = createBaseOneofDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2189,18 +1976,10 @@ export const OneofDescriptorProto = { }, fromJSON(object: any): OneofDescriptorProto { - const message = { ...baseOneofDescriptorProto } as OneofDescriptorProto; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.options !== undefined && object.options !== null) { - message.options = OneofOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + options: isSet(object.options) ? OneofOptions.fromJSON(object.options) : undefined, + }; }, toJSON(message: OneofDescriptorProto): unknown { @@ -2211,19 +1990,20 @@ export const OneofDescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): OneofDescriptorProto { - const message = { ...baseOneofDescriptorProto } as OneofDescriptorProto; + fromPartial, I>>(object: I): OneofDescriptorProto { + const message = createBaseOneofDescriptorProto(); message.name = object.name ?? ""; - if (object.options !== undefined && object.options !== null) { - message.options = OneofOptions.fromPartial(object.options); - } else { - message.options = undefined; - } + message.options = + object.options !== undefined && object.options !== null + ? OneofOptions.fromPartial(object.options) + : undefined; return message; }, }; -const baseEnumDescriptorProto: object = { name: "", reservedName: "" }; +function createBaseEnumDescriptorProto(): EnumDescriptorProto { + return { name: "", value: [], options: undefined, reservedRange: [], reservedName: [] }; +} export const EnumDescriptorProto = { encode(message: EnumDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2248,10 +2028,7 @@ export const EnumDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): EnumDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseEnumDescriptorProto } as EnumDescriptorProto; - message.value = []; - message.reservedRange = []; - message.reservedName = []; + const message = createBaseEnumDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2279,36 +2056,17 @@ export const EnumDescriptorProto = { }, fromJSON(object: any): EnumDescriptorProto { - const message = { ...baseEnumDescriptorProto } as EnumDescriptorProto; - message.value = []; - message.reservedRange = []; - message.reservedName = []; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.value !== undefined && object.value !== null) { - for (const e of object.value) { - message.value.push(EnumValueDescriptorProto.fromJSON(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = EnumOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - if (object.reservedRange !== undefined && object.reservedRange !== null) { - for (const e of object.reservedRange) { - message.reservedRange.push(EnumDescriptorProto_EnumReservedRange.fromJSON(e)); - } - } - if (object.reservedName !== undefined && object.reservedName !== null) { - for (const e of object.reservedName) { - message.reservedName.push(String(e)); - } - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + value: Array.isArray(object?.value) + ? object.value.map((e: any) => EnumValueDescriptorProto.fromJSON(e)) + : [], + options: isSet(object.options) ? EnumOptions.fromJSON(object.options) : undefined, + reservedRange: Array.isArray(object?.reservedRange) + ? object.reservedRange.map((e: any) => EnumDescriptorProto_EnumReservedRange.fromJSON(e)) + : [], + reservedName: Array.isArray(object?.reservedName) ? object.reservedName.map((e: any) => String(e)) : [], + }; }, toJSON(message: EnumDescriptorProto): unknown { @@ -2336,37 +2094,24 @@ export const EnumDescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): EnumDescriptorProto { - const message = { ...baseEnumDescriptorProto } as EnumDescriptorProto; + fromPartial, I>>(object: I): EnumDescriptorProto { + const message = createBaseEnumDescriptorProto(); message.name = object.name ?? ""; - message.value = []; - if (object.value !== undefined && object.value !== null) { - for (const e of object.value) { - message.value.push(EnumValueDescriptorProto.fromPartial(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = EnumOptions.fromPartial(object.options); - } else { - message.options = undefined; - } - message.reservedRange = []; - if (object.reservedRange !== undefined && object.reservedRange !== null) { - for (const e of object.reservedRange) { - message.reservedRange.push(EnumDescriptorProto_EnumReservedRange.fromPartial(e)); - } - } - message.reservedName = []; - if (object.reservedName !== undefined && object.reservedName !== null) { - for (const e of object.reservedName) { - message.reservedName.push(e); - } - } + message.value = object.value?.map((e) => EnumValueDescriptorProto.fromPartial(e)) || []; + message.options = + object.options !== undefined && object.options !== null + ? EnumOptions.fromPartial(object.options) + : undefined; + message.reservedRange = + object.reservedRange?.map((e) => EnumDescriptorProto_EnumReservedRange.fromPartial(e)) || []; + message.reservedName = object.reservedName?.map((e) => e) || []; return message; }, }; -const baseEnumDescriptorProto_EnumReservedRange: object = { start: 0, end: 0 }; +function createBaseEnumDescriptorProto_EnumReservedRange(): EnumDescriptorProto_EnumReservedRange { + return { start: 0, end: 0 }; +} export const EnumDescriptorProto_EnumReservedRange = { encode( @@ -2385,7 +2130,7 @@ export const EnumDescriptorProto_EnumReservedRange = { decode(input: _m0.Reader | Uint8Array, length?: number): EnumDescriptorProto_EnumReservedRange { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseEnumDescriptorProto_EnumReservedRange } as EnumDescriptorProto_EnumReservedRange; + const message = createBaseEnumDescriptorProto_EnumReservedRange(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2404,38 +2149,32 @@ export const EnumDescriptorProto_EnumReservedRange = { }, fromJSON(object: any): EnumDescriptorProto_EnumReservedRange { - const message = { ...baseEnumDescriptorProto_EnumReservedRange } as EnumDescriptorProto_EnumReservedRange; - if (object.start !== undefined && object.start !== null) { - message.start = Number(object.start); - } else { - message.start = 0; - } - if (object.end !== undefined && object.end !== null) { - message.end = Number(object.end); - } else { - message.end = 0; - } - return message; + return { + start: isSet(object.start) ? Number(object.start) : 0, + end: isSet(object.end) ? Number(object.end) : 0, + }; }, toJSON(message: EnumDescriptorProto_EnumReservedRange): unknown { const obj: any = {}; - message.start !== undefined && (obj.start = message.start); - message.end !== undefined && (obj.end = message.end); + message.start !== undefined && (obj.start = Math.round(message.start)); + message.end !== undefined && (obj.end = Math.round(message.end)); return obj; }, - fromPartial( - object: DeepPartial, + fromPartial, I>>( + object: I, ): EnumDescriptorProto_EnumReservedRange { - const message = { ...baseEnumDescriptorProto_EnumReservedRange } as EnumDescriptorProto_EnumReservedRange; + const message = createBaseEnumDescriptorProto_EnumReservedRange(); message.start = object.start ?? 0; message.end = object.end ?? 0; return message; }, }; -const baseEnumValueDescriptorProto: object = { name: "", number: 0 }; +function createBaseEnumValueDescriptorProto(): EnumValueDescriptorProto { + return { name: "", number: 0, options: undefined }; +} export const EnumValueDescriptorProto = { encode(message: EnumValueDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2454,7 +2193,7 @@ export const EnumValueDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): EnumValueDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseEnumValueDescriptorProto } as EnumValueDescriptorProto; + const message = createBaseEnumValueDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2476,48 +2215,39 @@ export const EnumValueDescriptorProto = { }, fromJSON(object: any): EnumValueDescriptorProto { - const message = { ...baseEnumValueDescriptorProto } as EnumValueDescriptorProto; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.number !== undefined && object.number !== null) { - message.number = Number(object.number); - } else { - message.number = 0; - } - if (object.options !== undefined && object.options !== null) { - message.options = EnumValueOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + number: isSet(object.number) ? Number(object.number) : 0, + options: isSet(object.options) ? EnumValueOptions.fromJSON(object.options) : undefined, + }; }, toJSON(message: EnumValueDescriptorProto): unknown { const obj: any = {}; message.name !== undefined && (obj.name = message.name); - message.number !== undefined && (obj.number = message.number); + message.number !== undefined && (obj.number = Math.round(message.number)); message.options !== undefined && (obj.options = message.options ? EnumValueOptions.toJSON(message.options) : undefined); return obj; }, - fromPartial(object: DeepPartial): EnumValueDescriptorProto { - const message = { ...baseEnumValueDescriptorProto } as EnumValueDescriptorProto; + fromPartial, I>>( + object: I, + ): EnumValueDescriptorProto { + const message = createBaseEnumValueDescriptorProto(); message.name = object.name ?? ""; message.number = object.number ?? 0; - if (object.options !== undefined && object.options !== null) { - message.options = EnumValueOptions.fromPartial(object.options); - } else { - message.options = undefined; - } + message.options = + object.options !== undefined && object.options !== null + ? EnumValueOptions.fromPartial(object.options) + : undefined; return message; }, }; -const baseServiceDescriptorProto: object = { name: "" }; +function createBaseServiceDescriptorProto(): ServiceDescriptorProto { + return { name: "", method: [], options: undefined }; +} export const ServiceDescriptorProto = { encode(message: ServiceDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2536,8 +2266,7 @@ export const ServiceDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): ServiceDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseServiceDescriptorProto } as ServiceDescriptorProto; - message.method = []; + const message = createBaseServiceDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2559,24 +2288,13 @@ export const ServiceDescriptorProto = { }, fromJSON(object: any): ServiceDescriptorProto { - const message = { ...baseServiceDescriptorProto } as ServiceDescriptorProto; - message.method = []; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.method !== undefined && object.method !== null) { - for (const e of object.method) { - message.method.push(MethodDescriptorProto.fromJSON(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = ServiceOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + method: Array.isArray(object?.method) + ? object.method.map((e: any) => MethodDescriptorProto.fromJSON(e)) + : [], + options: isSet(object.options) ? ServiceOptions.fromJSON(object.options) : undefined, + }; }, toJSON(message: ServiceDescriptorProto): unknown { @@ -2592,31 +2310,28 @@ export const ServiceDescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): ServiceDescriptorProto { - const message = { ...baseServiceDescriptorProto } as ServiceDescriptorProto; + fromPartial, I>>(object: I): ServiceDescriptorProto { + const message = createBaseServiceDescriptorProto(); message.name = object.name ?? ""; - message.method = []; - if (object.method !== undefined && object.method !== null) { - for (const e of object.method) { - message.method.push(MethodDescriptorProto.fromPartial(e)); - } - } - if (object.options !== undefined && object.options !== null) { - message.options = ServiceOptions.fromPartial(object.options); - } else { - message.options = undefined; - } + message.method = object.method?.map((e) => MethodDescriptorProto.fromPartial(e)) || []; + message.options = + object.options !== undefined && object.options !== null + ? ServiceOptions.fromPartial(object.options) + : undefined; return message; }, }; -const baseMethodDescriptorProto: object = { - name: "", - inputType: "", - outputType: "", - clientStreaming: false, - serverStreaming: false, -}; +function createBaseMethodDescriptorProto(): MethodDescriptorProto { + return { + name: "", + inputType: "", + outputType: "", + options: undefined, + clientStreaming: false, + serverStreaming: false, + }; +} export const MethodDescriptorProto = { encode(message: MethodDescriptorProto, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2644,7 +2359,7 @@ export const MethodDescriptorProto = { decode(input: _m0.Reader | Uint8Array, length?: number): MethodDescriptorProto { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMethodDescriptorProto } as MethodDescriptorProto; + const message = createBaseMethodDescriptorProto(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2675,38 +2390,14 @@ export const MethodDescriptorProto = { }, fromJSON(object: any): MethodDescriptorProto { - const message = { ...baseMethodDescriptorProto } as MethodDescriptorProto; - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.inputType !== undefined && object.inputType !== null) { - message.inputType = String(object.inputType); - } else { - message.inputType = ""; - } - if (object.outputType !== undefined && object.outputType !== null) { - message.outputType = String(object.outputType); - } else { - message.outputType = ""; - } - if (object.options !== undefined && object.options !== null) { - message.options = MethodOptions.fromJSON(object.options); - } else { - message.options = undefined; - } - if (object.clientStreaming !== undefined && object.clientStreaming !== null) { - message.clientStreaming = Boolean(object.clientStreaming); - } else { - message.clientStreaming = false; - } - if (object.serverStreaming !== undefined && object.serverStreaming !== null) { - message.serverStreaming = Boolean(object.serverStreaming); - } else { - message.serverStreaming = false; - } - return message; + return { + name: isSet(object.name) ? String(object.name) : "", + inputType: isSet(object.inputType) ? String(object.inputType) : "", + outputType: isSet(object.outputType) ? String(object.outputType) : "", + options: isSet(object.options) ? MethodOptions.fromJSON(object.options) : undefined, + clientStreaming: isSet(object.clientStreaming) ? Boolean(object.clientStreaming) : false, + serverStreaming: isSet(object.serverStreaming) ? Boolean(object.serverStreaming) : false, + }; }, toJSON(message: MethodDescriptorProto): unknown { @@ -2721,44 +2412,46 @@ export const MethodDescriptorProto = { return obj; }, - fromPartial(object: DeepPartial): MethodDescriptorProto { - const message = { ...baseMethodDescriptorProto } as MethodDescriptorProto; + fromPartial, I>>(object: I): MethodDescriptorProto { + const message = createBaseMethodDescriptorProto(); message.name = object.name ?? ""; message.inputType = object.inputType ?? ""; message.outputType = object.outputType ?? ""; - if (object.options !== undefined && object.options !== null) { - message.options = MethodOptions.fromPartial(object.options); - } else { - message.options = undefined; - } + message.options = + object.options !== undefined && object.options !== null + ? MethodOptions.fromPartial(object.options) + : undefined; message.clientStreaming = object.clientStreaming ?? false; message.serverStreaming = object.serverStreaming ?? false; return message; }, }; -const baseFileOptions: object = { - javaPackage: "", - javaOuterClassname: "", - javaMultipleFiles: false, - javaGenerateEqualsAndHash: false, - javaStringCheckUtf8: false, - optimizeFor: 1, - goPackage: "", - ccGenericServices: false, - javaGenericServices: false, - pyGenericServices: false, - phpGenericServices: false, - deprecated: false, - ccEnableArenas: false, - objcClassPrefix: "", - csharpNamespace: "", - swiftPrefix: "", - phpClassPrefix: "", - phpNamespace: "", - phpMetadataNamespace: "", - rubyPackage: "", -}; +function createBaseFileOptions(): FileOptions { + return { + javaPackage: "", + javaOuterClassname: "", + javaMultipleFiles: false, + javaGenerateEqualsAndHash: false, + javaStringCheckUtf8: false, + optimizeFor: 1, + goPackage: "", + ccGenericServices: false, + javaGenericServices: false, + pyGenericServices: false, + phpGenericServices: false, + deprecated: false, + ccEnableArenas: false, + objcClassPrefix: "", + csharpNamespace: "", + swiftPrefix: "", + phpClassPrefix: "", + phpNamespace: "", + phpMetadataNamespace: "", + rubyPackage: "", + uninterpretedOption: [], + }; +} export const FileOptions = { encode(message: FileOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -2831,8 +2524,7 @@ export const FileOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): FileOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseFileOptions } as FileOptions; - message.uninterpretedOption = []; + const message = createBaseFileOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -2908,114 +2600,33 @@ export const FileOptions = { }, fromJSON(object: any): FileOptions { - const message = { ...baseFileOptions } as FileOptions; - message.uninterpretedOption = []; - if (object.javaPackage !== undefined && object.javaPackage !== null) { - message.javaPackage = String(object.javaPackage); - } else { - message.javaPackage = ""; - } - if (object.javaOuterClassname !== undefined && object.javaOuterClassname !== null) { - message.javaOuterClassname = String(object.javaOuterClassname); - } else { - message.javaOuterClassname = ""; - } - if (object.javaMultipleFiles !== undefined && object.javaMultipleFiles !== null) { - message.javaMultipleFiles = Boolean(object.javaMultipleFiles); - } else { - message.javaMultipleFiles = false; - } - if (object.javaGenerateEqualsAndHash !== undefined && object.javaGenerateEqualsAndHash !== null) { - message.javaGenerateEqualsAndHash = Boolean(object.javaGenerateEqualsAndHash); - } else { - message.javaGenerateEqualsAndHash = false; - } - if (object.javaStringCheckUtf8 !== undefined && object.javaStringCheckUtf8 !== null) { - message.javaStringCheckUtf8 = Boolean(object.javaStringCheckUtf8); - } else { - message.javaStringCheckUtf8 = false; - } - if (object.optimizeFor !== undefined && object.optimizeFor !== null) { - message.optimizeFor = fileOptions_OptimizeModeFromJSON(object.optimizeFor); - } else { - message.optimizeFor = 1; - } - if (object.goPackage !== undefined && object.goPackage !== null) { - message.goPackage = String(object.goPackage); - } else { - message.goPackage = ""; - } - if (object.ccGenericServices !== undefined && object.ccGenericServices !== null) { - message.ccGenericServices = Boolean(object.ccGenericServices); - } else { - message.ccGenericServices = false; - } - if (object.javaGenericServices !== undefined && object.javaGenericServices !== null) { - message.javaGenericServices = Boolean(object.javaGenericServices); - } else { - message.javaGenericServices = false; - } - if (object.pyGenericServices !== undefined && object.pyGenericServices !== null) { - message.pyGenericServices = Boolean(object.pyGenericServices); - } else { - message.pyGenericServices = false; - } - if (object.phpGenericServices !== undefined && object.phpGenericServices !== null) { - message.phpGenericServices = Boolean(object.phpGenericServices); - } else { - message.phpGenericServices = false; - } - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.ccEnableArenas !== undefined && object.ccEnableArenas !== null) { - message.ccEnableArenas = Boolean(object.ccEnableArenas); - } else { - message.ccEnableArenas = false; - } - if (object.objcClassPrefix !== undefined && object.objcClassPrefix !== null) { - message.objcClassPrefix = String(object.objcClassPrefix); - } else { - message.objcClassPrefix = ""; - } - if (object.csharpNamespace !== undefined && object.csharpNamespace !== null) { - message.csharpNamespace = String(object.csharpNamespace); - } else { - message.csharpNamespace = ""; - } - if (object.swiftPrefix !== undefined && object.swiftPrefix !== null) { - message.swiftPrefix = String(object.swiftPrefix); - } else { - message.swiftPrefix = ""; - } - if (object.phpClassPrefix !== undefined && object.phpClassPrefix !== null) { - message.phpClassPrefix = String(object.phpClassPrefix); - } else { - message.phpClassPrefix = ""; - } - if (object.phpNamespace !== undefined && object.phpNamespace !== null) { - message.phpNamespace = String(object.phpNamespace); - } else { - message.phpNamespace = ""; - } - if (object.phpMetadataNamespace !== undefined && object.phpMetadataNamespace !== null) { - message.phpMetadataNamespace = String(object.phpMetadataNamespace); - } else { - message.phpMetadataNamespace = ""; - } - if (object.rubyPackage !== undefined && object.rubyPackage !== null) { - message.rubyPackage = String(object.rubyPackage); - } else { - message.rubyPackage = ""; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + javaPackage: isSet(object.javaPackage) ? String(object.javaPackage) : "", + javaOuterClassname: isSet(object.javaOuterClassname) ? String(object.javaOuterClassname) : "", + javaMultipleFiles: isSet(object.javaMultipleFiles) ? Boolean(object.javaMultipleFiles) : false, + javaGenerateEqualsAndHash: isSet(object.javaGenerateEqualsAndHash) + ? Boolean(object.javaGenerateEqualsAndHash) + : false, + javaStringCheckUtf8: isSet(object.javaStringCheckUtf8) ? Boolean(object.javaStringCheckUtf8) : false, + optimizeFor: isSet(object.optimizeFor) ? fileOptions_OptimizeModeFromJSON(object.optimizeFor) : 1, + goPackage: isSet(object.goPackage) ? String(object.goPackage) : "", + ccGenericServices: isSet(object.ccGenericServices) ? Boolean(object.ccGenericServices) : false, + javaGenericServices: isSet(object.javaGenericServices) ? Boolean(object.javaGenericServices) : false, + pyGenericServices: isSet(object.pyGenericServices) ? Boolean(object.pyGenericServices) : false, + phpGenericServices: isSet(object.phpGenericServices) ? Boolean(object.phpGenericServices) : false, + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + ccEnableArenas: isSet(object.ccEnableArenas) ? Boolean(object.ccEnableArenas) : false, + objcClassPrefix: isSet(object.objcClassPrefix) ? String(object.objcClassPrefix) : "", + csharpNamespace: isSet(object.csharpNamespace) ? String(object.csharpNamespace) : "", + swiftPrefix: isSet(object.swiftPrefix) ? String(object.swiftPrefix) : "", + phpClassPrefix: isSet(object.phpClassPrefix) ? String(object.phpClassPrefix) : "", + phpNamespace: isSet(object.phpNamespace) ? String(object.phpNamespace) : "", + phpMetadataNamespace: isSet(object.phpMetadataNamespace) ? String(object.phpMetadataNamespace) : "", + rubyPackage: isSet(object.rubyPackage) ? String(object.rubyPackage) : "", + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: FileOptions): unknown { @@ -3052,8 +2663,8 @@ export const FileOptions = { return obj; }, - fromPartial(object: DeepPartial): FileOptions { - const message = { ...baseFileOptions } as FileOptions; + fromPartial, I>>(object: I): FileOptions { + const message = createBaseFileOptions(); message.javaPackage = object.javaPackage ?? ""; message.javaOuterClassname = object.javaOuterClassname ?? ""; message.javaMultipleFiles = object.javaMultipleFiles ?? false; @@ -3074,22 +2685,21 @@ export const FileOptions = { message.phpNamespace = object.phpNamespace ?? ""; message.phpMetadataNamespace = object.phpMetadataNamespace ?? ""; message.rubyPackage = object.rubyPackage ?? ""; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseMessageOptions: object = { - messageSetWireFormat: false, - noStandardDescriptorAccessor: false, - deprecated: false, - mapEntry: false, -}; +function createBaseMessageOptions(): MessageOptions { + return { + messageSetWireFormat: false, + noStandardDescriptorAccessor: false, + deprecated: false, + mapEntry: false, + uninterpretedOption: [], + }; +} export const MessageOptions = { encode(message: MessageOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3114,8 +2724,7 @@ export const MessageOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): MessageOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMessageOptions } as MessageOptions; - message.uninterpretedOption = []; + const message = createBaseMessageOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3143,34 +2752,17 @@ export const MessageOptions = { }, fromJSON(object: any): MessageOptions { - const message = { ...baseMessageOptions } as MessageOptions; - message.uninterpretedOption = []; - if (object.messageSetWireFormat !== undefined && object.messageSetWireFormat !== null) { - message.messageSetWireFormat = Boolean(object.messageSetWireFormat); - } else { - message.messageSetWireFormat = false; - } - if (object.noStandardDescriptorAccessor !== undefined && object.noStandardDescriptorAccessor !== null) { - message.noStandardDescriptorAccessor = Boolean(object.noStandardDescriptorAccessor); - } else { - message.noStandardDescriptorAccessor = false; - } - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.mapEntry !== undefined && object.mapEntry !== null) { - message.mapEntry = Boolean(object.mapEntry); - } else { - message.mapEntry = false; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + messageSetWireFormat: isSet(object.messageSetWireFormat) ? Boolean(object.messageSetWireFormat) : false, + noStandardDescriptorAccessor: isSet(object.noStandardDescriptorAccessor) + ? Boolean(object.noStandardDescriptorAccessor) + : false, + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + mapEntry: isSet(object.mapEntry) ? Boolean(object.mapEntry) : false, + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: MessageOptions): unknown { @@ -3190,30 +2782,29 @@ export const MessageOptions = { return obj; }, - fromPartial(object: DeepPartial): MessageOptions { - const message = { ...baseMessageOptions } as MessageOptions; + fromPartial, I>>(object: I): MessageOptions { + const message = createBaseMessageOptions(); message.messageSetWireFormat = object.messageSetWireFormat ?? false; message.noStandardDescriptorAccessor = object.noStandardDescriptorAccessor ?? false; message.deprecated = object.deprecated ?? false; message.mapEntry = object.mapEntry ?? false; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseFieldOptions: object = { - ctype: 0, - packed: false, - jstype: 0, - lazy: false, - deprecated: false, - weak: false, -}; +function createBaseFieldOptions(): FieldOptions { + return { + ctype: 0, + packed: false, + jstype: 0, + lazy: false, + deprecated: false, + weak: false, + uninterpretedOption: [], + }; +} export const FieldOptions = { encode(message: FieldOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3244,8 +2835,7 @@ export const FieldOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): FieldOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseFieldOptions } as FieldOptions; - message.uninterpretedOption = []; + const message = createBaseFieldOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3279,44 +2869,17 @@ export const FieldOptions = { }, fromJSON(object: any): FieldOptions { - const message = { ...baseFieldOptions } as FieldOptions; - message.uninterpretedOption = []; - if (object.ctype !== undefined && object.ctype !== null) { - message.ctype = fieldOptions_CTypeFromJSON(object.ctype); - } else { - message.ctype = 0; - } - if (object.packed !== undefined && object.packed !== null) { - message.packed = Boolean(object.packed); - } else { - message.packed = false; - } - if (object.jstype !== undefined && object.jstype !== null) { - message.jstype = fieldOptions_JSTypeFromJSON(object.jstype); - } else { - message.jstype = 0; - } - if (object.lazy !== undefined && object.lazy !== null) { - message.lazy = Boolean(object.lazy); - } else { - message.lazy = false; - } - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.weak !== undefined && object.weak !== null) { - message.weak = Boolean(object.weak); - } else { - message.weak = false; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + ctype: isSet(object.ctype) ? fieldOptions_CTypeFromJSON(object.ctype) : 0, + packed: isSet(object.packed) ? Boolean(object.packed) : false, + jstype: isSet(object.jstype) ? fieldOptions_JSTypeFromJSON(object.jstype) : 0, + lazy: isSet(object.lazy) ? Boolean(object.lazy) : false, + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + weak: isSet(object.weak) ? Boolean(object.weak) : false, + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: FieldOptions): unknown { @@ -3337,25 +2900,23 @@ export const FieldOptions = { return obj; }, - fromPartial(object: DeepPartial): FieldOptions { - const message = { ...baseFieldOptions } as FieldOptions; + fromPartial, I>>(object: I): FieldOptions { + const message = createBaseFieldOptions(); message.ctype = object.ctype ?? 0; message.packed = object.packed ?? false; message.jstype = object.jstype ?? 0; message.lazy = object.lazy ?? false; message.deprecated = object.deprecated ?? false; message.weak = object.weak ?? false; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseOneofOptions: object = {}; +function createBaseOneofOptions(): OneofOptions { + return { uninterpretedOption: [] }; +} export const OneofOptions = { encode(message: OneofOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3368,8 +2929,7 @@ export const OneofOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): OneofOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseOneofOptions } as OneofOptions; - message.uninterpretedOption = []; + const message = createBaseOneofOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3385,14 +2945,11 @@ export const OneofOptions = { }, fromJSON(object: any): OneofOptions { - const message = { ...baseOneofOptions } as OneofOptions; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: OneofOptions): unknown { @@ -3407,19 +2964,17 @@ export const OneofOptions = { return obj; }, - fromPartial(object: DeepPartial): OneofOptions { - const message = { ...baseOneofOptions } as OneofOptions; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + fromPartial, I>>(object: I): OneofOptions { + const message = createBaseOneofOptions(); + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseEnumOptions: object = { allowAlias: false, deprecated: false }; +function createBaseEnumOptions(): EnumOptions { + return { allowAlias: false, deprecated: false, uninterpretedOption: [] }; +} export const EnumOptions = { encode(message: EnumOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3438,8 +2993,7 @@ export const EnumOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): EnumOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseEnumOptions } as EnumOptions; - message.uninterpretedOption = []; + const message = createBaseEnumOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3461,24 +3015,13 @@ export const EnumOptions = { }, fromJSON(object: any): EnumOptions { - const message = { ...baseEnumOptions } as EnumOptions; - message.uninterpretedOption = []; - if (object.allowAlias !== undefined && object.allowAlias !== null) { - message.allowAlias = Boolean(object.allowAlias); - } else { - message.allowAlias = false; - } - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + allowAlias: isSet(object.allowAlias) ? Boolean(object.allowAlias) : false, + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: EnumOptions): unknown { @@ -3495,21 +3038,19 @@ export const EnumOptions = { return obj; }, - fromPartial(object: DeepPartial): EnumOptions { - const message = { ...baseEnumOptions } as EnumOptions; + fromPartial, I>>(object: I): EnumOptions { + const message = createBaseEnumOptions(); message.allowAlias = object.allowAlias ?? false; message.deprecated = object.deprecated ?? false; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseEnumValueOptions: object = { deprecated: false }; +function createBaseEnumValueOptions(): EnumValueOptions { + return { deprecated: false, uninterpretedOption: [] }; +} export const EnumValueOptions = { encode(message: EnumValueOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3525,8 +3066,7 @@ export const EnumValueOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): EnumValueOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseEnumValueOptions } as EnumValueOptions; - message.uninterpretedOption = []; + const message = createBaseEnumValueOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3545,19 +3085,12 @@ export const EnumValueOptions = { }, fromJSON(object: any): EnumValueOptions { - const message = { ...baseEnumValueOptions } as EnumValueOptions; - message.uninterpretedOption = []; - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: EnumValueOptions): unknown { @@ -3573,20 +3106,18 @@ export const EnumValueOptions = { return obj; }, - fromPartial(object: DeepPartial): EnumValueOptions { - const message = { ...baseEnumValueOptions } as EnumValueOptions; + fromPartial, I>>(object: I): EnumValueOptions { + const message = createBaseEnumValueOptions(); message.deprecated = object.deprecated ?? false; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseServiceOptions: object = { deprecated: false }; +function createBaseServiceOptions(): ServiceOptions { + return { deprecated: false, uninterpretedOption: [] }; +} export const ServiceOptions = { encode(message: ServiceOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3602,8 +3133,7 @@ export const ServiceOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): ServiceOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseServiceOptions } as ServiceOptions; - message.uninterpretedOption = []; + const message = createBaseServiceOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3622,19 +3152,12 @@ export const ServiceOptions = { }, fromJSON(object: any): ServiceOptions { - const message = { ...baseServiceOptions } as ServiceOptions; - message.uninterpretedOption = []; - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: ServiceOptions): unknown { @@ -3650,20 +3173,18 @@ export const ServiceOptions = { return obj; }, - fromPartial(object: DeepPartial): ServiceOptions { - const message = { ...baseServiceOptions } as ServiceOptions; + fromPartial, I>>(object: I): ServiceOptions { + const message = createBaseServiceOptions(); message.deprecated = object.deprecated ?? false; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseMethodOptions: object = { deprecated: false, idempotencyLevel: 0 }; +function createBaseMethodOptions(): MethodOptions { + return { deprecated: false, idempotencyLevel: 0, uninterpretedOption: [] }; +} export const MethodOptions = { encode(message: MethodOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3682,8 +3203,7 @@ export const MethodOptions = { decode(input: _m0.Reader | Uint8Array, length?: number): MethodOptions { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMethodOptions } as MethodOptions; - message.uninterpretedOption = []; + const message = createBaseMethodOptions(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3705,24 +3225,15 @@ export const MethodOptions = { }, fromJSON(object: any): MethodOptions { - const message = { ...baseMethodOptions } as MethodOptions; - message.uninterpretedOption = []; - if (object.deprecated !== undefined && object.deprecated !== null) { - message.deprecated = Boolean(object.deprecated); - } else { - message.deprecated = false; - } - if (object.idempotencyLevel !== undefined && object.idempotencyLevel !== null) { - message.idempotencyLevel = methodOptions_IdempotencyLevelFromJSON(object.idempotencyLevel); - } else { - message.idempotencyLevel = 0; - } - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromJSON(e)); - } - } - return message; + return { + deprecated: isSet(object.deprecated) ? Boolean(object.deprecated) : false, + idempotencyLevel: isSet(object.idempotencyLevel) + ? methodOptions_IdempotencyLevelFromJSON(object.idempotencyLevel) + : 0, + uninterpretedOption: Array.isArray(object?.uninterpretedOption) + ? object.uninterpretedOption.map((e: any) => UninterpretedOption.fromJSON(e)) + : [], + }; }, toJSON(message: MethodOptions): unknown { @@ -3740,27 +3251,27 @@ export const MethodOptions = { return obj; }, - fromPartial(object: DeepPartial): MethodOptions { - const message = { ...baseMethodOptions } as MethodOptions; + fromPartial, I>>(object: I): MethodOptions { + const message = createBaseMethodOptions(); message.deprecated = object.deprecated ?? false; message.idempotencyLevel = object.idempotencyLevel ?? 0; - message.uninterpretedOption = []; - if (object.uninterpretedOption !== undefined && object.uninterpretedOption !== null) { - for (const e of object.uninterpretedOption) { - message.uninterpretedOption.push(UninterpretedOption.fromPartial(e)); - } - } + message.uninterpretedOption = + object.uninterpretedOption?.map((e) => UninterpretedOption.fromPartial(e)) || []; return message; }, }; -const baseUninterpretedOption: object = { - identifierValue: "", - positiveIntValue: Long.UZERO, - negativeIntValue: Long.ZERO, - doubleValue: 0, - aggregateValue: "", -}; +function createBaseUninterpretedOption(): UninterpretedOption { + return { + name: [], + identifierValue: "", + positiveIntValue: Long.UZERO, + negativeIntValue: Long.ZERO, + doubleValue: 0, + stringValue: new Uint8Array(), + aggregateValue: "", + }; +} export const UninterpretedOption = { encode(message: UninterpretedOption, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3791,9 +3302,7 @@ export const UninterpretedOption = { decode(input: _m0.Reader | Uint8Array, length?: number): UninterpretedOption { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseUninterpretedOption } as UninterpretedOption; - message.name = []; - message.stringValue = new Uint8Array(); + const message = createBaseUninterpretedOption(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3827,43 +3336,19 @@ export const UninterpretedOption = { }, fromJSON(object: any): UninterpretedOption { - const message = { ...baseUninterpretedOption } as UninterpretedOption; - message.name = []; - message.stringValue = new Uint8Array(); - if (object.name !== undefined && object.name !== null) { - for (const e of object.name) { - message.name.push(UninterpretedOption_NamePart.fromJSON(e)); - } - } - if (object.identifierValue !== undefined && object.identifierValue !== null) { - message.identifierValue = String(object.identifierValue); - } else { - message.identifierValue = ""; - } - if (object.positiveIntValue !== undefined && object.positiveIntValue !== null) { - message.positiveIntValue = Long.fromString(object.positiveIntValue); - } else { - message.positiveIntValue = Long.UZERO; - } - if (object.negativeIntValue !== undefined && object.negativeIntValue !== null) { - message.negativeIntValue = Long.fromString(object.negativeIntValue); - } else { - message.negativeIntValue = Long.ZERO; - } - if (object.doubleValue !== undefined && object.doubleValue !== null) { - message.doubleValue = Number(object.doubleValue); - } else { - message.doubleValue = 0; - } - if (object.stringValue !== undefined && object.stringValue !== null) { - message.stringValue = bytesFromBase64(object.stringValue); - } - if (object.aggregateValue !== undefined && object.aggregateValue !== null) { - message.aggregateValue = String(object.aggregateValue); - } else { - message.aggregateValue = ""; - } - return message; + return { + name: Array.isArray(object?.name) + ? object.name.map((e: any) => UninterpretedOption_NamePart.fromJSON(e)) + : [], + identifierValue: isSet(object.identifierValue) ? String(object.identifierValue) : "", + positiveIntValue: isSet(object.positiveIntValue) + ? Long.fromString(object.positiveIntValue) + : Long.UZERO, + negativeIntValue: isSet(object.negativeIntValue) ? Long.fromString(object.negativeIntValue) : Long.ZERO, + doubleValue: isSet(object.doubleValue) ? Number(object.doubleValue) : 0, + stringValue: isSet(object.stringValue) ? bytesFromBase64(object.stringValue) : new Uint8Array(), + aggregateValue: isSet(object.aggregateValue) ? String(object.aggregateValue) : "", + }; }, toJSON(message: UninterpretedOption): unknown { @@ -3887,25 +3372,18 @@ export const UninterpretedOption = { return obj; }, - fromPartial(object: DeepPartial): UninterpretedOption { - const message = { ...baseUninterpretedOption } as UninterpretedOption; - message.name = []; - if (object.name !== undefined && object.name !== null) { - for (const e of object.name) { - message.name.push(UninterpretedOption_NamePart.fromPartial(e)); - } - } + fromPartial, I>>(object: I): UninterpretedOption { + const message = createBaseUninterpretedOption(); + message.name = object.name?.map((e) => UninterpretedOption_NamePart.fromPartial(e)) || []; message.identifierValue = object.identifierValue ?? ""; - if (object.positiveIntValue !== undefined && object.positiveIntValue !== null) { - message.positiveIntValue = object.positiveIntValue as Long; - } else { - message.positiveIntValue = Long.UZERO; - } - if (object.negativeIntValue !== undefined && object.negativeIntValue !== null) { - message.negativeIntValue = object.negativeIntValue as Long; - } else { - message.negativeIntValue = Long.ZERO; - } + message.positiveIntValue = + object.positiveIntValue !== undefined && object.positiveIntValue !== null + ? Long.fromValue(object.positiveIntValue) + : Long.UZERO; + message.negativeIntValue = + object.negativeIntValue !== undefined && object.negativeIntValue !== null + ? Long.fromValue(object.negativeIntValue) + : Long.ZERO; message.doubleValue = object.doubleValue ?? 0; message.stringValue = object.stringValue ?? new Uint8Array(); message.aggregateValue = object.aggregateValue ?? ""; @@ -3913,7 +3391,9 @@ export const UninterpretedOption = { }, }; -const baseUninterpretedOption_NamePart: object = { namePart: "", isExtension: false }; +function createBaseUninterpretedOption_NamePart(): UninterpretedOption_NamePart { + return { namePart: "", isExtension: false }; +} export const UninterpretedOption_NamePart = { encode(message: UninterpretedOption_NamePart, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3929,7 +3409,7 @@ export const UninterpretedOption_NamePart = { decode(input: _m0.Reader | Uint8Array, length?: number): UninterpretedOption_NamePart { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseUninterpretedOption_NamePart } as UninterpretedOption_NamePart; + const message = createBaseUninterpretedOption_NamePart(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -3948,18 +3428,10 @@ export const UninterpretedOption_NamePart = { }, fromJSON(object: any): UninterpretedOption_NamePart { - const message = { ...baseUninterpretedOption_NamePart } as UninterpretedOption_NamePart; - if (object.namePart !== undefined && object.namePart !== null) { - message.namePart = String(object.namePart); - } else { - message.namePart = ""; - } - if (object.isExtension !== undefined && object.isExtension !== null) { - message.isExtension = Boolean(object.isExtension); - } else { - message.isExtension = false; - } - return message; + return { + namePart: isSet(object.namePart) ? String(object.namePart) : "", + isExtension: isSet(object.isExtension) ? Boolean(object.isExtension) : false, + }; }, toJSON(message: UninterpretedOption_NamePart): unknown { @@ -3969,15 +3441,19 @@ export const UninterpretedOption_NamePart = { return obj; }, - fromPartial(object: DeepPartial): UninterpretedOption_NamePart { - const message = { ...baseUninterpretedOption_NamePart } as UninterpretedOption_NamePart; + fromPartial, I>>( + object: I, + ): UninterpretedOption_NamePart { + const message = createBaseUninterpretedOption_NamePart(); message.namePart = object.namePart ?? ""; message.isExtension = object.isExtension ?? false; return message; }, }; -const baseSourceCodeInfo: object = {}; +function createBaseSourceCodeInfo(): SourceCodeInfo { + return { location: [] }; +} export const SourceCodeInfo = { encode(message: SourceCodeInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -3990,8 +3466,7 @@ export const SourceCodeInfo = { decode(input: _m0.Reader | Uint8Array, length?: number): SourceCodeInfo { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSourceCodeInfo } as SourceCodeInfo; - message.location = []; + const message = createBaseSourceCodeInfo(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -4007,14 +3482,11 @@ export const SourceCodeInfo = { }, fromJSON(object: any): SourceCodeInfo { - const message = { ...baseSourceCodeInfo } as SourceCodeInfo; - message.location = []; - if (object.location !== undefined && object.location !== null) { - for (const e of object.location) { - message.location.push(SourceCodeInfo_Location.fromJSON(e)); - } - } - return message; + return { + location: Array.isArray(object?.location) + ? object.location.map((e: any) => SourceCodeInfo_Location.fromJSON(e)) + : [], + }; }, toJSON(message: SourceCodeInfo): unknown { @@ -4027,25 +3499,16 @@ export const SourceCodeInfo = { return obj; }, - fromPartial(object: DeepPartial): SourceCodeInfo { - const message = { ...baseSourceCodeInfo } as SourceCodeInfo; - message.location = []; - if (object.location !== undefined && object.location !== null) { - for (const e of object.location) { - message.location.push(SourceCodeInfo_Location.fromPartial(e)); - } - } + fromPartial, I>>(object: I): SourceCodeInfo { + const message = createBaseSourceCodeInfo(); + message.location = object.location?.map((e) => SourceCodeInfo_Location.fromPartial(e)) || []; return message; }, }; -const baseSourceCodeInfo_Location: object = { - path: 0, - span: 0, - leadingComments: "", - trailingComments: "", - leadingDetachedComments: "", -}; +function createBaseSourceCodeInfo_Location(): SourceCodeInfo_Location { + return { path: [], span: [], leadingComments: "", trailingComments: "", leadingDetachedComments: [] }; +} export const SourceCodeInfo_Location = { encode(message: SourceCodeInfo_Location, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -4074,10 +3537,7 @@ export const SourceCodeInfo_Location = { decode(input: _m0.Reader | Uint8Array, length?: number): SourceCodeInfo_Location { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSourceCodeInfo_Location } as SourceCodeInfo_Location; - message.path = []; - message.span = []; - message.leadingDetachedComments = []; + const message = createBaseSourceCodeInfo_Location(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -4119,47 +3579,26 @@ export const SourceCodeInfo_Location = { }, fromJSON(object: any): SourceCodeInfo_Location { - const message = { ...baseSourceCodeInfo_Location } as SourceCodeInfo_Location; - message.path = []; - message.span = []; - message.leadingDetachedComments = []; - if (object.path !== undefined && object.path !== null) { - for (const e of object.path) { - message.path.push(Number(e)); - } - } - if (object.span !== undefined && object.span !== null) { - for (const e of object.span) { - message.span.push(Number(e)); - } - } - if (object.leadingComments !== undefined && object.leadingComments !== null) { - message.leadingComments = String(object.leadingComments); - } else { - message.leadingComments = ""; - } - if (object.trailingComments !== undefined && object.trailingComments !== null) { - message.trailingComments = String(object.trailingComments); - } else { - message.trailingComments = ""; - } - if (object.leadingDetachedComments !== undefined && object.leadingDetachedComments !== null) { - for (const e of object.leadingDetachedComments) { - message.leadingDetachedComments.push(String(e)); - } - } - return message; + return { + path: Array.isArray(object?.path) ? object.path.map((e: any) => Number(e)) : [], + span: Array.isArray(object?.span) ? object.span.map((e: any) => Number(e)) : [], + leadingComments: isSet(object.leadingComments) ? String(object.leadingComments) : "", + trailingComments: isSet(object.trailingComments) ? String(object.trailingComments) : "", + leadingDetachedComments: Array.isArray(object?.leadingDetachedComments) + ? object.leadingDetachedComments.map((e: any) => String(e)) + : [], + }; }, toJSON(message: SourceCodeInfo_Location): unknown { const obj: any = {}; if (message.path) { - obj.path = message.path.map((e) => e); + obj.path = message.path.map((e) => Math.round(e)); } else { obj.path = []; } if (message.span) { - obj.span = message.span.map((e) => e); + obj.span = message.span.map((e) => Math.round(e)); } else { obj.span = []; } @@ -4173,33 +3612,20 @@ export const SourceCodeInfo_Location = { return obj; }, - fromPartial(object: DeepPartial): SourceCodeInfo_Location { - const message = { ...baseSourceCodeInfo_Location } as SourceCodeInfo_Location; - message.path = []; - if (object.path !== undefined && object.path !== null) { - for (const e of object.path) { - message.path.push(e); - } - } - message.span = []; - if (object.span !== undefined && object.span !== null) { - for (const e of object.span) { - message.span.push(e); - } - } + fromPartial, I>>(object: I): SourceCodeInfo_Location { + const message = createBaseSourceCodeInfo_Location(); + message.path = object.path?.map((e) => e) || []; + message.span = object.span?.map((e) => e) || []; message.leadingComments = object.leadingComments ?? ""; message.trailingComments = object.trailingComments ?? ""; - message.leadingDetachedComments = []; - if (object.leadingDetachedComments !== undefined && object.leadingDetachedComments !== null) { - for (const e of object.leadingDetachedComments) { - message.leadingDetachedComments.push(e); - } - } + message.leadingDetachedComments = object.leadingDetachedComments?.map((e) => e) || []; return message; }, }; -const baseGeneratedCodeInfo: object = {}; +function createBaseGeneratedCodeInfo(): GeneratedCodeInfo { + return { annotation: [] }; +} export const GeneratedCodeInfo = { encode(message: GeneratedCodeInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -4212,8 +3638,7 @@ export const GeneratedCodeInfo = { decode(input: _m0.Reader | Uint8Array, length?: number): GeneratedCodeInfo { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseGeneratedCodeInfo } as GeneratedCodeInfo; - message.annotation = []; + const message = createBaseGeneratedCodeInfo(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -4229,14 +3654,11 @@ export const GeneratedCodeInfo = { }, fromJSON(object: any): GeneratedCodeInfo { - const message = { ...baseGeneratedCodeInfo } as GeneratedCodeInfo; - message.annotation = []; - if (object.annotation !== undefined && object.annotation !== null) { - for (const e of object.annotation) { - message.annotation.push(GeneratedCodeInfo_Annotation.fromJSON(e)); - } - } - return message; + return { + annotation: Array.isArray(object?.annotation) + ? object.annotation.map((e: any) => GeneratedCodeInfo_Annotation.fromJSON(e)) + : [], + }; }, toJSON(message: GeneratedCodeInfo): unknown { @@ -4251,19 +3673,16 @@ export const GeneratedCodeInfo = { return obj; }, - fromPartial(object: DeepPartial): GeneratedCodeInfo { - const message = { ...baseGeneratedCodeInfo } as GeneratedCodeInfo; - message.annotation = []; - if (object.annotation !== undefined && object.annotation !== null) { - for (const e of object.annotation) { - message.annotation.push(GeneratedCodeInfo_Annotation.fromPartial(e)); - } - } + fromPartial, I>>(object: I): GeneratedCodeInfo { + const message = createBaseGeneratedCodeInfo(); + message.annotation = object.annotation?.map((e) => GeneratedCodeInfo_Annotation.fromPartial(e)) || []; return message; }, }; -const baseGeneratedCodeInfo_Annotation: object = { path: 0, sourceFile: "", begin: 0, end: 0 }; +function createBaseGeneratedCodeInfo_Annotation(): GeneratedCodeInfo_Annotation { + return { path: [], sourceFile: "", begin: 0, end: 0 }; +} export const GeneratedCodeInfo_Annotation = { encode(message: GeneratedCodeInfo_Annotation, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -4287,8 +3706,7 @@ export const GeneratedCodeInfo_Annotation = { decode(input: _m0.Reader | Uint8Array, length?: number): GeneratedCodeInfo_Annotation { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseGeneratedCodeInfo_Annotation } as GeneratedCodeInfo_Annotation; - message.path = []; + const message = createBaseGeneratedCodeInfo_Annotation(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -4320,52 +3738,32 @@ export const GeneratedCodeInfo_Annotation = { }, fromJSON(object: any): GeneratedCodeInfo_Annotation { - const message = { ...baseGeneratedCodeInfo_Annotation } as GeneratedCodeInfo_Annotation; - message.path = []; - if (object.path !== undefined && object.path !== null) { - for (const e of object.path) { - message.path.push(Number(e)); - } - } - if (object.sourceFile !== undefined && object.sourceFile !== null) { - message.sourceFile = String(object.sourceFile); - } else { - message.sourceFile = ""; - } - if (object.begin !== undefined && object.begin !== null) { - message.begin = Number(object.begin); - } else { - message.begin = 0; - } - if (object.end !== undefined && object.end !== null) { - message.end = Number(object.end); - } else { - message.end = 0; - } - return message; + return { + path: Array.isArray(object?.path) ? object.path.map((e: any) => Number(e)) : [], + sourceFile: isSet(object.sourceFile) ? String(object.sourceFile) : "", + begin: isSet(object.begin) ? Number(object.begin) : 0, + end: isSet(object.end) ? Number(object.end) : 0, + }; }, toJSON(message: GeneratedCodeInfo_Annotation): unknown { const obj: any = {}; if (message.path) { - obj.path = message.path.map((e) => e); + obj.path = message.path.map((e) => Math.round(e)); } else { obj.path = []; } message.sourceFile !== undefined && (obj.sourceFile = message.sourceFile); - message.begin !== undefined && (obj.begin = message.begin); - message.end !== undefined && (obj.end = message.end); + message.begin !== undefined && (obj.begin = Math.round(message.begin)); + message.end !== undefined && (obj.end = Math.round(message.end)); return obj; }, - fromPartial(object: DeepPartial): GeneratedCodeInfo_Annotation { - const message = { ...baseGeneratedCodeInfo_Annotation } as GeneratedCodeInfo_Annotation; - message.path = []; - if (object.path !== undefined && object.path !== null) { - for (const e of object.path) { - message.path.push(e); - } - } + fromPartial, I>>( + object: I, + ): GeneratedCodeInfo_Annotation { + const message = createBaseGeneratedCodeInfo_Annotation(); + message.path = object.path?.map((e) => e) || []; message.sourceFile = object.sourceFile ?? ""; message.begin = object.begin ?? 0; message.end = object.end ?? 0; @@ -4399,15 +3797,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -4416,7 +3817,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/google/protobuf/duration.ts b/src/codec/google/protobuf/duration.ts index 62284c8c..e9bda3ed 100644 --- a/src/codec/google/protobuf/duration.ts +++ b/src/codec/google/protobuf/duration.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "google.protobuf"; @@ -82,7 +82,9 @@ export interface Duration { nanos: number; } -const baseDuration: object = { seconds: Long.ZERO, nanos: 0 }; +function createBaseDuration(): Duration { + return { seconds: Long.ZERO, nanos: 0 }; +} export const Duration = { encode(message: Duration, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -98,7 +100,7 @@ export const Duration = { decode(input: _m0.Reader | Uint8Array, length?: number): Duration { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDuration } as Duration; + const message = createBaseDuration(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -117,42 +119,34 @@ export const Duration = { }, fromJSON(object: any): Duration { - const message = { ...baseDuration } as Duration; - if (object.seconds !== undefined && object.seconds !== null) { - message.seconds = Long.fromString(object.seconds); - } else { - message.seconds = Long.ZERO; - } - if (object.nanos !== undefined && object.nanos !== null) { - message.nanos = Number(object.nanos); - } else { - message.nanos = 0; - } - return message; + return { + seconds: isSet(object.seconds) ? Long.fromString(object.seconds) : Long.ZERO, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; }, toJSON(message: Duration): unknown { const obj: any = {}; message.seconds !== undefined && (obj.seconds = (message.seconds || Long.ZERO).toString()); - message.nanos !== undefined && (obj.nanos = message.nanos); + message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)); return obj; }, - fromPartial(object: DeepPartial): Duration { - const message = { ...baseDuration } as Duration; - if (object.seconds !== undefined && object.seconds !== null) { - message.seconds = object.seconds as Long; - } else { - message.seconds = Long.ZERO; - } + fromPartial, I>>(object: I): Duration { + const message = createBaseDuration(); + message.seconds = + object.seconds !== undefined && object.seconds !== null ? Long.fromValue(object.seconds) : Long.ZERO; message.nanos = object.nanos ?? 0; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -161,7 +155,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/google/protobuf/timestamp.ts b/src/codec/google/protobuf/timestamp.ts index ea68eb88..57a13300 100644 --- a/src/codec/google/protobuf/timestamp.ts +++ b/src/codec/google/protobuf/timestamp.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "google.protobuf"; @@ -113,7 +113,9 @@ export interface Timestamp { nanos: number; } -const baseTimestamp: object = { seconds: Long.ZERO, nanos: 0 }; +function createBaseTimestamp(): Timestamp { + return { seconds: Long.ZERO, nanos: 0 }; +} export const Timestamp = { encode(message: Timestamp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -129,7 +131,7 @@ export const Timestamp = { decode(input: _m0.Reader | Uint8Array, length?: number): Timestamp { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseTimestamp } as Timestamp; + const message = createBaseTimestamp(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -148,42 +150,34 @@ export const Timestamp = { }, fromJSON(object: any): Timestamp { - const message = { ...baseTimestamp } as Timestamp; - if (object.seconds !== undefined && object.seconds !== null) { - message.seconds = Long.fromString(object.seconds); - } else { - message.seconds = Long.ZERO; - } - if (object.nanos !== undefined && object.nanos !== null) { - message.nanos = Number(object.nanos); - } else { - message.nanos = 0; - } - return message; + return { + seconds: isSet(object.seconds) ? Long.fromString(object.seconds) : Long.ZERO, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; }, toJSON(message: Timestamp): unknown { const obj: any = {}; message.seconds !== undefined && (obj.seconds = (message.seconds || Long.ZERO).toString()); - message.nanos !== undefined && (obj.nanos = message.nanos); + message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)); return obj; }, - fromPartial(object: DeepPartial): Timestamp { - const message = { ...baseTimestamp } as Timestamp; - if (object.seconds !== undefined && object.seconds !== null) { - message.seconds = object.seconds as Long; - } else { - message.seconds = Long.ZERO; - } + fromPartial, I>>(object: I): Timestamp { + const message = createBaseTimestamp(); + message.seconds = + object.seconds !== undefined && object.seconds !== null ? Long.fromValue(object.seconds) : Long.ZERO; message.nanos = object.nanos ?? 0; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -192,7 +186,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/tendermint/crypto/keys.ts b/src/codec/tendermint/crypto/keys.ts index 436f61a6..919de0db 100644 --- a/src/codec/tendermint/crypto/keys.ts +++ b/src/codec/tendermint/crypto/keys.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "tendermint.crypto"; @@ -10,7 +10,9 @@ export interface PublicKey { secp256k1: Uint8Array | undefined; } -const basePublicKey: object = {}; +function createBasePublicKey(): PublicKey { + return { ed25519: undefined, secp256k1: undefined }; +} export const PublicKey = { encode(message: PublicKey, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -26,7 +28,7 @@ export const PublicKey = { decode(input: _m0.Reader | Uint8Array, length?: number): PublicKey { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...basePublicKey } as PublicKey; + const message = createBasePublicKey(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -45,14 +47,10 @@ export const PublicKey = { }, fromJSON(object: any): PublicKey { - const message = { ...basePublicKey } as PublicKey; - if (object.ed25519 !== undefined && object.ed25519 !== null) { - message.ed25519 = bytesFromBase64(object.ed25519); - } - if (object.secp256k1 !== undefined && object.secp256k1 !== null) { - message.secp256k1 = bytesFromBase64(object.secp256k1); - } - return message; + return { + ed25519: isSet(object.ed25519) ? bytesFromBase64(object.ed25519) : undefined, + secp256k1: isSet(object.secp256k1) ? bytesFromBase64(object.secp256k1) : undefined, + }; }, toJSON(message: PublicKey): unknown { @@ -64,8 +62,8 @@ export const PublicKey = { return obj; }, - fromPartial(object: DeepPartial): PublicKey { - const message = { ...basePublicKey } as PublicKey; + fromPartial, I>>(object: I): PublicKey { + const message = createBasePublicKey(); message.ed25519 = object.ed25519 ?? undefined; message.secp256k1 = object.secp256k1 ?? undefined; return message; @@ -98,15 +96,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -115,7 +116,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/tendermint/crypto/proof.ts b/src/codec/tendermint/crypto/proof.ts index 4a7bcf37..b68c5005 100644 --- a/src/codec/tendermint/crypto/proof.ts +++ b/src/codec/tendermint/crypto/proof.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "tendermint.crypto"; @@ -40,7 +40,9 @@ export interface ProofOps { ops: ProofOp[]; } -const baseProof: object = { total: Long.ZERO, index: Long.ZERO }; +function createBaseProof(): Proof { + return { total: Long.ZERO, index: Long.ZERO, leafHash: new Uint8Array(), aunts: [] }; +} export const Proof = { encode(message: Proof, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -62,9 +64,7 @@ export const Proof = { decode(input: _m0.Reader | Uint8Array, length?: number): Proof { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseProof } as Proof; - message.aunts = []; - message.leafHash = new Uint8Array(); + const message = createBaseProof(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -89,28 +89,12 @@ export const Proof = { }, fromJSON(object: any): Proof { - const message = { ...baseProof } as Proof; - message.aunts = []; - message.leafHash = new Uint8Array(); - if (object.total !== undefined && object.total !== null) { - message.total = Long.fromString(object.total); - } else { - message.total = Long.ZERO; - } - if (object.index !== undefined && object.index !== null) { - message.index = Long.fromString(object.index); - } else { - message.index = Long.ZERO; - } - if (object.leafHash !== undefined && object.leafHash !== null) { - message.leafHash = bytesFromBase64(object.leafHash); - } - if (object.aunts !== undefined && object.aunts !== null) { - for (const e of object.aunts) { - message.aunts.push(bytesFromBase64(e)); - } - } - return message; + return { + total: isSet(object.total) ? Long.fromString(object.total) : Long.ZERO, + index: isSet(object.index) ? Long.fromString(object.index) : Long.ZERO, + leafHash: isSet(object.leafHash) ? bytesFromBase64(object.leafHash) : new Uint8Array(), + aunts: Array.isArray(object?.aunts) ? object.aunts.map((e: any) => bytesFromBase64(e)) : [], + }; }, toJSON(message: Proof): unknown { @@ -127,30 +111,21 @@ export const Proof = { return obj; }, - fromPartial(object: DeepPartial): Proof { - const message = { ...baseProof } as Proof; - if (object.total !== undefined && object.total !== null) { - message.total = object.total as Long; - } else { - message.total = Long.ZERO; - } - if (object.index !== undefined && object.index !== null) { - message.index = object.index as Long; - } else { - message.index = Long.ZERO; - } + fromPartial, I>>(object: I): Proof { + const message = createBaseProof(); + message.total = + object.total !== undefined && object.total !== null ? Long.fromValue(object.total) : Long.ZERO; + message.index = + object.index !== undefined && object.index !== null ? Long.fromValue(object.index) : Long.ZERO; message.leafHash = object.leafHash ?? new Uint8Array(); - message.aunts = []; - if (object.aunts !== undefined && object.aunts !== null) { - for (const e of object.aunts) { - message.aunts.push(e); - } - } + message.aunts = object.aunts?.map((e) => e) || []; return message; }, }; -const baseValueOp: object = {}; +function createBaseValueOp(): ValueOp { + return { key: new Uint8Array(), proof: undefined }; +} export const ValueOp = { encode(message: ValueOp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -166,8 +141,7 @@ export const ValueOp = { decode(input: _m0.Reader | Uint8Array, length?: number): ValueOp { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseValueOp } as ValueOp; - message.key = new Uint8Array(); + const message = createBaseValueOp(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -186,17 +160,10 @@ export const ValueOp = { }, fromJSON(object: any): ValueOp { - const message = { ...baseValueOp } as ValueOp; - message.key = new Uint8Array(); - if (object.key !== undefined && object.key !== null) { - message.key = bytesFromBase64(object.key); - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = Proof.fromJSON(object.proof); - } else { - message.proof = undefined; - } - return message; + return { + key: isSet(object.key) ? bytesFromBase64(object.key) : new Uint8Array(), + proof: isSet(object.proof) ? Proof.fromJSON(object.proof) : undefined, + }; }, toJSON(message: ValueOp): unknown { @@ -207,19 +174,18 @@ export const ValueOp = { return obj; }, - fromPartial(object: DeepPartial): ValueOp { - const message = { ...baseValueOp } as ValueOp; + fromPartial, I>>(object: I): ValueOp { + const message = createBaseValueOp(); message.key = object.key ?? new Uint8Array(); - if (object.proof !== undefined && object.proof !== null) { - message.proof = Proof.fromPartial(object.proof); - } else { - message.proof = undefined; - } + message.proof = + object.proof !== undefined && object.proof !== null ? Proof.fromPartial(object.proof) : undefined; return message; }, }; -const baseDominoOp: object = { key: "", input: "", output: "" }; +function createBaseDominoOp(): DominoOp { + return { key: "", input: "", output: "" }; +} export const DominoOp = { encode(message: DominoOp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -238,7 +204,7 @@ export const DominoOp = { decode(input: _m0.Reader | Uint8Array, length?: number): DominoOp { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDominoOp } as DominoOp; + const message = createBaseDominoOp(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -260,23 +226,11 @@ export const DominoOp = { }, fromJSON(object: any): DominoOp { - const message = { ...baseDominoOp } as DominoOp; - if (object.key !== undefined && object.key !== null) { - message.key = String(object.key); - } else { - message.key = ""; - } - if (object.input !== undefined && object.input !== null) { - message.input = String(object.input); - } else { - message.input = ""; - } - if (object.output !== undefined && object.output !== null) { - message.output = String(object.output); - } else { - message.output = ""; - } - return message; + return { + key: isSet(object.key) ? String(object.key) : "", + input: isSet(object.input) ? String(object.input) : "", + output: isSet(object.output) ? String(object.output) : "", + }; }, toJSON(message: DominoOp): unknown { @@ -287,8 +241,8 @@ export const DominoOp = { return obj; }, - fromPartial(object: DeepPartial): DominoOp { - const message = { ...baseDominoOp } as DominoOp; + fromPartial, I>>(object: I): DominoOp { + const message = createBaseDominoOp(); message.key = object.key ?? ""; message.input = object.input ?? ""; message.output = object.output ?? ""; @@ -296,7 +250,9 @@ export const DominoOp = { }, }; -const baseProofOp: object = { type: "" }; +function createBaseProofOp(): ProofOp { + return { type: "", key: new Uint8Array(), data: new Uint8Array() }; +} export const ProofOp = { encode(message: ProofOp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -315,9 +271,7 @@ export const ProofOp = { decode(input: _m0.Reader | Uint8Array, length?: number): ProofOp { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseProofOp } as ProofOp; - message.key = new Uint8Array(); - message.data = new Uint8Array(); + const message = createBaseProofOp(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -339,21 +293,11 @@ export const ProofOp = { }, fromJSON(object: any): ProofOp { - const message = { ...baseProofOp } as ProofOp; - message.key = new Uint8Array(); - message.data = new Uint8Array(); - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.key !== undefined && object.key !== null) { - message.key = bytesFromBase64(object.key); - } - if (object.data !== undefined && object.data !== null) { - message.data = bytesFromBase64(object.data); - } - return message; + return { + type: isSet(object.type) ? String(object.type) : "", + key: isSet(object.key) ? bytesFromBase64(object.key) : new Uint8Array(), + data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(), + }; }, toJSON(message: ProofOp): unknown { @@ -366,8 +310,8 @@ export const ProofOp = { return obj; }, - fromPartial(object: DeepPartial): ProofOp { - const message = { ...baseProofOp } as ProofOp; + fromPartial, I>>(object: I): ProofOp { + const message = createBaseProofOp(); message.type = object.type ?? ""; message.key = object.key ?? new Uint8Array(); message.data = object.data ?? new Uint8Array(); @@ -375,7 +319,9 @@ export const ProofOp = { }, }; -const baseProofOps: object = {}; +function createBaseProofOps(): ProofOps { + return { ops: [] }; +} export const ProofOps = { encode(message: ProofOps, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -388,8 +334,7 @@ export const ProofOps = { decode(input: _m0.Reader | Uint8Array, length?: number): ProofOps { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseProofOps } as ProofOps; - message.ops = []; + const message = createBaseProofOps(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -405,14 +350,9 @@ export const ProofOps = { }, fromJSON(object: any): ProofOps { - const message = { ...baseProofOps } as ProofOps; - message.ops = []; - if (object.ops !== undefined && object.ops !== null) { - for (const e of object.ops) { - message.ops.push(ProofOp.fromJSON(e)); - } - } - return message; + return { + ops: Array.isArray(object?.ops) ? object.ops.map((e: any) => ProofOp.fromJSON(e)) : [], + }; }, toJSON(message: ProofOps): unknown { @@ -425,14 +365,9 @@ export const ProofOps = { return obj; }, - fromPartial(object: DeepPartial): ProofOps { - const message = { ...baseProofOps } as ProofOps; - message.ops = []; - if (object.ops !== undefined && object.ops !== null) { - for (const e of object.ops) { - message.ops.push(ProofOp.fromPartial(e)); - } - } + fromPartial, I>>(object: I): ProofOps { + const message = createBaseProofOps(); + message.ops = object.ops?.map((e) => ProofOp.fromPartial(e)) || []; return message; }, }; @@ -463,15 +398,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -480,7 +418,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/tendermint/types/types.ts b/src/codec/tendermint/types/types.ts index 8c17aa4e..a086c4e7 100644 --- a/src/codec/tendermint/types/types.ts +++ b/src/codec/tendermint/types/types.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; import { Proof } from "../../tendermint/crypto/proof"; import { Consensus } from "../../tendermint/version/types"; import { ValidatorSet } from "../../tendermint/types/validator"; @@ -223,7 +223,9 @@ export interface TxProof { proof?: Proof; } -const basePartSetHeader: object = { total: 0 }; +function createBasePartSetHeader(): PartSetHeader { + return { total: 0, hash: new Uint8Array() }; +} export const PartSetHeader = { encode(message: PartSetHeader, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -239,8 +241,7 @@ export const PartSetHeader = { decode(input: _m0.Reader | Uint8Array, length?: number): PartSetHeader { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...basePartSetHeader } as PartSetHeader; - message.hash = new Uint8Array(); + const message = createBasePartSetHeader(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -259,36 +260,31 @@ export const PartSetHeader = { }, fromJSON(object: any): PartSetHeader { - const message = { ...basePartSetHeader } as PartSetHeader; - message.hash = new Uint8Array(); - if (object.total !== undefined && object.total !== null) { - message.total = Number(object.total); - } else { - message.total = 0; - } - if (object.hash !== undefined && object.hash !== null) { - message.hash = bytesFromBase64(object.hash); - } - return message; + return { + total: isSet(object.total) ? Number(object.total) : 0, + hash: isSet(object.hash) ? bytesFromBase64(object.hash) : new Uint8Array(), + }; }, toJSON(message: PartSetHeader): unknown { const obj: any = {}; - message.total !== undefined && (obj.total = message.total); + message.total !== undefined && (obj.total = Math.round(message.total)); message.hash !== undefined && (obj.hash = base64FromBytes(message.hash !== undefined ? message.hash : new Uint8Array())); return obj; }, - fromPartial(object: DeepPartial): PartSetHeader { - const message = { ...basePartSetHeader } as PartSetHeader; + fromPartial, I>>(object: I): PartSetHeader { + const message = createBasePartSetHeader(); message.total = object.total ?? 0; message.hash = object.hash ?? new Uint8Array(); return message; }, }; -const basePart: object = { index: 0 }; +function createBasePart(): Part { + return { index: 0, bytes: new Uint8Array(), proof: undefined }; +} export const Part = { encode(message: Part, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -307,8 +303,7 @@ export const Part = { decode(input: _m0.Reader | Uint8Array, length?: number): Part { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...basePart } as Part; - message.bytes = new Uint8Array(); + const message = createBasePart(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -330,47 +325,35 @@ export const Part = { }, fromJSON(object: any): Part { - const message = { ...basePart } as Part; - message.bytes = new Uint8Array(); - if (object.index !== undefined && object.index !== null) { - message.index = Number(object.index); - } else { - message.index = 0; - } - if (object.bytes !== undefined && object.bytes !== null) { - message.bytes = bytesFromBase64(object.bytes); - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = Proof.fromJSON(object.proof); - } else { - message.proof = undefined; - } - return message; + return { + index: isSet(object.index) ? Number(object.index) : 0, + bytes: isSet(object.bytes) ? bytesFromBase64(object.bytes) : new Uint8Array(), + proof: isSet(object.proof) ? Proof.fromJSON(object.proof) : undefined, + }; }, toJSON(message: Part): unknown { const obj: any = {}; - message.index !== undefined && (obj.index = message.index); + message.index !== undefined && (obj.index = Math.round(message.index)); message.bytes !== undefined && (obj.bytes = base64FromBytes(message.bytes !== undefined ? message.bytes : new Uint8Array())); message.proof !== undefined && (obj.proof = message.proof ? Proof.toJSON(message.proof) : undefined); return obj; }, - fromPartial(object: DeepPartial): Part { - const message = { ...basePart } as Part; + fromPartial, I>>(object: I): Part { + const message = createBasePart(); message.index = object.index ?? 0; message.bytes = object.bytes ?? new Uint8Array(); - if (object.proof !== undefined && object.proof !== null) { - message.proof = Proof.fromPartial(object.proof); - } else { - message.proof = undefined; - } + message.proof = + object.proof !== undefined && object.proof !== null ? Proof.fromPartial(object.proof) : undefined; return message; }, }; -const baseBlockID: object = {}; +function createBaseBlockID(): BlockID { + return { hash: new Uint8Array(), partSetHeader: undefined }; +} export const BlockID = { encode(message: BlockID, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -386,8 +369,7 @@ export const BlockID = { decode(input: _m0.Reader | Uint8Array, length?: number): BlockID { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseBlockID } as BlockID; - message.hash = new Uint8Array(); + const message = createBaseBlockID(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -406,17 +388,10 @@ export const BlockID = { }, fromJSON(object: any): BlockID { - const message = { ...baseBlockID } as BlockID; - message.hash = new Uint8Array(); - if (object.hash !== undefined && object.hash !== null) { - message.hash = bytesFromBase64(object.hash); - } - if (object.partSetHeader !== undefined && object.partSetHeader !== null) { - message.partSetHeader = PartSetHeader.fromJSON(object.partSetHeader); - } else { - message.partSetHeader = undefined; - } - return message; + return { + hash: isSet(object.hash) ? bytesFromBase64(object.hash) : new Uint8Array(), + partSetHeader: isSet(object.partSetHeader) ? PartSetHeader.fromJSON(object.partSetHeader) : undefined, + }; }, toJSON(message: BlockID): unknown { @@ -428,19 +403,35 @@ export const BlockID = { return obj; }, - fromPartial(object: DeepPartial): BlockID { - const message = { ...baseBlockID } as BlockID; + fromPartial, I>>(object: I): BlockID { + const message = createBaseBlockID(); message.hash = object.hash ?? new Uint8Array(); - if (object.partSetHeader !== undefined && object.partSetHeader !== null) { - message.partSetHeader = PartSetHeader.fromPartial(object.partSetHeader); - } else { - message.partSetHeader = undefined; - } + message.partSetHeader = + object.partSetHeader !== undefined && object.partSetHeader !== null + ? PartSetHeader.fromPartial(object.partSetHeader) + : undefined; return message; }, }; -const baseHeader: object = { chainId: "", height: Long.ZERO }; +function createBaseHeader(): Header { + return { + version: undefined, + chainId: "", + height: Long.ZERO, + time: undefined, + lastBlockId: undefined, + lastCommitHash: new Uint8Array(), + dataHash: new Uint8Array(), + validatorsHash: new Uint8Array(), + nextValidatorsHash: new Uint8Array(), + consensusHash: new Uint8Array(), + appHash: new Uint8Array(), + lastResultsHash: new Uint8Array(), + evidenceHash: new Uint8Array(), + proposerAddress: new Uint8Array(), + }; +} export const Header = { encode(message: Header, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -492,16 +483,7 @@ export const Header = { decode(input: _m0.Reader | Uint8Array, length?: number): Header { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseHeader } as Header; - message.lastCommitHash = new Uint8Array(); - message.dataHash = new Uint8Array(); - message.validatorsHash = new Uint8Array(); - message.nextValidatorsHash = new Uint8Array(); - message.consensusHash = new Uint8Array(); - message.appHash = new Uint8Array(); - message.lastResultsHash = new Uint8Array(); - message.evidenceHash = new Uint8Array(); - message.proposerAddress = new Uint8Array(); + const message = createBaseHeader(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -556,69 +538,32 @@ export const Header = { }, fromJSON(object: any): Header { - const message = { ...baseHeader } as Header; - message.lastCommitHash = new Uint8Array(); - message.dataHash = new Uint8Array(); - message.validatorsHash = new Uint8Array(); - message.nextValidatorsHash = new Uint8Array(); - message.consensusHash = new Uint8Array(); - message.appHash = new Uint8Array(); - message.lastResultsHash = new Uint8Array(); - message.evidenceHash = new Uint8Array(); - message.proposerAddress = new Uint8Array(); - if (object.version !== undefined && object.version !== null) { - message.version = Consensus.fromJSON(object.version); - } else { - message.version = undefined; - } - if (object.chainId !== undefined && object.chainId !== null) { - message.chainId = String(object.chainId); - } else { - message.chainId = ""; - } - if (object.height !== undefined && object.height !== null) { - message.height = Long.fromString(object.height); - } else { - message.height = Long.ZERO; - } - if (object.time !== undefined && object.time !== null) { - message.time = fromJsonTimestamp(object.time); - } else { - message.time = undefined; - } - if (object.lastBlockId !== undefined && object.lastBlockId !== null) { - message.lastBlockId = BlockID.fromJSON(object.lastBlockId); - } else { - message.lastBlockId = undefined; - } - if (object.lastCommitHash !== undefined && object.lastCommitHash !== null) { - message.lastCommitHash = bytesFromBase64(object.lastCommitHash); - } - if (object.dataHash !== undefined && object.dataHash !== null) { - message.dataHash = bytesFromBase64(object.dataHash); - } - if (object.validatorsHash !== undefined && object.validatorsHash !== null) { - message.validatorsHash = bytesFromBase64(object.validatorsHash); - } - if (object.nextValidatorsHash !== undefined && object.nextValidatorsHash !== null) { - message.nextValidatorsHash = bytesFromBase64(object.nextValidatorsHash); - } - if (object.consensusHash !== undefined && object.consensusHash !== null) { - message.consensusHash = bytesFromBase64(object.consensusHash); - } - if (object.appHash !== undefined && object.appHash !== null) { - message.appHash = bytesFromBase64(object.appHash); - } - if (object.lastResultsHash !== undefined && object.lastResultsHash !== null) { - message.lastResultsHash = bytesFromBase64(object.lastResultsHash); - } - if (object.evidenceHash !== undefined && object.evidenceHash !== null) { - message.evidenceHash = bytesFromBase64(object.evidenceHash); - } - if (object.proposerAddress !== undefined && object.proposerAddress !== null) { - message.proposerAddress = bytesFromBase64(object.proposerAddress); - } - return message; + return { + version: isSet(object.version) ? Consensus.fromJSON(object.version) : undefined, + chainId: isSet(object.chainId) ? String(object.chainId) : "", + height: isSet(object.height) ? Long.fromString(object.height) : Long.ZERO, + time: isSet(object.time) ? fromJsonTimestamp(object.time) : undefined, + lastBlockId: isSet(object.lastBlockId) ? BlockID.fromJSON(object.lastBlockId) : undefined, + lastCommitHash: isSet(object.lastCommitHash) + ? bytesFromBase64(object.lastCommitHash) + : new Uint8Array(), + dataHash: isSet(object.dataHash) ? bytesFromBase64(object.dataHash) : new Uint8Array(), + validatorsHash: isSet(object.validatorsHash) + ? bytesFromBase64(object.validatorsHash) + : new Uint8Array(), + nextValidatorsHash: isSet(object.nextValidatorsHash) + ? bytesFromBase64(object.nextValidatorsHash) + : new Uint8Array(), + consensusHash: isSet(object.consensusHash) ? bytesFromBase64(object.consensusHash) : new Uint8Array(), + appHash: isSet(object.appHash) ? bytesFromBase64(object.appHash) : new Uint8Array(), + lastResultsHash: isSet(object.lastResultsHash) + ? bytesFromBase64(object.lastResultsHash) + : new Uint8Array(), + evidenceHash: isSet(object.evidenceHash) ? bytesFromBase64(object.evidenceHash) : new Uint8Array(), + proposerAddress: isSet(object.proposerAddress) + ? bytesFromBase64(object.proposerAddress) + : new Uint8Array(), + }; }, toJSON(message: Header): unknown { @@ -665,25 +610,20 @@ export const Header = { return obj; }, - fromPartial(object: DeepPartial
): Header { - const message = { ...baseHeader } as Header; - if (object.version !== undefined && object.version !== null) { - message.version = Consensus.fromPartial(object.version); - } else { - message.version = undefined; - } + fromPartial, I>>(object: I): Header { + const message = createBaseHeader(); + message.version = + object.version !== undefined && object.version !== null + ? Consensus.fromPartial(object.version) + : undefined; message.chainId = object.chainId ?? ""; - if (object.height !== undefined && object.height !== null) { - message.height = object.height as Long; - } else { - message.height = Long.ZERO; - } + message.height = + object.height !== undefined && object.height !== null ? Long.fromValue(object.height) : Long.ZERO; message.time = object.time ?? undefined; - if (object.lastBlockId !== undefined && object.lastBlockId !== null) { - message.lastBlockId = BlockID.fromPartial(object.lastBlockId); - } else { - message.lastBlockId = undefined; - } + message.lastBlockId = + object.lastBlockId !== undefined && object.lastBlockId !== null + ? BlockID.fromPartial(object.lastBlockId) + : undefined; message.lastCommitHash = object.lastCommitHash ?? new Uint8Array(); message.dataHash = object.dataHash ?? new Uint8Array(); message.validatorsHash = object.validatorsHash ?? new Uint8Array(); @@ -697,7 +637,9 @@ export const Header = { }, }; -const baseData: object = {}; +function createBaseData(): Data { + return { txs: [] }; +} export const Data = { encode(message: Data, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -710,8 +652,7 @@ export const Data = { decode(input: _m0.Reader | Uint8Array, length?: number): Data { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseData } as Data; - message.txs = []; + const message = createBaseData(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -727,14 +668,9 @@ export const Data = { }, fromJSON(object: any): Data { - const message = { ...baseData } as Data; - message.txs = []; - if (object.txs !== undefined && object.txs !== null) { - for (const e of object.txs) { - message.txs.push(bytesFromBase64(e)); - } - } - return message; + return { + txs: Array.isArray(object?.txs) ? object.txs.map((e: any) => bytesFromBase64(e)) : [], + }; }, toJSON(message: Data): unknown { @@ -747,19 +683,25 @@ export const Data = { return obj; }, - fromPartial(object: DeepPartial): Data { - const message = { ...baseData } as Data; - message.txs = []; - if (object.txs !== undefined && object.txs !== null) { - for (const e of object.txs) { - message.txs.push(e); - } - } + fromPartial, I>>(object: I): Data { + const message = createBaseData(); + message.txs = object.txs?.map((e) => e) || []; return message; }, }; -const baseVote: object = { type: 0, height: Long.ZERO, round: 0, validatorIndex: 0 }; +function createBaseVote(): Vote { + return { + type: 0, + height: Long.ZERO, + round: 0, + blockId: undefined, + timestamp: undefined, + validatorAddress: new Uint8Array(), + validatorIndex: 0, + signature: new Uint8Array(), + }; +} export const Vote = { encode(message: Vote, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -793,9 +735,7 @@ export const Vote = { decode(input: _m0.Reader | Uint8Array, length?: number): Vote { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseVote } as Vote; - message.validatorAddress = new Uint8Array(); - message.signature = new Uint8Array(); + const message = createBaseVote(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -832,53 +772,25 @@ export const Vote = { }, fromJSON(object: any): Vote { - const message = { ...baseVote } as Vote; - message.validatorAddress = new Uint8Array(); - message.signature = new Uint8Array(); - if (object.type !== undefined && object.type !== null) { - message.type = signedMsgTypeFromJSON(object.type); - } else { - message.type = 0; - } - if (object.height !== undefined && object.height !== null) { - message.height = Long.fromString(object.height); - } else { - message.height = Long.ZERO; - } - if (object.round !== undefined && object.round !== null) { - message.round = Number(object.round); - } else { - message.round = 0; - } - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromJSON(object.blockId); - } else { - message.blockId = undefined; - } - if (object.timestamp !== undefined && object.timestamp !== null) { - message.timestamp = fromJsonTimestamp(object.timestamp); - } else { - message.timestamp = undefined; - } - if (object.validatorAddress !== undefined && object.validatorAddress !== null) { - message.validatorAddress = bytesFromBase64(object.validatorAddress); - } - if (object.validatorIndex !== undefined && object.validatorIndex !== null) { - message.validatorIndex = Number(object.validatorIndex); - } else { - message.validatorIndex = 0; - } - if (object.signature !== undefined && object.signature !== null) { - message.signature = bytesFromBase64(object.signature); - } - return message; + return { + type: isSet(object.type) ? signedMsgTypeFromJSON(object.type) : 0, + height: isSet(object.height) ? Long.fromString(object.height) : Long.ZERO, + round: isSet(object.round) ? Number(object.round) : 0, + blockId: isSet(object.blockId) ? BlockID.fromJSON(object.blockId) : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + validatorAddress: isSet(object.validatorAddress) + ? bytesFromBase64(object.validatorAddress) + : new Uint8Array(), + validatorIndex: isSet(object.validatorIndex) ? Number(object.validatorIndex) : 0, + signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(), + }; }, toJSON(message: Vote): unknown { const obj: any = {}; message.type !== undefined && (obj.type = signedMsgTypeToJSON(message.type)); message.height !== undefined && (obj.height = (message.height || Long.ZERO).toString()); - message.round !== undefined && (obj.round = message.round); + message.round !== undefined && (obj.round = Math.round(message.round)); message.blockId !== undefined && (obj.blockId = message.blockId ? BlockID.toJSON(message.blockId) : undefined); message.timestamp !== undefined && (obj.timestamp = message.timestamp.toISOString()); @@ -886,7 +798,7 @@ export const Vote = { (obj.validatorAddress = base64FromBytes( message.validatorAddress !== undefined ? message.validatorAddress : new Uint8Array(), )); - message.validatorIndex !== undefined && (obj.validatorIndex = message.validatorIndex); + message.validatorIndex !== undefined && (obj.validatorIndex = Math.round(message.validatorIndex)); message.signature !== undefined && (obj.signature = base64FromBytes( message.signature !== undefined ? message.signature : new Uint8Array(), @@ -894,20 +806,16 @@ export const Vote = { return obj; }, - fromPartial(object: DeepPartial): Vote { - const message = { ...baseVote } as Vote; + fromPartial, I>>(object: I): Vote { + const message = createBaseVote(); message.type = object.type ?? 0; - if (object.height !== undefined && object.height !== null) { - message.height = object.height as Long; - } else { - message.height = Long.ZERO; - } + message.height = + object.height !== undefined && object.height !== null ? Long.fromValue(object.height) : Long.ZERO; message.round = object.round ?? 0; - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromPartial(object.blockId); - } else { - message.blockId = undefined; - } + message.blockId = + object.blockId !== undefined && object.blockId !== null + ? BlockID.fromPartial(object.blockId) + : undefined; message.timestamp = object.timestamp ?? undefined; message.validatorAddress = object.validatorAddress ?? new Uint8Array(); message.validatorIndex = object.validatorIndex ?? 0; @@ -916,7 +824,9 @@ export const Vote = { }, }; -const baseCommit: object = { height: Long.ZERO, round: 0 }; +function createBaseCommit(): Commit { + return { height: Long.ZERO, round: 0, blockId: undefined, signatures: [] }; +} export const Commit = { encode(message: Commit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -938,8 +848,7 @@ export const Commit = { decode(input: _m0.Reader | Uint8Array, length?: number): Commit { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCommit } as Commit; - message.signatures = []; + const message = createBaseCommit(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -964,35 +873,20 @@ export const Commit = { }, fromJSON(object: any): Commit { - const message = { ...baseCommit } as Commit; - message.signatures = []; - if (object.height !== undefined && object.height !== null) { - message.height = Long.fromString(object.height); - } else { - message.height = Long.ZERO; - } - if (object.round !== undefined && object.round !== null) { - message.round = Number(object.round); - } else { - message.round = 0; - } - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromJSON(object.blockId); - } else { - message.blockId = undefined; - } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(CommitSig.fromJSON(e)); - } - } - return message; + return { + height: isSet(object.height) ? Long.fromString(object.height) : Long.ZERO, + round: isSet(object.round) ? Number(object.round) : 0, + blockId: isSet(object.blockId) ? BlockID.fromJSON(object.blockId) : undefined, + signatures: Array.isArray(object?.signatures) + ? object.signatures.map((e: any) => CommitSig.fromJSON(e)) + : [], + }; }, toJSON(message: Commit): unknown { const obj: any = {}; message.height !== undefined && (obj.height = (message.height || Long.ZERO).toString()); - message.round !== undefined && (obj.round = message.round); + message.round !== undefined && (obj.round = Math.round(message.round)); message.blockId !== undefined && (obj.blockId = message.blockId ? BlockID.toJSON(message.blockId) : undefined); if (message.signatures) { @@ -1003,30 +897,28 @@ export const Commit = { return obj; }, - fromPartial(object: DeepPartial): Commit { - const message = { ...baseCommit } as Commit; - if (object.height !== undefined && object.height !== null) { - message.height = object.height as Long; - } else { - message.height = Long.ZERO; - } + fromPartial, I>>(object: I): Commit { + const message = createBaseCommit(); + message.height = + object.height !== undefined && object.height !== null ? Long.fromValue(object.height) : Long.ZERO; message.round = object.round ?? 0; - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromPartial(object.blockId); - } else { - message.blockId = undefined; - } - message.signatures = []; - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(CommitSig.fromPartial(e)); - } - } + message.blockId = + object.blockId !== undefined && object.blockId !== null + ? BlockID.fromPartial(object.blockId) + : undefined; + message.signatures = object.signatures?.map((e) => CommitSig.fromPartial(e)) || []; return message; }, }; -const baseCommitSig: object = { blockIdFlag: 0 }; +function createBaseCommitSig(): CommitSig { + return { + blockIdFlag: 0, + validatorAddress: new Uint8Array(), + timestamp: undefined, + signature: new Uint8Array(), + }; +} export const CommitSig = { encode(message: CommitSig, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1048,9 +940,7 @@ export const CommitSig = { decode(input: _m0.Reader | Uint8Array, length?: number): CommitSig { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCommitSig } as CommitSig; - message.validatorAddress = new Uint8Array(); - message.signature = new Uint8Array(); + const message = createBaseCommitSig(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1075,26 +965,14 @@ export const CommitSig = { }, fromJSON(object: any): CommitSig { - const message = { ...baseCommitSig } as CommitSig; - message.validatorAddress = new Uint8Array(); - message.signature = new Uint8Array(); - if (object.blockIdFlag !== undefined && object.blockIdFlag !== null) { - message.blockIdFlag = blockIDFlagFromJSON(object.blockIdFlag); - } else { - message.blockIdFlag = 0; - } - if (object.validatorAddress !== undefined && object.validatorAddress !== null) { - message.validatorAddress = bytesFromBase64(object.validatorAddress); - } - if (object.timestamp !== undefined && object.timestamp !== null) { - message.timestamp = fromJsonTimestamp(object.timestamp); - } else { - message.timestamp = undefined; - } - if (object.signature !== undefined && object.signature !== null) { - message.signature = bytesFromBase64(object.signature); - } - return message; + return { + blockIdFlag: isSet(object.blockIdFlag) ? blockIDFlagFromJSON(object.blockIdFlag) : 0, + validatorAddress: isSet(object.validatorAddress) + ? bytesFromBase64(object.validatorAddress) + : new Uint8Array(), + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(), + }; }, toJSON(message: CommitSig): unknown { @@ -1112,8 +990,8 @@ export const CommitSig = { return obj; }, - fromPartial(object: DeepPartial): CommitSig { - const message = { ...baseCommitSig } as CommitSig; + fromPartial, I>>(object: I): CommitSig { + const message = createBaseCommitSig(); message.blockIdFlag = object.blockIdFlag ?? 0; message.validatorAddress = object.validatorAddress ?? new Uint8Array(); message.timestamp = object.timestamp ?? undefined; @@ -1122,7 +1000,17 @@ export const CommitSig = { }, }; -const baseProposal: object = { type: 0, height: Long.ZERO, round: 0, polRound: 0 }; +function createBaseProposal(): Proposal { + return { + type: 0, + height: Long.ZERO, + round: 0, + polRound: 0, + blockId: undefined, + timestamp: undefined, + signature: new Uint8Array(), + }; +} export const Proposal = { encode(message: Proposal, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1153,8 +1041,7 @@ export const Proposal = { decode(input: _m0.Reader | Uint8Array, length?: number): Proposal { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseProposal } as Proposal; - message.signature = new Uint8Array(); + const message = createBaseProposal(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1188,50 +1075,23 @@ export const Proposal = { }, fromJSON(object: any): Proposal { - const message = { ...baseProposal } as Proposal; - message.signature = new Uint8Array(); - if (object.type !== undefined && object.type !== null) { - message.type = signedMsgTypeFromJSON(object.type); - } else { - message.type = 0; - } - if (object.height !== undefined && object.height !== null) { - message.height = Long.fromString(object.height); - } else { - message.height = Long.ZERO; - } - if (object.round !== undefined && object.round !== null) { - message.round = Number(object.round); - } else { - message.round = 0; - } - if (object.polRound !== undefined && object.polRound !== null) { - message.polRound = Number(object.polRound); - } else { - message.polRound = 0; - } - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromJSON(object.blockId); - } else { - message.blockId = undefined; - } - if (object.timestamp !== undefined && object.timestamp !== null) { - message.timestamp = fromJsonTimestamp(object.timestamp); - } else { - message.timestamp = undefined; - } - if (object.signature !== undefined && object.signature !== null) { - message.signature = bytesFromBase64(object.signature); - } - return message; + return { + type: isSet(object.type) ? signedMsgTypeFromJSON(object.type) : 0, + height: isSet(object.height) ? Long.fromString(object.height) : Long.ZERO, + round: isSet(object.round) ? Number(object.round) : 0, + polRound: isSet(object.polRound) ? Number(object.polRound) : 0, + blockId: isSet(object.blockId) ? BlockID.fromJSON(object.blockId) : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(), + }; }, toJSON(message: Proposal): unknown { const obj: any = {}; message.type !== undefined && (obj.type = signedMsgTypeToJSON(message.type)); message.height !== undefined && (obj.height = (message.height || Long.ZERO).toString()); - message.round !== undefined && (obj.round = message.round); - message.polRound !== undefined && (obj.polRound = message.polRound); + message.round !== undefined && (obj.round = Math.round(message.round)); + message.polRound !== undefined && (obj.polRound = Math.round(message.polRound)); message.blockId !== undefined && (obj.blockId = message.blockId ? BlockID.toJSON(message.blockId) : undefined); message.timestamp !== undefined && (obj.timestamp = message.timestamp.toISOString()); @@ -1242,28 +1102,26 @@ export const Proposal = { return obj; }, - fromPartial(object: DeepPartial): Proposal { - const message = { ...baseProposal } as Proposal; + fromPartial, I>>(object: I): Proposal { + const message = createBaseProposal(); message.type = object.type ?? 0; - if (object.height !== undefined && object.height !== null) { - message.height = object.height as Long; - } else { - message.height = Long.ZERO; - } + message.height = + object.height !== undefined && object.height !== null ? Long.fromValue(object.height) : Long.ZERO; message.round = object.round ?? 0; message.polRound = object.polRound ?? 0; - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromPartial(object.blockId); - } else { - message.blockId = undefined; - } + message.blockId = + object.blockId !== undefined && object.blockId !== null + ? BlockID.fromPartial(object.blockId) + : undefined; message.timestamp = object.timestamp ?? undefined; message.signature = object.signature ?? new Uint8Array(); return message; }, }; -const baseSignedHeader: object = {}; +function createBaseSignedHeader(): SignedHeader { + return { header: undefined, commit: undefined }; +} export const SignedHeader = { encode(message: SignedHeader, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1279,7 +1137,7 @@ export const SignedHeader = { decode(input: _m0.Reader | Uint8Array, length?: number): SignedHeader { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSignedHeader } as SignedHeader; + const message = createBaseSignedHeader(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1298,18 +1156,10 @@ export const SignedHeader = { }, fromJSON(object: any): SignedHeader { - const message = { ...baseSignedHeader } as SignedHeader; - if (object.header !== undefined && object.header !== null) { - message.header = Header.fromJSON(object.header); - } else { - message.header = undefined; - } - if (object.commit !== undefined && object.commit !== null) { - message.commit = Commit.fromJSON(object.commit); - } else { - message.commit = undefined; - } - return message; + return { + header: isSet(object.header) ? Header.fromJSON(object.header) : undefined, + commit: isSet(object.commit) ? Commit.fromJSON(object.commit) : undefined, + }; }, toJSON(message: SignedHeader): unknown { @@ -1319,23 +1169,19 @@ export const SignedHeader = { return obj; }, - fromPartial(object: DeepPartial): SignedHeader { - const message = { ...baseSignedHeader } as SignedHeader; - if (object.header !== undefined && object.header !== null) { - message.header = Header.fromPartial(object.header); - } else { - message.header = undefined; - } - if (object.commit !== undefined && object.commit !== null) { - message.commit = Commit.fromPartial(object.commit); - } else { - message.commit = undefined; - } + fromPartial, I>>(object: I): SignedHeader { + const message = createBaseSignedHeader(); + message.header = + object.header !== undefined && object.header !== null ? Header.fromPartial(object.header) : undefined; + message.commit = + object.commit !== undefined && object.commit !== null ? Commit.fromPartial(object.commit) : undefined; return message; }, }; -const baseLightBlock: object = {}; +function createBaseLightBlock(): LightBlock { + return { signedHeader: undefined, validatorSet: undefined }; +} export const LightBlock = { encode(message: LightBlock, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1351,7 +1197,7 @@ export const LightBlock = { decode(input: _m0.Reader | Uint8Array, length?: number): LightBlock { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseLightBlock } as LightBlock; + const message = createBaseLightBlock(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1370,18 +1216,10 @@ export const LightBlock = { }, fromJSON(object: any): LightBlock { - const message = { ...baseLightBlock } as LightBlock; - if (object.signedHeader !== undefined && object.signedHeader !== null) { - message.signedHeader = SignedHeader.fromJSON(object.signedHeader); - } else { - message.signedHeader = undefined; - } - if (object.validatorSet !== undefined && object.validatorSet !== null) { - message.validatorSet = ValidatorSet.fromJSON(object.validatorSet); - } else { - message.validatorSet = undefined; - } - return message; + return { + signedHeader: isSet(object.signedHeader) ? SignedHeader.fromJSON(object.signedHeader) : undefined, + validatorSet: isSet(object.validatorSet) ? ValidatorSet.fromJSON(object.validatorSet) : undefined, + }; }, toJSON(message: LightBlock): unknown { @@ -1393,23 +1231,23 @@ export const LightBlock = { return obj; }, - fromPartial(object: DeepPartial): LightBlock { - const message = { ...baseLightBlock } as LightBlock; - if (object.signedHeader !== undefined && object.signedHeader !== null) { - message.signedHeader = SignedHeader.fromPartial(object.signedHeader); - } else { - message.signedHeader = undefined; - } - if (object.validatorSet !== undefined && object.validatorSet !== null) { - message.validatorSet = ValidatorSet.fromPartial(object.validatorSet); - } else { - message.validatorSet = undefined; - } + fromPartial, I>>(object: I): LightBlock { + const message = createBaseLightBlock(); + message.signedHeader = + object.signedHeader !== undefined && object.signedHeader !== null + ? SignedHeader.fromPartial(object.signedHeader) + : undefined; + message.validatorSet = + object.validatorSet !== undefined && object.validatorSet !== null + ? ValidatorSet.fromPartial(object.validatorSet) + : undefined; return message; }, }; -const baseBlockMeta: object = { blockSize: Long.ZERO, numTxs: Long.ZERO }; +function createBaseBlockMeta(): BlockMeta { + return { blockId: undefined, blockSize: Long.ZERO, header: undefined, numTxs: Long.ZERO }; +} export const BlockMeta = { encode(message: BlockMeta, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1431,7 +1269,7 @@ export const BlockMeta = { decode(input: _m0.Reader | Uint8Array, length?: number): BlockMeta { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseBlockMeta } as BlockMeta; + const message = createBaseBlockMeta(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1456,28 +1294,12 @@ export const BlockMeta = { }, fromJSON(object: any): BlockMeta { - const message = { ...baseBlockMeta } as BlockMeta; - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromJSON(object.blockId); - } else { - message.blockId = undefined; - } - if (object.blockSize !== undefined && object.blockSize !== null) { - message.blockSize = Long.fromString(object.blockSize); - } else { - message.blockSize = Long.ZERO; - } - if (object.header !== undefined && object.header !== null) { - message.header = Header.fromJSON(object.header); - } else { - message.header = undefined; - } - if (object.numTxs !== undefined && object.numTxs !== null) { - message.numTxs = Long.fromString(object.numTxs); - } else { - message.numTxs = Long.ZERO; - } - return message; + return { + blockId: isSet(object.blockId) ? BlockID.fromJSON(object.blockId) : undefined, + blockSize: isSet(object.blockSize) ? Long.fromString(object.blockSize) : Long.ZERO, + header: isSet(object.header) ? Header.fromJSON(object.header) : undefined, + numTxs: isSet(object.numTxs) ? Long.fromString(object.numTxs) : Long.ZERO, + }; }, toJSON(message: BlockMeta): unknown { @@ -1490,33 +1312,27 @@ export const BlockMeta = { return obj; }, - fromPartial(object: DeepPartial): BlockMeta { - const message = { ...baseBlockMeta } as BlockMeta; - if (object.blockId !== undefined && object.blockId !== null) { - message.blockId = BlockID.fromPartial(object.blockId); - } else { - message.blockId = undefined; - } - if (object.blockSize !== undefined && object.blockSize !== null) { - message.blockSize = object.blockSize as Long; - } else { - message.blockSize = Long.ZERO; - } - if (object.header !== undefined && object.header !== null) { - message.header = Header.fromPartial(object.header); - } else { - message.header = undefined; - } - if (object.numTxs !== undefined && object.numTxs !== null) { - message.numTxs = object.numTxs as Long; - } else { - message.numTxs = Long.ZERO; - } + fromPartial, I>>(object: I): BlockMeta { + const message = createBaseBlockMeta(); + message.blockId = + object.blockId !== undefined && object.blockId !== null + ? BlockID.fromPartial(object.blockId) + : undefined; + message.blockSize = + object.blockSize !== undefined && object.blockSize !== null + ? Long.fromValue(object.blockSize) + : Long.ZERO; + message.header = + object.header !== undefined && object.header !== null ? Header.fromPartial(object.header) : undefined; + message.numTxs = + object.numTxs !== undefined && object.numTxs !== null ? Long.fromValue(object.numTxs) : Long.ZERO; return message; }, }; -const baseTxProof: object = {}; +function createBaseTxProof(): TxProof { + return { rootHash: new Uint8Array(), data: new Uint8Array(), proof: undefined }; +} export const TxProof = { encode(message: TxProof, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -1535,9 +1351,7 @@ export const TxProof = { decode(input: _m0.Reader | Uint8Array, length?: number): TxProof { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseTxProof } as TxProof; - message.rootHash = new Uint8Array(); - message.data = new Uint8Array(); + const message = createBaseTxProof(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -1559,21 +1373,11 @@ export const TxProof = { }, fromJSON(object: any): TxProof { - const message = { ...baseTxProof } as TxProof; - message.rootHash = new Uint8Array(); - message.data = new Uint8Array(); - if (object.rootHash !== undefined && object.rootHash !== null) { - message.rootHash = bytesFromBase64(object.rootHash); - } - if (object.data !== undefined && object.data !== null) { - message.data = bytesFromBase64(object.data); - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = Proof.fromJSON(object.proof); - } else { - message.proof = undefined; - } - return message; + return { + rootHash: isSet(object.rootHash) ? bytesFromBase64(object.rootHash) : new Uint8Array(), + data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(), + proof: isSet(object.proof) ? Proof.fromJSON(object.proof) : undefined, + }; }, toJSON(message: TxProof): unknown { @@ -1586,15 +1390,12 @@ export const TxProof = { return obj; }, - fromPartial(object: DeepPartial): TxProof { - const message = { ...baseTxProof } as TxProof; + fromPartial, I>>(object: I): TxProof { + const message = createBaseTxProof(); message.rootHash = object.rootHash ?? new Uint8Array(); message.data = object.data ?? new Uint8Array(); - if (object.proof !== undefined && object.proof !== null) { - message.proof = Proof.fromPartial(object.proof); - } else { - message.proof = undefined; - } + message.proof = + object.proof !== undefined && object.proof !== null ? Proof.fromPartial(object.proof) : undefined; return message; }, }; @@ -1625,15 +1426,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -1642,6 +1446,11 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + function toTimestamp(date: Date): Timestamp { const seconds = numberToLong(date.getTime() / 1_000); const nanos = (date.getTime() % 1_000) * 1_000_000; @@ -1672,3 +1481,7 @@ if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/tendermint/types/validator.ts b/src/codec/tendermint/types/validator.ts index adf316c9..25ad48e7 100644 --- a/src/codec/tendermint/types/validator.ts +++ b/src/codec/tendermint/types/validator.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; import { PublicKey } from "../../tendermint/crypto/keys"; export const protobufPackage = "tendermint.types"; @@ -23,7 +23,9 @@ export interface SimpleValidator { votingPower: Long; } -const baseValidatorSet: object = { totalVotingPower: Long.ZERO }; +function createBaseValidatorSet(): ValidatorSet { + return { validators: [], proposer: undefined, totalVotingPower: Long.ZERO }; +} export const ValidatorSet = { encode(message: ValidatorSet, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -42,8 +44,7 @@ export const ValidatorSet = { decode(input: _m0.Reader | Uint8Array, length?: number): ValidatorSet { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseValidatorSet } as ValidatorSet; - message.validators = []; + const message = createBaseValidatorSet(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -65,24 +66,13 @@ export const ValidatorSet = { }, fromJSON(object: any): ValidatorSet { - const message = { ...baseValidatorSet } as ValidatorSet; - message.validators = []; - if (object.validators !== undefined && object.validators !== null) { - for (const e of object.validators) { - message.validators.push(Validator.fromJSON(e)); - } - } - if (object.proposer !== undefined && object.proposer !== null) { - message.proposer = Validator.fromJSON(object.proposer); - } else { - message.proposer = undefined; - } - if (object.totalVotingPower !== undefined && object.totalVotingPower !== null) { - message.totalVotingPower = Long.fromString(object.totalVotingPower); - } else { - message.totalVotingPower = Long.ZERO; - } - return message; + return { + validators: Array.isArray(object?.validators) + ? object.validators.map((e: any) => Validator.fromJSON(e)) + : [], + proposer: isSet(object.proposer) ? Validator.fromJSON(object.proposer) : undefined, + totalVotingPower: isSet(object.totalVotingPower) ? Long.fromString(object.totalVotingPower) : Long.ZERO, + }; }, toJSON(message: ValidatorSet): unknown { @@ -99,29 +89,29 @@ export const ValidatorSet = { return obj; }, - fromPartial(object: DeepPartial): ValidatorSet { - const message = { ...baseValidatorSet } as ValidatorSet; - message.validators = []; - if (object.validators !== undefined && object.validators !== null) { - for (const e of object.validators) { - message.validators.push(Validator.fromPartial(e)); - } - } - if (object.proposer !== undefined && object.proposer !== null) { - message.proposer = Validator.fromPartial(object.proposer); - } else { - message.proposer = undefined; - } - if (object.totalVotingPower !== undefined && object.totalVotingPower !== null) { - message.totalVotingPower = object.totalVotingPower as Long; - } else { - message.totalVotingPower = Long.ZERO; - } + fromPartial, I>>(object: I): ValidatorSet { + const message = createBaseValidatorSet(); + message.validators = object.validators?.map((e) => Validator.fromPartial(e)) || []; + message.proposer = + object.proposer !== undefined && object.proposer !== null + ? Validator.fromPartial(object.proposer) + : undefined; + message.totalVotingPower = + object.totalVotingPower !== undefined && object.totalVotingPower !== null + ? Long.fromValue(object.totalVotingPower) + : Long.ZERO; return message; }, }; -const baseValidator: object = { votingPower: Long.ZERO, proposerPriority: Long.ZERO }; +function createBaseValidator(): Validator { + return { + address: new Uint8Array(), + pubKey: undefined, + votingPower: Long.ZERO, + proposerPriority: Long.ZERO, + }; +} export const Validator = { encode(message: Validator, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -143,8 +133,7 @@ export const Validator = { decode(input: _m0.Reader | Uint8Array, length?: number): Validator { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseValidator } as Validator; - message.address = new Uint8Array(); + const message = createBaseValidator(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -169,27 +158,12 @@ export const Validator = { }, fromJSON(object: any): Validator { - const message = { ...baseValidator } as Validator; - message.address = new Uint8Array(); - if (object.address !== undefined && object.address !== null) { - message.address = bytesFromBase64(object.address); - } - if (object.pubKey !== undefined && object.pubKey !== null) { - message.pubKey = PublicKey.fromJSON(object.pubKey); - } else { - message.pubKey = undefined; - } - if (object.votingPower !== undefined && object.votingPower !== null) { - message.votingPower = Long.fromString(object.votingPower); - } else { - message.votingPower = Long.ZERO; - } - if (object.proposerPriority !== undefined && object.proposerPriority !== null) { - message.proposerPriority = Long.fromString(object.proposerPriority); - } else { - message.proposerPriority = Long.ZERO; - } - return message; + return { + address: isSet(object.address) ? bytesFromBase64(object.address) : new Uint8Array(), + pubKey: isSet(object.pubKey) ? PublicKey.fromJSON(object.pubKey) : undefined, + votingPower: isSet(object.votingPower) ? Long.fromString(object.votingPower) : Long.ZERO, + proposerPriority: isSet(object.proposerPriority) ? Long.fromString(object.proposerPriority) : Long.ZERO, + }; }, toJSON(message: Validator): unknown { @@ -204,29 +178,28 @@ export const Validator = { return obj; }, - fromPartial(object: DeepPartial): Validator { - const message = { ...baseValidator } as Validator; + fromPartial, I>>(object: I): Validator { + const message = createBaseValidator(); message.address = object.address ?? new Uint8Array(); - if (object.pubKey !== undefined && object.pubKey !== null) { - message.pubKey = PublicKey.fromPartial(object.pubKey); - } else { - message.pubKey = undefined; - } - if (object.votingPower !== undefined && object.votingPower !== null) { - message.votingPower = object.votingPower as Long; - } else { - message.votingPower = Long.ZERO; - } - if (object.proposerPriority !== undefined && object.proposerPriority !== null) { - message.proposerPriority = object.proposerPriority as Long; - } else { - message.proposerPriority = Long.ZERO; - } + message.pubKey = + object.pubKey !== undefined && object.pubKey !== null + ? PublicKey.fromPartial(object.pubKey) + : undefined; + message.votingPower = + object.votingPower !== undefined && object.votingPower !== null + ? Long.fromValue(object.votingPower) + : Long.ZERO; + message.proposerPriority = + object.proposerPriority !== undefined && object.proposerPriority !== null + ? Long.fromValue(object.proposerPriority) + : Long.ZERO; return message; }, }; -const baseSimpleValidator: object = { votingPower: Long.ZERO }; +function createBaseSimpleValidator(): SimpleValidator { + return { pubKey: undefined, votingPower: Long.ZERO }; +} export const SimpleValidator = { encode(message: SimpleValidator, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -242,7 +215,7 @@ export const SimpleValidator = { decode(input: _m0.Reader | Uint8Array, length?: number): SimpleValidator { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSimpleValidator } as SimpleValidator; + const message = createBaseSimpleValidator(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -261,18 +234,10 @@ export const SimpleValidator = { }, fromJSON(object: any): SimpleValidator { - const message = { ...baseSimpleValidator } as SimpleValidator; - if (object.pubKey !== undefined && object.pubKey !== null) { - message.pubKey = PublicKey.fromJSON(object.pubKey); - } else { - message.pubKey = undefined; - } - if (object.votingPower !== undefined && object.votingPower !== null) { - message.votingPower = Long.fromString(object.votingPower); - } else { - message.votingPower = Long.ZERO; - } - return message; + return { + pubKey: isSet(object.pubKey) ? PublicKey.fromJSON(object.pubKey) : undefined, + votingPower: isSet(object.votingPower) ? Long.fromString(object.votingPower) : Long.ZERO, + }; }, toJSON(message: SimpleValidator): unknown { @@ -283,18 +248,16 @@ export const SimpleValidator = { return obj; }, - fromPartial(object: DeepPartial): SimpleValidator { - const message = { ...baseSimpleValidator } as SimpleValidator; - if (object.pubKey !== undefined && object.pubKey !== null) { - message.pubKey = PublicKey.fromPartial(object.pubKey); - } else { - message.pubKey = undefined; - } - if (object.votingPower !== undefined && object.votingPower !== null) { - message.votingPower = object.votingPower as Long; - } else { - message.votingPower = Long.ZERO; - } + fromPartial, I>>(object: I): SimpleValidator { + const message = createBaseSimpleValidator(); + message.pubKey = + object.pubKey !== undefined && object.pubKey !== null + ? PublicKey.fromPartial(object.pubKey) + : undefined; + message.votingPower = + object.votingPower !== undefined && object.votingPower !== null + ? Long.fromValue(object.votingPower) + : Long.ZERO; return message; }, }; @@ -325,15 +288,18 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join("")); } -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -342,7 +308,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/codec/tendermint/version/types.ts b/src/codec/tendermint/version/types.ts index 37f45e8b..5ed689cb 100644 --- a/src/codec/tendermint/version/types.ts +++ b/src/codec/tendermint/version/types.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import Long from "long"; -import _m0 from "protobufjs/minimal"; +import * as _m0 from "protobufjs/minimal"; export const protobufPackage = "tendermint.version"; @@ -24,7 +24,9 @@ export interface Consensus { app: Long; } -const baseApp: object = { protocol: Long.UZERO, software: "" }; +function createBaseApp(): App { + return { protocol: Long.UZERO, software: "" }; +} export const App = { encode(message: App, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -40,7 +42,7 @@ export const App = { decode(input: _m0.Reader | Uint8Array, length?: number): App { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseApp } as App; + const message = createBaseApp(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -59,18 +61,10 @@ export const App = { }, fromJSON(object: any): App { - const message = { ...baseApp } as App; - if (object.protocol !== undefined && object.protocol !== null) { - message.protocol = Long.fromString(object.protocol); - } else { - message.protocol = Long.UZERO; - } - if (object.software !== undefined && object.software !== null) { - message.software = String(object.software); - } else { - message.software = ""; - } - return message; + return { + protocol: isSet(object.protocol) ? Long.fromString(object.protocol) : Long.UZERO, + software: isSet(object.software) ? String(object.software) : "", + }; }, toJSON(message: App): unknown { @@ -80,19 +74,20 @@ export const App = { return obj; }, - fromPartial(object: DeepPartial): App { - const message = { ...baseApp } as App; - if (object.protocol !== undefined && object.protocol !== null) { - message.protocol = object.protocol as Long; - } else { - message.protocol = Long.UZERO; - } + fromPartial, I>>(object: I): App { + const message = createBaseApp(); + message.protocol = + object.protocol !== undefined && object.protocol !== null + ? Long.fromValue(object.protocol) + : Long.UZERO; message.software = object.software ?? ""; return message; }, }; -const baseConsensus: object = { block: Long.UZERO, app: Long.UZERO }; +function createBaseConsensus(): Consensus { + return { block: Long.UZERO, app: Long.UZERO }; +} export const Consensus = { encode(message: Consensus, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -108,7 +103,7 @@ export const Consensus = { decode(input: _m0.Reader | Uint8Array, length?: number): Consensus { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseConsensus } as Consensus; + const message = createBaseConsensus(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -127,18 +122,10 @@ export const Consensus = { }, fromJSON(object: any): Consensus { - const message = { ...baseConsensus } as Consensus; - if (object.block !== undefined && object.block !== null) { - message.block = Long.fromString(object.block); - } else { - message.block = Long.UZERO; - } - if (object.app !== undefined && object.app !== null) { - message.app = Long.fromString(object.app); - } else { - message.app = Long.UZERO; - } - return message; + return { + block: isSet(object.block) ? Long.fromString(object.block) : Long.UZERO, + app: isSet(object.app) ? Long.fromString(object.app) : Long.UZERO, + }; }, toJSON(message: Consensus): unknown { @@ -148,25 +135,21 @@ export const Consensus = { return obj; }, - fromPartial(object: DeepPartial): Consensus { - const message = { ...baseConsensus } as Consensus; - if (object.block !== undefined && object.block !== null) { - message.block = object.block as Long; - } else { - message.block = Long.UZERO; - } - if (object.app !== undefined && object.app !== null) { - message.app = object.app as Long; - } else { - message.app = Long.UZERO; - } + fromPartial, I>>(object: I): Consensus { + const message = createBaseConsensus(); + message.block = + object.block !== undefined && object.block !== null ? Long.fromValue(object.block) : Long.UZERO; + message.app = object.app !== undefined && object.app !== null ? Long.fromValue(object.app) : Long.UZERO; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + export type DeepPartial = T extends Builtin ? T + : T extends Long + ? string | number | Long : T extends Array ? Array> : T extends ReadonlyArray @@ -175,7 +158,16 @@ export type DeepPartial = T extends Builtin ? { [K in keyof T]?: DeepPartial } : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + if (_m0.util.Long !== Long) { _m0.util.Long = Long as any; _m0.configure(); } + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/utils/arbiterPool.ts b/src/utils/arbiterPool.ts new file mode 100644 index 00000000..9c4d6aca --- /dev/null +++ b/src/utils/arbiterPool.ts @@ -0,0 +1,433 @@ +import { CosmWasmClient, SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate"; +import { calculateFee, createProtobufRpcClient, QueryClient } from "@cosmjs/stargate"; +import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; +import { PoEContractType } from "codec/confio/poe/v1beta1/poe"; +import { QueryClientImpl } from "codec/confio/poe/v1beta1/query"; +import { NetworkConfig } from "config/network"; + +export interface VotingRules { + /// Length of voting period in days + readonly voting_period: number; + /// quorum requirement (0.0-1.0) + readonly quorum: string; + /// threshold requirement (0.5-1.0) + readonly threshold: string; + /// If true, and absolute threshold and quorum are met, we can end before voting period finished + readonly allow_end_early: boolean; +} + +export interface VoterDetail { + readonly addr: string; + readonly points: number; +} + +export interface VoterListResponse { + readonly voters: readonly VoterDetail[]; +} + +export type VoteOption = "yes" | "no" | "abstain"; + +export interface ApoolProposal { + readonly text?: Record; +} + +export type Expiration = { + readonly at_height: number; +} & { + readonly at_time: string; +} & { + readonly never: Record; +}; + +export type Cw3Status = "pending" | "open" | "rejected" | "passed" | "executed"; + +export interface Votes { + readonly yes: number; + readonly no: number; + readonly abstain: number; + readonly veto: number; +} + +export interface ProposalResponse { + readonly id: number; + readonly title: string; + readonly description: string; + readonly proposal: ApoolProposal; + readonly status: "pending" | "open" | "rejected" | "passed" | "executed"; + readonly expires: Expiration; + /// This is the threshold that is applied to this proposal. Both the rules of the voting contract, + /// as well as the total_points of the voting group may have changed since this time. That means + /// that the generic `Threshold{}` query does not provide valid information for existing proposals. + readonly rules: VotingRules; + readonly total_points: number; + /// This is a running tally of all votes cast on this proposal so far. + readonly votes: Votes; +} + +export interface ProposalListResponse { + readonly proposals: readonly ProposalResponse[]; +} + +export interface APoolProposeResponse { + readonly txHash: string; + readonly proposalId?: number; +} + +export interface VoteInfo { + readonly voter: string; + readonly vote: VoteOption; + readonly proposal_id: number; + readonly points: number; +} + +export interface VoteResponse { + readonly vote: VoteInfo | null; +} + +export interface VoteListResponse { + readonly votes: readonly VoteInfo[]; +} + +export type ComplaintState = { + readonly initiated?: { expiration: Expiration }; +} & { + readonly waiting?: { wait_over: Expiration }; +} & { readonly aborted?: Record } & { readonly accepted?: Record } & { + readonly processing?: { arbiters: string }; +} & { readonly closed?: { summary: string; ipfs_link: string } }; + +export interface Complaint { + readonly complaint_id: number; + readonly title: string; + readonly description: string; + readonly plaintiff: string; + readonly defendant: string; + readonly state: ComplaintState; +} + +export interface ListComplaintsResponse { + readonly complaints: readonly Complaint[]; +} + +export function getProposalTitle(proposal: ApoolProposal): string { + const proposalProp = Object.keys(proposal)[0]; + + switch (proposalProp) { + case "text": + return "Open Text Proposal"; + default: + return "Uknown proposal type"; + } +} + +export class ApContractQuerier { + arbiterPoolAddress?: string; + arbiterPoolVotingAddress?: string; + + constructor(readonly config: NetworkConfig, protected readonly client: CosmWasmClient) {} + + protected async initAddress(): Promise { + if (this.arbiterPoolAddress || this.arbiterPoolVotingAddress) return; + + const tendermintClient = await Tendermint34Client.connect(this.config.rpcUrl); + const queryClient = new QueryClient(tendermintClient); + const rpcClient = createProtobufRpcClient(queryClient); + const queryService = new QueryClientImpl(rpcClient); + + const { address: arbiterPoolAddress } = await queryService.ContractAddress({ + contractType: PoEContractType.ARBITER_POOL, + }); + const { address: arbiterPoolVotingAddress } = await queryService.ContractAddress({ + contractType: PoEContractType.ARBITER_POOL_VOTING, + }); + + this.arbiterPoolAddress = arbiterPoolAddress; + this.arbiterPoolVotingAddress = arbiterPoolVotingAddress; + } + + async getProposals(startAfter?: number): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const query = { list_proposals: { start_after: startAfter } }; + const { proposals }: ProposalListResponse = await this.client.queryContractSmart( + this.arbiterPoolVotingAddress, + query, + ); + return proposals; + } + + async getAllProposals(): Promise { + let proposals: readonly ProposalResponse[] = []; + let nextProposals: readonly ProposalResponse[] = []; + + do { + const lastProposalId = proposals[proposals.length - 1]?.id; + nextProposals = await this.getProposals(lastProposalId); + proposals = [...proposals, ...nextProposals]; + } while (nextProposals.length); + + return proposals; + } + + async getProposal(proposalId: number): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const query = { proposal: { proposal_id: proposalId } }; + const proposalResponse: ProposalResponse = await this.client.queryContractSmart( + this.arbiterPoolVotingAddress, + query, + ); + return proposalResponse; + } + + async getVotes(proposalId: number, startAfter?: string): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const query = { + list_votes: { + proposal_id: proposalId, + start_after: startAfter, + }, + }; + const { votes }: VoteListResponse = await this.client.queryContractSmart( + this.arbiterPoolVotingAddress, + query, + ); + return votes; + } + + async getAllVotes(proposalId: number): Promise { + let votes: readonly VoteInfo[] = []; + let nextVotes: readonly VoteInfo[] = []; + + do { + const lastVoterAddress = votes[votes.length - 1]?.voter; + nextVotes = await this.getVotes(proposalId, lastVoterAddress); + votes = [...votes, ...nextVotes]; + } while (nextVotes.length); + + return votes; + } + + async getVote(proposalId: number, voter: string): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const query = { vote: { proposal_id: proposalId, voter } }; + const voteResponse: VoteResponse = await this.client.queryContractSmart( + this.arbiterPoolVotingAddress, + query, + ); + return voteResponse; + } + + async getVoters(startAfter?: string): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const query = { list_voters: { start_after: startAfter } }; + const { voters }: VoterListResponse = await this.client.queryContractSmart( + this.arbiterPoolVotingAddress, + query, + ); + return voters; + } + + async getAllVoters(): Promise { + let voters: readonly VoterDetail[] = []; + let nextVoters: readonly VoterDetail[] = []; + + do { + const lastVoterAddress = voters[voters.length - 1]?.addr; + nextVoters = await this.getVoters(lastVoterAddress); + voters = [...voters, ...nextVoters]; + } while (nextVoters.length); + + return voters; + } + + async getComplaints(startAfter?: number): Promise { + await this.initAddress(); + if (!this.arbiterPoolAddress) throw new Error("arbiterPoolAddress was not set"); + + const query = { list_complaints: { start_after: startAfter } }; + const { complaints }: ListComplaintsResponse = await this.client.queryContractSmart( + this.arbiterPoolAddress, + query, + ); + + const complaintsWithId: readonly Complaint[] = complaints.map((complaint, index) => ({ + ...complaint, + complaint_id: index, + })); + return complaintsWithId; + } + + async getAllComplaints(): Promise { + let complaints: readonly Complaint[] = []; + let nextComplaints: readonly Complaint[] = []; + + do { + const lastComplaintId = complaints.length ? complaints.length - 1 : undefined; + nextComplaints = await this.getComplaints(lastComplaintId); + complaints = [...complaints, ...nextComplaints]; + } while (nextComplaints.length); + + return complaints; + } + + async getComplaint(complaintId: number): Promise { + await this.initAddress(); + if (!this.arbiterPoolAddress) throw new Error("arbiterPoolAddress was not set"); + + const query = { complaint: { complaint_id: complaintId } }; + const complaint = await this.client.queryContractSmart(this.arbiterPoolAddress, query); + return { ...complaint, complaint_id: complaintId }; + } +} + +export class ApContract extends ApContractQuerier { + static readonly GAS_PROPOSE = 200_000; + static readonly GAS_VOTE = 200_000; + static readonly GAS_EXECUTE = 500_000; + static readonly GAS_CLOSE = 500_000; + static readonly GAS_REGISTER_COMPLAINT = 500_000; + static readonly GAS_ACCEPT_COMPLAINT = 500_000; + static readonly GAS_WITHDRAW_COMPLAINT = 500_000; + static readonly GAS_RENDER_DECISION = 500_000; + + readonly #signingClient: SigningCosmWasmClient; + + constructor(config: NetworkConfig, signingClient: SigningCosmWasmClient) { + super(config, signingClient); + this.#signingClient = signingClient; + } + + async propose( + senderAddress: string, + description: string, + proposal: ApoolProposal, + ): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const title = getProposalTitle(proposal); + const msg = { propose: { title, description, proposal } }; + + const result = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolVotingAddress, + msg, + calculateFee(ApContract.GAS_PROPOSE, this.config.gasPrice), + ); + + const proposalIdAttr = result.logs + .flatMap((log) => log.events) + .flatMap((event) => event.attributes) + .find((attr) => attr.key === "proposal_id"); + + const proposalId = proposalIdAttr ? parseInt(proposalIdAttr.value, 10) : undefined; + + return { txHash: result.transactionHash, proposalId }; + } + + async voteProposal(senderAddress: string, proposalId: number, vote: VoteOption): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const msg = { vote: { proposal_id: proposalId, vote } }; + const { transactionHash } = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolVotingAddress, + msg, + calculateFee(ApContract.GAS_VOTE, this.config.gasPrice), + ); + return transactionHash; + } + + async executeProposal(senderAddress: string, proposalId: number): Promise { + await this.initAddress(); + if (!this.arbiterPoolVotingAddress) throw new Error("arbiterPoolVotingAddress was not set"); + + const msg = { execute: { proposal_id: proposalId } }; + const { transactionHash } = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolVotingAddress, + msg, + calculateFee(ApContract.GAS_EXECUTE, this.config.gasPrice), + ); + return transactionHash; + } + + async registerComplaint( + senderAddress: string, + title: string, + description: string, + defendant: string, + ): Promise { + await this.initAddress(); + if (!this.arbiterPoolAddress) throw new Error("arbiterPoolAddress was not set"); + + const msg = { register_complaint: { title, description, defendant } }; + const { transactionHash } = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolAddress, + msg, + calculateFee(ApContract.GAS_REGISTER_COMPLAINT, this.config.gasPrice), + ); + return transactionHash; + + // TODO return complaintId too, getting it from the logs events + // return { txHash: result.transactionHash, complaintId }; + } + + async acceptComplaint(senderAddress: string, complaintId: number): Promise { + await this.initAddress(); + if (!this.arbiterPoolAddress) throw new Error("arbiterPoolAddress was not set"); + + const msg = { accept_complaint: { complaint_id: complaintId } }; + const { transactionHash } = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolAddress, + msg, + calculateFee(ApContract.GAS_ACCEPT_COMPLAINT, this.config.gasPrice), + ); + return transactionHash; + } + + async withdrawComplaint(senderAddress: string, complaintId: number, reason: string): Promise { + await this.initAddress(); + if (!this.arbiterPoolAddress) throw new Error("arbiterPoolAddress was not set"); + + const msg = { withdraw_complaint: { complaint_id: complaintId, reason } }; + const { transactionHash } = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolAddress, + msg, + calculateFee(ApContract.GAS_WITHDRAW_COMPLAINT, this.config.gasPrice), + ); + return transactionHash; + } + + async renderDecision( + senderAddress: string, + complaintId: number, + summary: string, + ipfsLink: string, + ): Promise { + await this.initAddress(); + if (!this.arbiterPoolAddress) throw new Error("arbiterPoolAddress was not set"); + + const msg = { render_decision: { complaint_id: complaintId, summary, ipfs_link: ipfsLink } }; + const { transactionHash } = await this.#signingClient.execute( + senderAddress, + this.arbiterPoolAddress, + msg, + calculateFee(ApContract.GAS_RENDER_DECISION, this.config.gasPrice), + ); + return transactionHash; + } +}