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

Feature request: Improve API to retrieve transactions #1594

Open
montyly opened this issue Jan 23, 2020 · 1 comment
Open

Feature request: Improve API to retrieve transactions #1594

montyly opened this issue Jan 23, 2020 · 1 comment

Comments

@montyly
Copy link
Member

montyly commented Jan 23, 2020

A common mistake in our scripts has this pattern:

contract = create[....]
contract.f1(..)
contract.f1(..) // we want to return value here
contract.f1(..)
contract.f1(..)
for state in m.ready_states:

    second_f1_call_transaction = state.platform.transactions[1]

Here state.platform.transactions[1] will not be the second call to f1, but the first. Because the first transactions of the platform will be the contract's deployement.

For complex scripts, that are split through multiple files, it's also more complex to determine what index should be given to state.platform.transactions.

An alternative would be to return an object after the functions calls, like

first_tx = contract.f1(..)

And be able to access the state's related transaction later, either through something like

transaction = state.platform.get_transaction(first_tx)

or

transaction = first_tx.get_transaction(state | state_id)

I see one caveat though, for contract's creation, m.solidity_create_contract already returns an object. I see two solutions:

  • Return a tuple, but that might just overcomplexity the API
  • Not return the tx-object, but have it accessible through the contract (like contract.tx_creation).

Note that here tx is maybe not a good name, as the object will, in fact, refers to the set of transactions for all the states

Any thoughts?

@feliam
Copy link
Contributor

feliam commented Feb 18, 2020

Idea...

contract = create[....]
contract.f1(..)
result_f1_2 = contract.f1(..) // we want to return value here
contract.f1(..)
contract.f1(..)
for state in m.ready_states:
    second_f1_call_transaction = result_f1_2(state)

This will need a way to id human_transactions (maybe just the order) so result_f1_2() function knows in which transaction look for the result and all.

longshot:
result_f1_2 could be of a Result class exploiting some python magic to be permisive in the common case.

class Result():
     def __init__(self, tx_id, returntype, mcore):
        self.mcore=mcore
        self.tx_id = tx_id
        self.returntype = returntype

     def __call__(self, state=None, *args, **kwargs):
        # maybe if state is None check if there is a single state and look for it in self.mcore.ready_states 
        return ABI.deserialize(self.returntype, state.platform.human_transactions[self.tx_id].returndata)

     def __str__(self):
           if 1 == self.mcore.count_ready_states():
               for st in self.mcore.ready_states:
                     return str(self(st))
            return "{symbolic}"


     def __iter__(self):
          for st in self.mcore.ready_states:
              self._current_state=st.id
              yield self(st)

      def current_state(self):
          return self.mcore.load(self._current_state)   

      def count(self):
           return self.mcore.count_ready_states()
contract = create[....]
contract.f1(..)
result_f1_2 = contract.f1(..) // we want to return value here
print (result_f1_2)  #is a single result this prints the right thing
contract.f1(..)
contract.f1(..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants