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

Remove unused method and formating things #33

Merged
merged 1 commit into from
May 13, 2024
Merged
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
95 changes: 59 additions & 36 deletions contracting/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ def run_private_function(self, f, signer=None, environment=None, **kwargs):
f = '{}{}'.format(constants.PRIVATE_METHOD_PREFIX, f)

# Execute
result = self._abstract_function_call(signer=signer, executor=self.executor, contract_name=self.name,
environment=environment, func=f, metering=None, now=None, **kwargs)
result = self._abstract_function_call(
signer=signer,
executor=self.executor,
contract_name=self.name,
environment=environment,
func=f,
metering=None,
now=None,
**kwargs
)

# Set executor back to restricted mode
self.executor.bypass_privates = False
Expand Down Expand Up @@ -137,7 +145,19 @@ def now(self):
d = datetime.today()
return Datetime(d.year, d.month, d.day, hour=d.hour, minute=d.minute)

def _abstract_function_call(self, signer, executor, contract_name, func, environment=None, stamps=constants.DEFAULT_STAMPS, metering=None, now=None, **kwargs):
def _abstract_function_call(
self,
signer,
executor,
contract_name,
func,
environment=None,
stamps=constants.DEFAULT_STAMPS,
metering=None,
now=None,
**kwargs
):

# for k, v in kwargs.items():
# assert v is not None, 'Keyword "{}" not provided. Must not be None.'.format(k)
environment = environment or self.environment
Expand All @@ -148,13 +168,15 @@ def _abstract_function_call(self, signer, executor, contract_name, func, environ
if environment.get('now') is None:
environment.update({'now': now})

output = executor.execute(sender=signer,
contract_name=contract_name,
function_name=func,
kwargs=kwargs,
stamps=stamps,
environment=environment,
metering=metering)
output = executor.execute(
sender=signer,
contract_name=contract_name,
function_name=func,
kwargs=kwargs,
stamps=stamps,
environment=environment,
metering=metering
)

if executor.production:
executor.sandbox.terminate()
Expand All @@ -173,12 +195,15 @@ def _abstract_function_call(self, signer, executor, contract_name, func, environ


class ContractingClient:
def __init__(self, signer='sys',
submission_filename=os.path.join(os.path.dirname(__file__), 'contracts/submission.s.py'),
driver=Driver(),
metering=False,
compiler=ContractingCompiler(),
environment={}):
def __init__(
self,
signer='sys',
submission_filename=os.path.join(os.path.dirname(__file__), 'contracts/submission.s.py'),
driver=Driver(),
metering=False,
compiler=ContractingCompiler(),
environment={}
):

self.executor = Executor(metering=metering, driver=driver)
self.raw_driver = driver
Expand All @@ -193,9 +218,7 @@ def __init__(self, signer='sys',
with open(self.submission_filename) as f:
contract = f.read()

self.raw_driver.set_contract(name='submission',
code=contract)

self.raw_driver.set_contract(name='submission', code=contract)
self.raw_driver.commit()

# Get submission contract from state
Expand All @@ -215,8 +238,8 @@ def set_submission_contract(self, filename=None, commit=True):
contract = f.read()

self.raw_driver.delete_contract(name='submission')
self.raw_driver.set_contract(name='submission',
code=contract)
self.raw_driver.set_contract(name='submission', code=contract)

if commit:
self.raw_driver.commit()

Expand Down Expand Up @@ -248,11 +271,13 @@ def get_contract(self, name):

funcs.append((func_name, kwargs))

return AbstractContract(name=name,
signer=self.signer,
environment=self.environment,
executor=self.executor,
funcs=funcs)
return AbstractContract(
name=name,
signer=self.signer,
environment=self.environment,
executor=self.executor,
funcs=funcs
)

def closure_to_code_string(self, f):
closure_code = inspect.getsource(f)
Expand Down Expand Up @@ -287,14 +312,6 @@ def lint(self, f, raise_errors=False):
else:
return violations

def estimate_stamps(self, contract_name, function_name, kwargs):
simulated = self.executor.simulate(
contract_name=contract_name,
function_name=function_name,
kwargs=kwargs)

return simulated['stamps_used']

def compile(self, f):
if isinstance(f, FunctionType):
f, _ = self.closure_to_code_string(f)
Expand All @@ -316,8 +333,14 @@ def submit(self, f, name=None, metering=None, owner=None, constructor_args={}, s
if signer is None:
signer = self.signer

self.submission_contract.submit_contract(name=name, code=f, owner=owner, constructor_args=constructor_args,
metering=metering, signer=signer)
self.submission_contract.submit_contract(
name=name,
code=f,
owner=owner,
constructor_args=constructor_args,
metering=metering,
signer=signer
)

def get_contracts(self):
contracts = []
Expand Down
Loading