class MsgDeposit(StdMsg): type = "gov/MsgDeposit" action = "deposit" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^gov/MsgDeposit\Z"), value=S.OBJECT( proposal_id=S.STRING_INTEGER, depositor=S.ACC_ADDRESS, amount=Coins.__schema__, ), ) proposal_id: int depositor: AccAddress amount: Coins def __post_init__(self): self.depositor = validate_acc_address(self.depositor) self.amount = Coins(self.amount) def msg_value(self) -> dict: d = dict(self.__dict__) d["proposal_id"] = str(self.proposal_id) return d @classmethod def from_data(cls, data: dict) -> MsgDeposit: data = data["value"] return cls( proposal_id=int(data["proposal_id"]), depositor=data["depositor"], amount=Coins.from_data(data["amount"]), )
class MsgSend(StdMsg): type = "bank/MsgSend" action = "send" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^bank/MsgSend\Z"), value=S.OBJECT( from_address=S.ACC_ADDRESS, to_address=S.ACC_ADDRESS, amount=Coins.__schema__, ), ) from_address: AccAddress to_address: AccAddress amount: Union[Coins, List[Coin]] def __post_init__(self): self.from_address = validate_acc_address(self.from_address) self.to_address = validate_acc_address(self.to_address) self.amount = Coins(self.amount) @classmethod def from_data(cls, data: dict) -> MsgSend: data = data["value"] amount = Coins.from_data(data["amount"]) return cls( from_address=data["from_address"], to_address=data["to_address"], amount=amount, )
class MsgExchangeRatePrevote(StdMsg): type = "oracle/MsgExchangeRatePrevote" action = "exchangerateprevote" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^oracle/MsgExchangeRatePrevote\Z"), value=S.OBJECT( hash=S.STRING, denom=S.STRING, feeder=S.ACC_ADDRESS, validator=S.VAL_ADDRESS, ), ) hash: str denom: str feeder: AccAddress validator: ValAddress def __post_init__(self): self.feeder = AccAddress(self.feeder) self.validator = ValAddress(self.validator) @classmethod def from_data(cls, data: dict) -> MsgExchangeRatePrevote: data = data["value"] return cls( hash=data["hash"], denom=data["denom"], feeder=data["feeder"], validator=data["validator"], )
class MsgSwap(StdMsg): type = "market/MsgSwap" action = "swap" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^market/MsgSwap\Z"), value=S.OBJECT(trader=S.ACC_ADDRESS, offer_coin=Coin.__schema__, ask_denom=S.STRING), ) trader: AccAddress offer_coin: Coin ask_denom: str def __post_init__(self): self.trader = validate_acc_address(self.trader) @classmethod def from_data(cls, data: dict) -> MsgSwap: data = data["value"] return cls( trader=data["trader"], offer_coin=Coin.from_data(data["offer_coin"]), ask_denom=data["ask_denom"], )
class MsgSubmitProposal(StdMsg): type = "gov/MsgSubmitProposal" action = "submit_proposal" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^gov/MsgSubmitProposal\Z"), value=S.OBJECT( content=S.ANY(*(pt.__schema__ for pt in PROPOSAL_TYPES.values())), initial_deposit=Coins.__schema__, proposer=S.ACC_ADDRESS, ), ) content: Type[Content] initial_deposit: Coins proposer: AccAddress def __post_init__(self): self.proposer = validate_acc_address(self.proposer) self.initial_deposit = Coins(self.initial_deposit) @classmethod def from_data(cls, data: dict) -> MsgSubmitProposal: data = data["value"] p_type = PROPOSAL_TYPES[data["content"]["type"]] content = p_type.from_data(data["content"]) return cls( content=content, initial_deposit=Coins.from_data(data["initial_deposit"]), proposer=data["proposer"], )
class ParameterChangeProposal(Content): type = "params/ParameterChangeProposal" ParamChanges = ParamChanges # alias for easy access __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^params/ParameterChangeProposal\Z"), value=S.OBJECT( title=S.STRING, description=S.STRING, changes=ParamChanges.__schema__, ), ) title: str description: str changes: ParamChanges = field(default_factory=ParamChanges) def __post_init__(self): # validation checks for key if isinstance(self.changes, dict): self.changes = ParamChanges(self.changes) @classmethod def from_data(cls, data: dict) -> ParameterChangeProposal: data = data["value"] return cls( title=data["title"], description=data["description"], changes=ParamChanges.from_data(data["changes"]), )
class MsgUndelegate(StdMsg): type = "staking/MsgUndelegate" action = "begin_unbonding" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^staking/MsgUndelegate\Z"), value=S.OBJECT( delegator_address=S.ACC_ADDRESS, validator_address=S.VAL_ADDRESS, amount=Coin.__schema__, ), ) delegator_address: AccAddress validator_address: ValAddress amount: Coin def __post_init__(self): self.delegator_address = validate_acc_address(self.delegator_address) self.validator_address = validate_val_address(self.validator_address) @classmethod def from_data(cls, data: dict) -> MsgUndelegate: data = data["value"] return cls( delegator_address=data["delegator_address"], validator_address=data["validator_address"], amount=Coin.from_data(data["amount"]), )
class Block(BlockHeader, JsonDeserializable): __schema__ = S.OBJECT( block_meta=BlockHeader.__schema__, block=S.OBJECT( data=S.OBJECT(txs=S.OPTIONAL(S.ARRAY(S.STRING))), evidence={}, last_commit={}, ), ) evidence: JiguBox # TODO: improve and document last_commit: JiguBox # TODO: improve and document txs: List[ Union[str, StdTx, TxInfo, TxInfosQuery]] # ordered last for convenience of pretty printing @classmethod def from_data(cls, data: dict) -> Block: header = BlockHeader.from_data(data["block_meta"]) txs = (data["block"]["data"]["txs"] or []) # these will be Amino-encoded tx strings evidence = JiguBox(data["block"].get("evidence")) last_commit = JiguBox(data["block"].get("last_commit")) return cls(txs=txs, evidence=evidence, last_commit=last_commit, **header.__dict__)
class MsgWithdrawDelegationReward(StdMsg): type = "distribution/MsgWithdrawDelegationReward" action = "withdraw_delegation_reward" schema = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^distribution/MsgWithdrawDelegationReward\Z"), value=S.OBJECT( delegator_address=S.ACC_ADDRESS, validator_address=S.VAL_ADDRESS ), ) delegator_address: AccAddress validator_address: ValAddress def __post_init__(self): self.delegator_address = validate_acc_address(self.delegator_address) self.validator_address = validate_val_address(self.validator_address) @classmethod def from_data(cls, data: dict) -> MsgWithdrawDelegationReward: data = data["value"] return cls( delegator_address=data["delegator_address"], validator_address=data["validator_address"], )
class CommunityPoolSpendProposal(Content): type = "distribution/CommunityPoolSpendProposal" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN( r"^distribution/CommunityPoolSpendProposal\Z"), value=S.OBJECT( title=S.STRING, description=S.STRING, recipient=S.ACC_ADDRESS, amount=Coins.__schema__, ), ) title: str description: str recipient: AccAddress amount: Coins @classmethod def from_data(cls, data: dict) -> CommunityPoolSpendProposal: data = data["value"] return cls( title=data["title"], description=data["description"], recipient=data["recipient"], amount=Coins.from_data(data["amount"]), )
class MsgExchangeRateVote(StdMsg): type = "oracle/MsgExchangeRateVote" action = "exchangeratevote" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^oracle/MsgExchangeRateVote\Z"), value=S.OBJECT( exchange_rate=Dec.__schema__, salt=S.STRING, denom=S.STRING, feeder=S.ACC_ADDRESS, validator=S.VAL_ADDRESS, ), ) exchange_rate: Union[str, Type[Decimal], Coin, int] salt: str denom: str feeder: AccAddress validator: ValAddress def __post_init__(self): self.feeder = validate_acc_address(self.feeder) self.validator = validate_val_address(self.validator) if not isinstance(self.exchange_rate, Coin): self.exchange_rate = Coin(self.denom, self.exchange_rate) else: validate_same_denom(self.exchange_rate.denom, self.denom) def msg_value(self) -> dict: d = dict(self.__dict__) d["exchange_rate"] = str(self.exchange_rate.amount) return d @property def vote_hash(self): return vote_hash(self.salt, self.exchange_rate.amount, self.denom, self.validator) @property def prevote(self): return MsgExchangeRatePrevote( hash=self.vote_hash, denom=self.denom, feeder=self.feeder, validator=self.validator, ) @classmethod def from_data(cls, data: dict) -> MsgExchangeRateVote: data = data["value"] xr = Coin(data["denom"], data["exchange_rate"]) return cls( exchange_rate=xr, salt=data["salt"], denom=xr.denom, feeder=data["feeder"], validator=data["validator"], )
class BlockHeader(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( block_id=S.OBJ, header=S.OBJECT( chain_id=S.STRING, height=S.STRING_INTEGER, time=Timestamp.__schema__, num_txs=S.STRING_INTEGER, total_txs=S.STRING_INTEGER, last_commit_hash=S.STRING, data_hash=S.STRING, next_validators_hash=S.STRING, consensus_hash=S.STRING, app_hash=S.STRING, proposer_address=S.STRING, last_block_id=S.OBJ, ), ) chain_id: str height: int time: Timestamp num_txs: int total_txs: int hashes: dict proposer: str block_id: JiguBox last_block_id: JiguBox @classmethod def from_data(cls, data: dict) -> BlockHeader: header = data["header"] hashes = JiguBox({ "last_commit": header["last_commit_hash"], "data": header["data_hash"], "validators": header["validators_hash"], "next_validators": header["next_validators_hash"], "consensus": header["consensus_hash"], "app": header["app_hash"], "last_results": header["last_results_hash"], "evidence": header["evidence_hash"], }) return cls( chain_id=header["chain_id"], height=int(header["height"]), time=Timestamp.from_data(header["time"]), num_txs=int(header["num_txs"]), total_txs=int(header["total_txs"]), hashes=hashes, proposer=header["proposer_address"], block_id=JiguBox(data["block_id"]), last_block_id=JiguBox(header["last_block_id"]), )
class MsgMultiSend(StdMsg): type = "bank/MsgMultiSend" action = "multisend" Input = Input # alias Output = Output # alias __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^bank/MsgMultiSend\Z"), value=S.OBJECT(inputs=S.ARRAY(Input.__schema__), outputs=S.ARRAY(Output.__schema__)), ) inputs: List[Union[Input, dict]] outputs: List[Union[Output, dict]] def __init__( self, inputs: List[Input], outputs: List[Output], ): self.inputs = [] self.outputs = [] for i in inputs: if isinstance(i, dict): self.inputs.append( Input(address=i["address"], coins=i["coins"])) elif isinstance(i, Input): self.inputs.append(i) else: raise TypeError( f"invalid item {type(i)} encountered in MsgMultiSend.inputs, can only accept 'Input' or 'dict'." ) for o in outputs: if isinstance(o, dict): self.outputs.append( Output(address=o["address"], coins=o["coins"])) elif isinstance(o, Output): self.outputs.append(o) else: raise TypeError( f"invalid item {type(o)} encountered in MsgMultiSend.outputs, can only accept 'Output' or 'dict'." ) @classmethod def from_data(cls, data: dict) -> MsgMultiSend: data = data["value"] return cls( inputs=[Input.from_data(i) for i in data["inputs"]], outputs=[Output.from_data(o) for o in data["outputs"]], )
class MsgCreateValidator(StdMsg): type = "staking/MsgCreateValidator" action = "create_validator" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^staking/MsgCreateValidator\Z"), value=S.OBJECT( description=Description.__schema__, commission=CommissionRates.__schema__, min_self_delegation=S.STRING_INTEGER, delegator_address=S.ACC_ADDRESS, validator_address=S.VAL_ADDRESS, pubkey=S.VAL_CONSPUBKEY, value=Coin.__schema__, ), ) description: Description commission: CommissionRates min_self_delegation: int delegator_address: AccAddress validator_address: ValAddress pubkey: ValConsPubKey value: Coin def __post_init__(self): self.delegator_address = validate_acc_address(self.delegator_address) self.validator_address = validate_val_address(self.validator_address) validate_val_conspubkey(self.pubkey) self.min_self_delegation = int(self.min_self_delegation) def msg_value(self) -> dict: d = dict(self.__dict__) msd = self.min_self_delegation d["min_self_delegation"] = str(msd) return d @classmethod def from_data(cls, data: dict) -> MsgCreateValidator: data = data["value"] return cls( description=Description.from_data(data["description"]), commission=CommissionRates.from_data(data["commission"]), min_self_delegation=int(data["min_self_delegation"]), delegator_address=data["delegator_address"], validator_address=data["validator_address"], pubkey=data["pubkey"], value=Coin.from_data(data["value"]), )
class UnbondingEntry(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( initial_balance=S.STRING_INTEGER, balance=S.STRING_INTEGER, creation_height=S.STRING_INTEGER, completion_time=Timestamp.__schema__, ) initial_balance: Coin balance: Coin creation_height: int completion_time: Timestamp def to_data(self) -> dict: return { "initial_balance": str(self.initial_balance.amount), "balance": str(self.balance.amount), "creation_height": str(self.creation_height), "completion_time": self.completion_time, } @classmethod def from_data(cls, data: Dict[str, str]) -> UnbondingEntry: return cls( initial_balance=Coin(uLuna, data["initial_balance"]), balance=Coin(uLuna, data["balance"]), creation_height=int(data["creation_height"]), completion_time=Timestamp.from_data(data["completion_time"]), )
class StdFee(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT(gas=S.STRING_INTEGER, amount=Coins.__schema__) gas: int = 0 amount: Coins = field(default_factory=Coins) def __post_init__(self): self.amount = Coins(self.amount) def to_data(self) -> dict: return {"gas": str(self.gas), "amount": self.amount} @property def min_gas_prices(self) -> Coins: return self.amount.dec_coins / self.gas @classmethod def make(cls, gas: int = 0, **denoms): amount = Coins() for denom in denoms: amount += Coin(denom, denoms[denom]) return cls(gas=gas, amount=amount) @classmethod def from_data(cls, data: dict) -> StdFee: return cls(gas=int(data["gas"]), amount=Coins.from_data(data["amount"]))
class RedelegationEntry(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( initial_balance=S.STRING_INTEGER, balance=S.STRING_INTEGER, shares_dst=Dec.__schema__, creation_height=S.INTEGER, completion_time=Timestamp.__schema__, ) initial_balance: Coin balance: Coin shares_dst: Coin creation_height: int completion_time: Timestamp def to_data(self) -> dict: return { "creation_height": self.creation_height, "completion_time": self.completion_time, "initial_balance": str(self.initial_balance.amount), "balance": str(self.balance.amount), "shares_dst": str(self.shares_dst.amount), } @classmethod def from_data(cls, data: dict) -> RedelegationEntry: return cls( initial_balance=Coin(uLuna, data["initial_balance"]), balance=Coin(uLuna, data["balance"]), shares_dst=Coin(uLuna, data["shares_dst"]), creation_height=int(data["creation_height"]), completion_time=Timestamp.from_data(data["completion_time"]), )
class Content(JsonSerializable, JsonDeserializable, metaclass=abc.ABCMeta): __schema__ = S.OBJECT( type=S.STRING, value=S.OBJECT(title=S.STRING, description=S.STRING) ) @property @abc.abstractmethod def type(self): raise NotImplementedError def proposal_value(self): return dict(self.__dict__) def to_data(self) -> Dict[str, Any]: return {"type": self.type, "value": self.proposal_value()}
class TextProposal(Content): type = "gov/TextProposal" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^gov/TextProposal\Z"), value=S.OBJECT(title=S.STRING, description=S.STRING), ) title: str description: str @classmethod def from_data(cls, data: dict) -> TextProposal: data = data["value"] return cls(title=data["title"], description=data["description"])
class Delegation(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( delegator_address=S.ACC_ADDRESS, validator_address=S.VAL_ADDRESS, shares=Dec.__schema__, balance=S.STRING_INTEGER, ) delegator_address: AccAddress validator_address: ValAddress shares: Coin balance: Coin def to_data(self) -> dict: return { "delegator_address": self.delegator_address, "validator_address": self.validator_address, "shares": str(self.shares.amount), "balance": str(self.balance.amount), } @classmethod def from_data(cls, data: Dict[str, str]) -> Delegation: return cls( delegator_address=data["delegator_address"], validator_address=data["validator_address"], shares=Coin(uLuna, data["shares"]), balance=Coin(uLuna, data["balance"]), )
class ExchangeRatePrevote(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( hash=S.STRING, denom=S.STRING, voter=S.VAL_ADDRESS, submit_block=S.STRING_INTEGER, ) hash: str denom: str voter: ValAddress submit_block: int def __post_init__(self): self.voter = validate_val_address(self.voter) self.submit_block = int(self.submit_block) def to_data(self) -> Dict[str, str]: return { "hash": self.hash, "denom": self.denom, "voter": self.voter, "submit_block": str(self.submit_block), } @classmethod def from_data(cls, data: Dict[str, str]) -> ExchangeRatePrevote: return cls( hash=data["hash"], denom=data["denom"], voter=data["voter"], submit_block=int(data["submit_block"]), )
class Account(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^core/Account\Z"), value=S.OBJECT( address=S.ACC_ADDRESS, coins=Coins.__schema__, public_key=S.OPTIONAL(PublicKey.__schema__), account_number=S.STRING_INTEGER, sequence=S.STRING_INTEGER, ), ) address: str coins: Coins public_key: Optional[PublicKey] account_number: int sequence: int def __post_init__(self): if self.address: self.address = validate_acc_address(self.address) if self.coins: self.coins = Coins(self.coins) self.account_number = int(self.account_number) self.sequence = int(self.sequence) def to_data(self) -> dict: d = dict(self.__dict__) d["account_number"] = str(self.account_number) d["sequence"] = str(self.sequence) return {"type": "core/Account", "value": d} @classmethod def from_data(cls, data: dict) -> Account: if "type" in data: data = data["value"] pk = data["public_key"] if pk is not None: pk = PublicKey.deserialize(data["public_key"]) return cls( address=data["address"], coins=Coins.from_data(data["coins"]), public_key=pk, account_number=data["account_number"], sequence=data["sequence"], )
class Validator(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( operator_address=S.VAL_ADDRESS, consensus_pubkey=S.STRING, tokens=S.STRING_INTEGER, jailed=S.BOOLEAN, status=S.INTEGER, # this is converted to string delegator_shares=Dec.__schema__, description=Description.__schema__, unbonding_height=S.STRING_INTEGER, unbonding_time=Timestamp.__schema__, commission=Commission.__schema__, min_self_delegation=S.STRING_INTEGER, ) operator_address: ValAddress consensus_pubkey: str jailed: bool status_code: int tokens: Coin delegator_shares: Coin description: Description unbonding_height: int unbonding_time: Timestamp commission: Commission min_self_delegation: int @property def status(self) -> str: """String version of `status_code`""" return ["unbonded", "unbonding", "bonded"][self.status_code] def to_data(self) -> dict: s = self d = dict(self.__dict__) del d["status_code"] d["status"] = s.status_code d["tokens"] = str(s.tokens.amount) d["delegator_shares"] = str(s.delegator_shares.amount) d["unbonding_height"] = str(s.unbonding_height) d["min_self_delegation"] = str(s.min_self_delegation) return d @classmethod def from_data(cls, data: dict) -> Validator: return cls( operator_address=data["operator_address"], consensus_pubkey=data["consensus_pubkey"], jailed=data["jailed"], status_code=data["status"], tokens=Coin(uLuna, data["tokens"]), delegator_shares=Coin(uLuna, data["delegator_shares"]), description=Description.from_data(data["description"]), unbonding_height=int(data["unbonding_height"]), unbonding_time=Timestamp.from_data(data["unbonding_time"]), commission=Commission.from_data(data["commission"]), min_self_delegation=int(data["min_self_delegation"]), )
class MsgEditValidator(StdMsg): type = "staking/MsgEditValidator" action = "edit_validator" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^staking/MsgEditValidator\Z"), value=S.OBJECT( Description=Description.__schema__, address=S.VAL_ADDRESS, commission_rate=S.OPTIONAL(Dec.__schema__), min_self_delegation=S.OPTIONAL(S.STRING_INTEGER), ), ) Description: Description address: ValAddress commission_rate: Optional[Dec] = None min_self_delegation: Optional[int] = None def __post_init__(self): if self.commission_rate is not None: self.commission_rate = Dec(self.commission_rate) if self.min_self_delegation is not None: self.min_self_delegation = int(self.min_self_delegation) self.address = validate_val_address(self.address) def msg_value(self) -> dict: d = dict(self.__dict__) msd = self.min_self_delegation if msd is not None: msd = str(msd) d["min_self_delegation"] = msd return d @classmethod def from_data(cls, data: dict) -> MsgEditValidator: data = data["value"] msd = int(data["min_self_delegation"]) if data["min_self_delegation"] else None cr = Dec(data["commission_rate"]) if data["commission_rate"] else None return cls( Description=data["Description"], address=data["address"], commission_rate=cr, min_self_delegation=msd, )
class TxBroadcastResult(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( height=S.STRING_INTEGER, txhash=S.STRING, raw_log=S.STRING, logs=S.ARRAY(MsgInfo.__schema__), gas_wanted=S.STRING_INTEGER, gas_used=S.STRING_INTEGER, events=S.ARRAY({}), ) height: int txhash: str raw_log: str # logs: list gas_wanted: int gas_used: int # events: list msgs: MsgInfosQuery @property def pretty_data(self): d = dict(self.__dict__) d.pop("raw_log") return d.items() @property def events(self): return self.msgs.events @classmethod def from_data(cls, data: dict, tx) -> TxBroadcastResult: logs = TxInfo.merge_logs(data, tx) if logs: logs = MsgInfosQuery(logs) return cls( height=data.get("height") and int(data["height"]), txhash=data.get("txhash"), raw_log=data.get("raw_log"), gas_wanted=data.get("gas_wanted") and int(data["gas_wanted"]), gas_used=data.get("gas_used") and int(data["gas_used"]), # events=data.get("events"), msgs=logs, )
class MsgWithdrawValidatorCommission(StdMsg): type = "distribution/MsgWithdrawValidatorCommission" action = "withdraw_validator_commission" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^distribution/MsgWithdrawValidatorCommission\Z"), value=S.OBJECT(validator_address=S.VAL_ADDRESS), ) validator_address: ValAddress def __post_init__(self): self.validator_address = validate_val_address(self.validator_address) @classmethod def from_data(cls, data: dict) -> MsgWithdrawValidatorCommission: data = data["value"] return cls(validator_address=data["validator_address"])
class MsgUnjail(StdMsg): type = "cosmos/MsgUnjail" action = "unjail" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^cosmos/MsgUnjail\Z"), value=S.OBJECT(address=S.VAL_ADDRESS), ) address: ValAddress def __post_init__(self): self.address = validate_val_address(self.address) @classmethod def from_data(cls, data: dict) -> MsgUnjail: data = data["value"] return cls(address=data["address"])
class MsgDelegateFeedConsent(StdMsg): type = "oracle/MsgDelegateFeedConsent" action = "delegatefeeder" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^oracle/MsgDelegateFeedConsent\Z"), value=S.OBJECT(operator=S.VAL_ADDRESS, delegate=S.ACC_ADDRESS), ) operator: ValAddress delegate: AccAddress def __post_init__(self): self.operator = validate_val_address(self.operator) self.delegate = validate_acc_address(self.delegate) @classmethod def from_data(cls, data: dict) -> MsgDelegateFeedConsent: data = data["value"] return cls(operator=data["operator"], delegate=data["delegate"])
class MsgVote(StdMsg): type = "gov/MsgVote" action = "vote" __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^gov/MsgVote\Z"), value=S.OBJECT( proposal_id=S.STRING_INTEGER, voter=S.ACC_ADDRESS, option=S.ONE(S.STRING, S.INTEGER), # signing is different ), ) EMPTY = "Empty" YES = "Yes" ABSTAIN = "Abstain" NO = "No" NO_WITH_VETO = "NoWithVeto" proposal_id: int voter: AccAddress option: str def __post_init__(self): self.voter = validate_acc_address(self.voter) def msg_value(self) -> dict: d = dict(self.__dict__) d["proposal_id"] = str(self.proposal_id) return d @classmethod def from_data(cls, data: dict) -> MsgVote: data = data["value"] return cls( proposal_id=int(data["proposal_id"]), voter=data["voter"], option=data["option"], )
class StdTx(JsonSerializable, JsonDeserializable): __schema__ = S.OBJECT( type=S.STRING_WITH_PATTERN(r"^core/StdTx\Z"), value=S.OBJECT( fee=StdFee.__schema__, msg=S.ARRAY(S.ANY(*(mt.__schema__ for mt in MSG_TYPES.values()))), signatures=S.ARRAY(StdSignature.__schema__), memo=S.STRING, ), ) # NOTE: msg is not plural, and is NOT a typo. This may change later for consistency. fee: Optional[StdFee] = None msg: List[StdMsg] = field(default_factory=list) signatures: List[StdSignature] = field(default_factory=list) memo: str = "" def to_data(self) -> dict: return { "type": "core/StdTx", "value": dict(self.__dict__), } @classmethod def from_data(cls, data: dict) -> StdTx: data = data["value"] fee = StdFee.from_data(data["fee"]) # deserialize the messages msg = [] for m in data["msg"]: msg_type = MSG_TYPES[m["type"]] msg.append(msg_type.from_data(m)) signatures = [StdSignature.from_data(s) for s in data["signatures"]] return cls(fee=fee, msg=msg, signatures=signatures, memo=data["memo"])