Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: event_query_tx_for flag is not supported #111

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,19 @@ def staking_pool(self, bonded=True, i=0):
def transfer_offline(self, from_, to, coins, sequence, i=0, fees=None):
return self.cosmos_cli(i).transfer_offline(from_, to, coins, sequence, fees)

def transfer(self, from_, to, coins, i=0, generate_only=False, fees=None):
return self.cosmos_cli(i).transfer(from_, to, coins, generate_only, fees)
def transfer(
self,
from_,
to,
coins,
i=0,
generate_only=False,
fees=None,
event_query_tx=True,
):
return self.cosmos_cli(i).transfer(
from_, to, coins, generate_only, fees, event_query_tx,
)

def transfer_from_ledger(
self, from_, to, coins, i=0, generate_only=False, fees=None
Expand All @@ -426,8 +437,12 @@ def transfer_from_ledger(
def get_delegated_amount(self, which_addr, i=0):
return self.cosmos_cli(i).get_delegated_amount(which_addr)

def delegate_amount(self, to_addr, amount, from_addr, i=0, gas_price=None):
return self.cosmos_cli(i).delegate_amount(to_addr, amount, from_addr, gas_price)
def delegate_amount(
self, to_addr, amount, from_addr, i=0, gas_price=None, event_query_tx=True,
):
return self.cosmos_cli(i).delegate_amount(
to_addr, amount, from_addr, gas_price, event_query_tx,
)

# to_addr: croclcl1... , from_addr: cro1...
def unbond_amount(self, to_addr, amount, from_addr, i=0):
Expand Down Expand Up @@ -543,11 +558,13 @@ def edit_validator(
def gov_propose(self, proposer, kind, proposal, i=0):
return self.cosmos_cli(i).gov_propose(proposer, kind, proposal)

def gov_vote(self, voter, proposal_id, option, i=0):
return self.cosmos_cli(i).gov_vote(voter, proposal_id, option)
def gov_vote(self, voter, proposal_id, option, i=0, event_query_tx=True):
return self.cosmos_cli(i).gov_vote(voter, proposal_id, option, event_query_tx)

def gov_deposit(self, depositor, proposal_id, amount, i=0):
return self.cosmos_cli(i).gov_deposit(depositor, proposal_id, amount)
def gov_deposit(self, depositor, proposal_id, amount, i=0, event_query_tx=True):
return self.cosmos_cli(i).gov_deposit(
depositor, proposal_id, amount, event_query_tx,
)

def query_proposals(self, depositor=None, limit=None, status=None, voter=None, i=0):
return self.cosmos_cli(i).query_proposals(depositor, limit, status, voter)
Expand Down Expand Up @@ -638,6 +655,9 @@ def transfer_nft_token(
from_addr, to_addr, denomid, tokenid
)

def event_query_tx_for(self, hash, i=0):
return self.cosmos_cli(i).event_query_tx_for(hash)


def start_cluster(data_dir):
cmd = [
Expand Down
35 changes: 29 additions & 6 deletions pystarport/cosmoscli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import enum
import hashlib
import json
import subprocess
import tempfile
import threading
import time
Expand Down Expand Up @@ -40,10 +41,10 @@ class ChainCommand:
def __init__(self, cmd=None):
self.cmd = cmd or CHAIN

def __call__(self, cmd, *args, stdin=None, **kwargs):
def __call__(self, cmd, *args, stdin=None, stderr=subprocess.STDOUT, **kwargs):
"execute chain-maind"
args = " ".join(build_cli_args_safe(cmd, *args, **kwargs))
return interact(f"{self.cmd} {args}", input=stdin)
return interact(f"{self.cmd} {args}", input=stdin, stderr=stderr)


class CosmosCLI:
Expand Down Expand Up @@ -325,7 +326,15 @@ def staking_pool(self, bonded=True):
)["bonded_tokens" if bonded else "not_bonded_tokens"]
)

def transfer(self, from_, to, coins, generate_only=False, fees=None):
def transfer(
self,
from_,
to,
coins,
generate_only=False,
fees=None,
event_query_tx=True,
):
rsp = json.loads(
self.raw(
"tx",
Expand All @@ -343,7 +352,7 @@ def transfer(self, from_, to, coins, generate_only=False, fees=None):
fees=fees,
)
)
if not generate_only and rsp["code"] == 0:
if not generate_only and rsp["code"] == 0 and event_query_tx:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

Expand Down Expand Up @@ -400,7 +409,9 @@ def get_delegated_amount(self, which_addr):
)
)

def delegate_amount(self, to_addr, amount, from_addr, gas_price=None):
def delegate_amount(
self, to_addr, amount, from_addr, gas_price=None, event_query_tx=True,
):
rsp = json.loads(
self.raw(
"tx",
Expand All @@ -417,7 +428,7 @@ def delegate_amount(self, to_addr, amount, from_addr, gas_price=None):
gas_prices=gas_price,
)
)
if rsp["code"] == 0:
if rsp["code"] == 0 and event_query_tx:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

Expand Down Expand Up @@ -1042,3 +1053,15 @@ def transfer_nft_token(self, from_addr, to_addr, denomid, tokenid):
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def event_query_tx_for(self, hash):
return json.loads(
self.raw(
"query",
"event-query-tx-for",
hash,
"-y",
home=self.data_dir,
stderr=subprocess.DEVNULL,
)
)
Loading