commit 7cbc4f97f1be5fcecbb3da765691a3c0929e4a7a
parent 64fc16a2a31ee063efc472cf82439aad4768bf85
Author: lash <dev@holbrook.no>
Date: Mon, 8 May 2023 05:26:21 +0100
Implement chainlib-gen
Diffstat:
4 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/python/evm_tokenvote/__init__.py b/python/evm_tokenvote/__init__.py
@@ -1,3 +1,6 @@
from .voter import Voter
from .voter import Proposal
from .voter import ProposalState
+from .voter import bytecode
+from .voter import create
+from .voter import args
diff --git a/python/evm_tokenvote/data/.chainlib b/python/evm_tokenvote/data/.chainlib
diff --git a/python/evm_tokenvote/unittest/base.py b/python/evm_tokenvote/unittest/base.py
@@ -118,7 +118,7 @@ class TestEvmVoteRegistry(TestEvmVoteAccounts):
self.assertEqual(r['status'], 1)
c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash, o) = c.constructor(self.accounts[0], self.token_address, voter_registry_address=self.registry_address, proposer_registry_address=self.proposer_registry_address)
+ (tx_hash, o) = c.constructor(self.accounts[0], self.token_address, voter_registry=self.registry_address, proposer_registry=self.proposer_registry_address)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
diff --git a/python/evm_tokenvote/voter.py b/python/evm_tokenvote/voter.py
@@ -64,27 +64,27 @@ class Voter(TxFactory):
__abi = None
__bytecode = None
- def constructor(self, sender_address, token_address, protect_supply=False, voter_registry_address=None, proposer_registry_address=None, tx_format=TxFormat.JSONRPC, version=None):
- code = self.cargs(token_address, protect_supply=protect_supply, voter_registry_address=voter_registry_address, proposer_registry_address=proposer_registry_address, version=version)
+ def constructor(self, sender_address, token_address, protect_supply=False, voter_registry=None, proposer_registry=None, tx_format=TxFormat.JSONRPC, version=None):
+ code = self.cargs(token_address, protect_supply=protect_supply, voter_registry=voter_registry, proposer_registry=proposer_registry, version=version)
tx = self.template(sender_address, None, use_nonce=True)
tx = self.set_code(tx, code)
return self.finalize(tx, tx_format)
@staticmethod
- def cargs(token_address, protect_supply=False, voter_registry_address=None, proposer_registry_address=None, version=None):
- if voter_registry_address == None:
- voter_registry_address = ZERO_ADDRESS
- if proposer_registry_address == None:
- proposer_registry_address = ZERO_ADDRESS
+ def cargs(token_address, protect_supply=False, voter_registry=None, proposer_registry=None, version=None):
+ if voter_registry == None:
+ voter_registry = ZERO_ADDRESS
+ if proposer_registry == None:
+ proposer_registry = ZERO_ADDRESS
if token_address == None:
raise ValueError("token address cannot be zero address")
code = Voter.bytecode(version=version)
enc = ABIContractEncoder()
enc.address(token_address)
enc.bool(protect_supply)
- enc.address(voter_registry_address)
- enc.address(proposer_registry_address)
+ enc.address(voter_registry)
+ enc.address(proposer_registry)
args = enc.get()
code += args
logg.debug('constructor code: ' + args)
@@ -344,3 +344,19 @@ class Voter(TxFactory):
serial=serial,
)
return o
+
+
+def bytecode(**kwargs):
+ return Voter.bytecode(version=kwargs.get('version'))
+
+
+def create(**kwargs):
+ return Voter.cargs(kwargs['token_address'], protect_supply=kwargs.get('protect_supply'), voter_registry=kwargs.get('voter_registry'), proposer_registry=kwargs.get('proposer_registry'), version=kwargs.get('version'))
+
+
+def args(v):
+ if v == 'create':
+ return (['token_address'], ['protect_supply', 'voter_registry', 'propose_registry'],)
+ elif v == 'default' or v == 'bytecode':
+ return ([], ['version'],)
+ raise ValueError('unknown command: ' + v)