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

fix pyrgov for latest checkBlance.rho #216

Merged
merged 4 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 10 additions & 3 deletions pyrgov/rgov.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def render_contract_template(template_file: pathlib, substitutions: Mapping[str,
file = template_file.open()
template = file.read()
file.close()
return string.Template(template).substitute(substitutions)
contract = string.Template(template).substitute(substitutions)
return contract

class rgovAPI:

Expand Down Expand Up @@ -109,6 +110,8 @@ def import_shared_private_keys(self) -> Mapping[str, str]:
return keys

def get_private_key(self, name: str) -> PrivateKey:
if name == 'anonymous':
return PrivateKey.generate() # Warning potential Ambient Access, if account is given REV
if name in self.keyVault:
return PrivateKey.from_hex(self.keyVault[name])
reason = 'No key found in vault for ' + name
Expand All @@ -128,10 +131,14 @@ def propose(self) -> None:
def checkBalance(self, rev_addr: str, block_hash: str='') -> int:
contract = render_contract_template(
CHECK_BALANCE_RHO_TPL,
{'addr': rev_addr, 'myBalance': "mybal"},
{'addr': rev_addr, 'myBalance': "mybal",
'rev': "${rev}", 'fraction': "${fraction}", 'num': "${num}"},
)
result = self.client.exploratory_deploy(contract, block_hash)
return result[0].exprs[0].e_list_body.ps[2].exprs[0].g_int
if result[0].exprs[0].HasField("e_list_body"):
return result[0].exprs[0].e_list_body.ps[2].exprs[0].g_int
if result[1].exprs[0].HasField("e_list_body"):
return result[1].exprs[0].e_list_body.ps[2].exprs[0].g_int

def transfer(self, from_addr: str, to_addr: str, amount: int, key: PrivateKey) -> str:
contract = render_contract_template(
Expand Down
7 changes: 5 additions & 2 deletions testing/unit_test/test_balance.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/python3

from rchain.crypto import PrivateKey
from pyrgov.rgov import rgovAPI
import pathlib

if __name__ != pathlib.Path(__file__).stem and __name__ != '__main__':
assert False

rgov = rgovAPI('localhost')
new1 = PrivateKey.generate()
new1 = rgov.get_private_key('anonymous')
admin = rgov.get_private_key('bootstrap')

balance = rgov.checkBalance(new1.get_public_key().get_rev_address())
Expand Down