コード例 #1
0
 def from_data(cls, data: dict) -> LazyGradedVestingAccount:
     data = data["value"]
     return cls(
         address=data["address"],
         coins=Coins.from_data(data["coins"]),
         public_key=PublicKey.from_data(data["public_key"]),
         account_number=data["account_number"],
         sequence=data["sequence"],
         original_vesting=Coins.from_data(data["original_vesting"]),
         delegated_free=Coins.from_data(data["delegated_free"]),
         delegated_vesting=Coins.from_data(data["delegated_vesting"]),
         end_time=data["end_time"],
         vesting_schedules=data["vesting_schedules"],
     )
コード例 #2
0
    async def validator_rewards(self,
                                validator: ValAddress) -> ValidatorRewards:
        """Fetches the commission reward data for a validator.

        Args:
            validator (ValAddress): validator operator address

        Returns:
            ValidatorRewards: validator rewards
        """
        res = await self._c._get(f"/distribution/validators/{validator}")
        return ValidatorRewards(
            self_bond_rewards=Coins.from_data(res["self_bond_rewards"]),
            val_commission=Coins.from_data(res["val_commission"]),
        )
コード例 #3
0
 def from_data(cls, data: dict) -> MsgSend:
     data = data["value"]
     return cls(
         from_address=data["from_address"],
         to_address=data["to_address"],
         amount=Coins.from_data(data["amount"]),
     )
コード例 #4
0
    async def estimate_fee(
        self,
        tx: Union[StdSignMsg, StdTx],
        gas_prices: Optional[Coins.Input] = None,
        gas_adjustment: Optional[Numeric.Input] = None,
        denoms: Optional[List[str]] = None,
    ) -> StdFee:
        gas_prices = gas_prices or self._c.gas_prices
        gas_adjustment = gas_adjustment or self._c.gas_adjustment

        if isinstance(tx, StdSignMsg):
            tx_value = tx.to_stdtx().to_data()["value"]
        else:
            tx_value = tx.to_data()["value"]

        tx_value["fee"]["gas"] = "0"

        data = {
            "tx": tx_value,
            "gas_prices": gas_prices and Coins(gas_prices).to_data(),
            "gas_adjustment": gas_adjustment and str(gas_adjustment),
        }

        res = await self._c._post("/txs/estimate_fee", data)
        fees = Coins.from_data(res["fees"])
        # only pick the denoms we are interested in?
        if denoms:
            fees = fees.filter(lambda c: c.denom in denoms)  # type: ignore
        return StdFee(int(res["gas"]), fees)
コード例 #5
0
ファイル: msgs.py プロジェクト: r-amiri/terra-sdk-python
 def from_data(cls, data: dict) -> MsgDeposit:
     data = data["value"]
     return cls(
         proposal_id=data["proposal_id"],
         depositor=data["depositor"],
         amount=Coins.from_data(data["amount"]),
     )
コード例 #6
0
    async def community_pool(self) -> Coins:
        """Fetches the community pool.

        Returns:
            Coins: community pool
        """
        res = await self._c._get("/distribution/community_pool")
        return Coins.from_data(res)
コード例 #7
0
ファイル: proposals.py プロジェクト: r-amiri/terra-sdk-python
 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"]),
     )
コード例 #8
0
    async def tax_proceeds(self) -> Coins:
        """Fetches the current tax proceeds.

        Returns:
            Coins: tax proceeds
        """
        res = await self._c._get("/treasury/tax_proceeds")
        return Coins.from_data(res)
コード例 #9
0
 def from_data(cls, data: dict) -> MsgExecuteContract:
     data = data["value"]
     return cls(
         sender=data["sender"],
         contract=data["contract"],
         execute_msg=b64_to_dict(data["execute_msg"]),
         coins=Coins.from_data(data["coins"]),
     )
コード例 #10
0
 def from_data(cls, data: dict) -> Account:
     data = data["value"]
     return cls(
         address=data["address"],
         coins=Coins.from_data(data["coins"]),
         public_key=PublicKey.from_data(data["public_key"]),
         account_number=data["account_number"],
         sequence=data["sequence"],
     )
コード例 #11
0
 def from_data(cls, data: dict) -> MsgInstantiateContract:
     data = data["value"]
     return cls(
         owner=data["owner"],
         code_id=data["code_id"],
         init_msg=b64_to_dict(data["init_msg"]),
         init_coins=Coins.from_data(data["init_coins"]),
         migratable=data["migratable"],
     )
コード例 #12
0
ファイル: msgs.py プロジェクト: r-amiri/terra-sdk-python
    def from_data(cls, data: dict) -> MsgSubmitProposal:
        from terra_sdk.util.parse_content import parse_content

        data = data["value"]
        content = parse_content(data["content"])
        return cls(
            content=content,
            initial_deposit=Coins.from_data(data["initial_deposit"]),
            proposer=data["proposer"],
        )
コード例 #13
0
    async def rewards(self, delegator: AccAddress) -> Rewards:
        """Fetches the staking reward data for a delegator.

        Args:
            delegator (AccAddress): delegator account address

        Returns:
            Rewards: delegator rewards
        """
        res = await self._c._get(
            f"/distribution/delegators/{delegator}/rewards")
        return Rewards(
            rewards={
                item["validator_address"]: Coins.from_data(item["reward"]
                                                           or [])
                for item in res["rewards"]
            },
            total=Coins.from_data(res["total"]),
        )
コード例 #14
0
    async def exchange_rates(self) -> Coins:
        """Fetches registered exchange rates of Luna in all available denoms.

        Returns:
            Coins: exchange rates of Luna
        """
        res = await self._c._get("/oracle/denoms/exchange_rates")
        if res:
            return Coins.from_data(res)
        else:
            return Coins({})
コード例 #15
0
ファイル: bank.py プロジェクト: r-amiri/terra-sdk-python
    async def balance(self, address: AccAddress) -> Coins:
        """Fetches an account's current balance.

        Args:
            address (AccAddress): account address

        Returns:
            Coins: balance
        """
        res = await self._c._get(f"/bank/balances/{address}")
        return Coins.from_data(res)
コード例 #16
0
ファイル: data.py プロジェクト: stjordanis/terra-sdk-python
 def from_data(cls, data: dict) -> Proposal:
     return cls(
         id=data["id"],
         content=Content.from_data(data["content"]),
         proposal_status=data["proposal_status"],
         final_tally_result=data["final_tally_result"],
         submit_time=data["submit_time"],
         deposit_end_time=data["deposit_end_time"],
         total_deposit=Coins.from_data(data["total_deposit"]),
         voting_start_time=data["voting_start_time"],
         voting_end_time=data["voting_end_time"],
     )
コード例 #17
0
ファイル: tx.py プロジェクト: r-amiri/terra-sdk-python
    async def estimate_fee(
        self,
        tx: Union[StdSignMsg, StdTx],
        gas_prices: Optional[Coins.Input] = None,
        gas_adjustment: Optional[Numeric.Input] = None,
        denoms: Optional[List[str]] = None,
    ) -> StdFee:
        """Estimates the proper fee to apply by simulating it within the node.

        Args:
            tx (Union[StdSignMsg, StdTx]): transaction to estimate fee for
            gas_prices (Optional[Coins.Input], optional): gas prices to use.
            gas_adjustment (Optional[Numeric.Input], optional): gas adjustment to use.
            denoms (Optional[List[str]], optional): list of denoms to use to pay for gas.

        Returns:
            StdFee: estimated fee
        """
        gas_prices = gas_prices or self._c.gas_prices
        gas_adjustment = gas_adjustment or self._c.gas_adjustment

        if isinstance(tx, StdSignMsg):
            tx_value = tx.to_stdtx().to_data()["value"]
        else:
            tx_value = tx.to_data()["value"]

        tx_value["fee"]["gas"] = "0"

        data = {
            "tx": tx_value,
            "gas_prices": gas_prices and Coins(gas_prices).to_data(),
            "gas_adjustment": gas_adjustment and str(gas_adjustment),
        }

        res = await self._c._post("/txs/estimate_fee", data)
        fees = Coins.from_data(res["fees"])
        # only pick the denoms we are interested in?
        if denoms:
            fees = fees.filter(lambda c: c.denom in denoms)  # type: ignore
        return StdFee(int(res["gas"]), fees)
コード例 #18
0
 async def balance(self, address: AccAddress) -> Coins:
     res = await self._c._get(f"/bank/balances/{address}")
     return Coins.from_data(res)
コード例 #19
0
 def from_data(cls, data: dict) -> MsgFundCommunityPool:
     data = data["value"]
     return cls(depositor=data["depositor"],
                amount=Coins.from_data(data["amount"]))
コード例 #20
0
 async def tax_proceeds(self) -> Coins:
     res = await self._c._get(f"/treasury/tax_proceeds")
     return Coins.from_data(res)
コード例 #21
0
ファイル: data.py プロジェクト: r-amiri/terra-sdk-python
 def from_data(cls, data: dict) -> SendAuthorization:
     data = data["value"]
     return cls(spend_limit=Coins.from_data(data["spend_limit"]))
コード例 #22
0
ファイル: oracle.py プロジェクト: stjordanis/terra-sdk-python
 async def exchange_rates(self) -> Coins:
     res = self._c._get(f"/oracle/denoms/exchange_rates", raw=True)
     if res.get("result"):
         return Coins.from_data(res)
     else:
         return Coins({})