Skip to content

Commit

Permalink
Problem: event_query_tx_for flag is not supported (#111)
Browse files Browse the repository at this point in the history
* Problem: event_query_tx_for flag is not supported

this change should have been included in d808e2b

* fix create_nft
  • Loading branch information
mmsqe authored Jan 4, 2024
1 parent d808e2b commit 1c35155
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
39 changes: 30 additions & 9 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 @@ -587,9 +604,10 @@ def create_nft(
'"image":{"type":"string","description":"testdescription"}}}',
fees=None,
i=0,
event_query_tx=True,
):
return self.cosmos_cli(i).create_nft(
from_addr, denomid, denomname, schema, fees
from_addr, denomid, denomname, schema, fees, event_query_tx,
)

def query_nft(self, denomid="mydenomid", i=0):
Expand Down Expand Up @@ -638,6 +656,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
41 changes: 33 additions & 8 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 @@ -893,7 +904,9 @@ def export(self):
def unsaferesetall(self):
return self.raw("unsafe-reset-all")

def create_nft(self, from_addr, denomid, denomname, schema, fees):
def create_nft(
self, from_addr, denomid, denomname, schema, fees, event_query_tx=True,
):
rsp = json.loads(
self.raw(
"tx",
Expand All @@ -911,7 +924,7 @@ def create_nft(self, from_addr, denomid, denomname, schema, fees):
node=self.node_rpc,
)
)
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 +1055,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,
)
)

0 comments on commit 1c35155

Please sign in to comment.