Skip to content

Commit

Permalink
Problem: ibc channel upgrade related methods are not supported (#139)
Browse files Browse the repository at this point in the history
* Problem: ibc channel upgrade related methods are not supported

* register_counterparty_payee

* pay_packet_fee

* ibc_denom_trace

* ci

* Update .github/workflows/test.yml

Signed-off-by: yihuang <[email protected]>

---------

Signed-off-by: yihuang <[email protected]>
Co-authored-by: yihuang <[email protected]>
  • Loading branch information
mmsqe and yihuang authored Oct 14, 2024
1 parent 7b83d80 commit a7dac7f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- [#128](https://github.com/crypto-com/pystarport/pull/128) fix wrong description on empty flag when create validator and align flags for edit validator.
- [#129](https://github.com/crypto-com/pystarport/pull/129) create and get validator are incompatible.
- [#137](https://github.com/crypto-com/pystarport/pull/137) support ica and icaauth cmd.
- [#139](https://github.com/crypto-com/pystarport/pull/139) support ibc channel upgrade related methods.

*Feb 7, 2023*

Expand Down
26 changes: 26 additions & 0 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ def migrate_keystore(self, i=0):
def ibc_query_channels(self, connid, i=0, **kwargs):
return self.cosmos_cli(i).ibc_query_channels(connid, **kwargs)

def ibc_query_channel(self, port_id, channel_id, i=0, **kwargs):
return self.cosmos_cli(i).ibc_query_channel(port_id, channel_id, **kwargs)

def ica_register_account(self, connid, i=0, event_query_tx=True, **kwargs):
return self.cosmos_cli(i).ica_register_account(
connid,
Expand Down Expand Up @@ -813,6 +816,24 @@ def ica_submit_tx(
def ica_generate_packet_data(self, tx, memo=None, encoding="proto3", i=0, **kwargs):
return self.cosmos_cli(i).ica_generate_packet_data(memo, encoding, **kwargs)

def ibc_upgrade_channels(self, version, from_addr, i=0, **kwargs):
return self.cosmos_cli(i).ibc_upgrade_channels(version, from_addr, **kwargs)

def register_counterparty_payee(
self, port_id, channel_id, relayer, counterparty_payee, i=0, **kwargs
):
return self.cosmos_cli(i).register_counterparty_payee(
port_id, channel_id, relayer, counterparty_payee, **kwargs
)

def pay_packet_fee(self, port_id, channel_id, packet_seq, i=0, **kwargs):
return self.cosmos_cli(i).pay_packet_fee(
port_id, channel_id, packet_seq, **kwargs
)

def ibc_denom_trace(self, path, node, i=0):
return self.cosmos_cli(i).ibc_denom_trace(path, node)


def start_cluster(data_dir):
cmd = [
Expand Down Expand Up @@ -1190,6 +1211,11 @@ class Relayer(Enum):
RLY = "rly"


class ChannelOrder(Enum):
ORDERED = "ORDER_ORDERED"
UNORDERED = "ORDER_UNORDERED"


def init_cluster(
data_dir,
config_path,
Expand Down
88 changes: 88 additions & 0 deletions pystarport/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,23 @@ def ibc_query_channels(self, connid, **kwargs):
)
)

def ibc_query_channel(self, port_id, channel_id, **kwargs):
default_kwargs = {
"node": self.node_rpc,
"output": "json",
}
return json.loads(
self.raw(
"q",
"ibc",
"channel",
"end",
port_id,
channel_id,
**(default_kwargs | kwargs),
)
)

def ica_register_account(self, connid, event_query_tx=True, **kwargs):
"execute on host chain to attach an account to the connection"
default_kwargs = {
Expand Down Expand Up @@ -1357,3 +1374,74 @@ def ica_generate_packet_data(self, tx, memo=None, encoding="proto3", **kwargs):
**kwargs,
)
)

def ibc_upgrade_channels(self, version, from_addr, **kwargs):
return json.loads(
self.raw(
"tx",
"ibc",
"channel",
"upgrade-channels",
json.dumps(version),
"-y",
"--json",
from_=from_addr,
keyring_backend="test",
chain_id=self.chain_id,
home=self.data_dir,
stderr=subprocess.DEVNULL,
**kwargs,
)
)

def register_counterparty_payee(
self, port_id, channel_id, relayer, counterparty_payee, **kwargs
):
rsp = json.loads(
self.raw(
"tx",
"ibc-fee",
"register-counterparty-payee",
port_id,
channel_id,
relayer,
counterparty_payee,
"-y",
home=self.data_dir,
**kwargs,
)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def pay_packet_fee(self, port_id, channel_id, packet_seq, **kwargs):
rsp = json.loads(
self.raw(
"tx",
"ibc-fee",
"pay-packet-fee",
port_id,
channel_id,
str(packet_seq),
"-y",
home=self.data_dir,
**kwargs,
)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def ibc_denom_trace(self, path, node):
denom_hash = hashlib.sha256(path.encode()).hexdigest().upper()
return json.loads(
self.raw(
"q",
"ibc-transfer",
"denom-trace",
denom_hash,
node=node,
output="json",
)
)["denom_trace"]

0 comments on commit a7dac7f

Please sign in to comment.