Skip to content

Commit

Permalink
fix distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jul 18, 2024
1 parent 491859e commit e8eed1c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 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 re
import subprocess
import tempfile
import threading
Expand Down Expand Up @@ -249,7 +250,7 @@ def query_all_txs(self, addr):
return json.loads(txs)

def distribution_commission(self, addr):
coin = json.loads(
res = json.loads(
self.raw(
"query",
"distribution",
Expand All @@ -258,23 +259,27 @@ def distribution_commission(self, addr):
output="json",
node=self.node_rpc,
)
)["commission"][0]
return float(coin["amount"])
)["commission"]
coin = (res.get("commission") or res)[0]
amt = re.search(r"\d+\.?\d*", coin)
return float(amt.group()) if amt else 0.0

def distribution_community(self):
coin = json.loads(
res = json.loads(
self.raw(
"query",
"distribution",
"community-pool",
output="json",
node=self.node_rpc,
)
)["pool"][0]
return float(coin["amount"])
)
coin = res["pool"][0]
amt = re.search(r"\d+\.?\d*", coin)
return float(amt.group()) if amt else 0.0

def distribution_reward(self, delegator_addr):
coin = json.loads(
res = json.loads(
self.raw(
"query",
"distribution",
Expand All @@ -283,8 +288,10 @@ def distribution_reward(self, delegator_addr):
output="json",
node=self.node_rpc,
)
)["total"][0]
return float(coin["amount"])
)
coin = res["total"][0]
amt = re.search(r"\d+\.?\d*", coin)
return float(amt.group()) if amt else 0.0

def address(self, name, bech="acc"):
output = self.raw(
Expand Down Expand Up @@ -331,9 +338,10 @@ def validators(self):
)["validators"]

def staking_params(self):
return json.loads(
res = json.loads(
self.raw("query", "staking", "params", output="json", node=self.node_rpc)
)
return res.get("params") or res

def staking_pool(self, bonded=True):
res = self.raw("query", "staking", "pool", output="json", node=self.node_rpc)
Expand Down

0 comments on commit e8eed1c

Please sign in to comment.