|
22 | 22 | from pyinjective.proto.cosmos.staking.v1beta1 import tx_pb2 as cosmos_staking_tx_pb |
23 | 23 | from pyinjective.proto.cosmwasm.wasm.v1 import tx_pb2 as wasm_tx_pb |
24 | 24 | from pyinjective.proto.exchange import injective_explorer_rpc_pb2 as explorer_pb2 |
| 25 | +from pyinjective.proto.ibc.applications.transfer.v1 import tx_pb2 as ibc_transfer_tx_pb |
| 26 | +from pyinjective.proto.ibc.core.client.v1 import client_pb2 as ibc_core_client_pb |
25 | 27 | from pyinjective.proto.injective.auction.v1beta1 import tx_pb2 as injective_auction_tx_pb |
26 | 28 | from pyinjective.proto.injective.exchange.v1beta1 import ( |
27 | 29 | authz_pb2 as injective_authz_pb, |
@@ -143,14 +145,14 @@ def Coin(self, amount: int, denom: str): |
143 | 145 | warn("This method is deprecated. Use coin instead", DeprecationWarning, stacklevel=2) |
144 | 146 | return base_coin_pb.Coin(amount=str(amount), denom=denom) |
145 | 147 |
|
146 | | - def coin(self, amount: int, denom: str): |
| 148 | + def coin(self, amount: int, denom: str) -> base_coin_pb.Coin: |
147 | 149 | """ |
148 | 150 | This method create an instance of Coin gRPC type, considering the amount is already expressed in chain format |
149 | 151 | """ |
150 | 152 | formatted_amount_string = str(int(amount)) |
151 | 153 | return base_coin_pb.Coin(amount=formatted_amount_string, denom=denom) |
152 | 154 |
|
153 | | - def create_coin_amount(self, amount: Decimal, token_name: str): |
| 155 | + def create_coin_amount(self, amount: Decimal, token_name: str) -> base_coin_pb.Coin: |
154 | 156 | """ |
155 | 157 | This method create an instance of Coin gRPC type, considering the amount is already expressed in chain format |
156 | 158 | """ |
@@ -2142,6 +2144,38 @@ def msg_update_distribution_params(self, authority: str, community_tax: str, wit |
2142 | 2144 | def msg_community_pool_spend(self, authority: str, recipient: str, amount: List[base_coin_pb.Coin]): |
2143 | 2145 | return cosmos_distribution_tx_pb.MsgCommunityPoolSpend(authority=authority, recipient=recipient, amount=amount) |
2144 | 2146 |
|
| 2147 | + # region IBC Transfer module |
| 2148 | + def msg_ibc_transfer( |
| 2149 | + self, |
| 2150 | + source_port: str, |
| 2151 | + source_channel: str, |
| 2152 | + token_amount: base_coin_pb.Coin, |
| 2153 | + sender: str, |
| 2154 | + receiver: str, |
| 2155 | + timeout_height: Optional[int] = None, |
| 2156 | + timeout_timestamp: Optional[int] = None, |
| 2157 | + memo: Optional[str] = None, |
| 2158 | + ) -> ibc_transfer_tx_pb.MsgTransfer: |
| 2159 | + if timeout_height is None and timeout_timestamp is None: |
| 2160 | + raise ValueError("IBC Transfer error: Either timeout_height or timeout_timestamp must be provided") |
| 2161 | + parsed_timeout_height = None |
| 2162 | + if timeout_height: |
| 2163 | + parsed_timeout_height = ibc_core_client_pb.Height( |
| 2164 | + revision_number=timeout_height, revision_height=timeout_height |
| 2165 | + ) |
| 2166 | + return ibc_transfer_tx_pb.MsgTransfer( |
| 2167 | + source_port=source_port, |
| 2168 | + source_channel=source_channel, |
| 2169 | + token=token_amount, |
| 2170 | + sender=sender, |
| 2171 | + receiver=receiver, |
| 2172 | + timeout_height=parsed_timeout_height, |
| 2173 | + timeout_timestamp=timeout_timestamp, |
| 2174 | + memo=memo, |
| 2175 | + ) |
| 2176 | + |
| 2177 | + # endregion |
| 2178 | + |
2145 | 2179 | # data field format: [request-msg-header][raw-byte-msg-response] |
2146 | 2180 | # you need to figure out this magic prefix number to trim request-msg-header off the data |
2147 | 2181 | # this method handles only exchange responses |
|
0 commit comments