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

Replace ConciseContract with ContractCaller #1025

Closed
dylanjw opened this issue Aug 28, 2018 · 8 comments
Closed

Replace ConciseContract with ContractCaller #1025

dylanjw opened this issue Aug 28, 2018 · 8 comments

Comments

@dylanjw
Copy link
Contributor

dylanjw commented Aug 28, 2018

ConciseContract shouldn't be a factory, it should be it's own calling API. meta-tracking in #722

How can it be fixed?

Add deprecation warning to ConciseContract and ImplicitContract. Add a new api: ContractReader.

one proposed api:

contract = w3.eth.contract(address, abi=abi)
reader = contract.reader({'from': caller_addr, ...})  # essentially ConciseContract(contract) with sugar
reader.balanceOf(address)  # or whatever call you want to make

Note that there will be internal breakage when removing ConciseContract, notably in the ens module. So part of this change will be updating ENS to use the new reader API. Brief discussion at #1118 (comment)

@Exef
Copy link
Contributor

Exef commented Aug 30, 2018

Should ContractReader have access to ContractEvents? In my opinion - yes, because events are also part of reading contract data from blockchain.

@carver
Copy link
Collaborator

carver commented Aug 30, 2018

Hm, I'm not sure we'd be making the events API any easier to call. Maybe name it ContractCaller for semantic alignment?

@dylanjw dylanjw changed the title Replace ConciseContract with ContractReader Replace ConciseContract with ContractCaller Aug 30, 2018
@dylanjw
Copy link
Contributor Author

dylanjw commented Aug 30, 2018

I like ContractCaller. So the idea is that ContractCaller can only make calls, and removing the ability to use modifiers to make transactions or estimate gas.

For example, this would not be possible:

contract.withdraw(amount, transact={'from': eth.accounts[1], 'gas': 100000, ...})

I was confused by the name ContractReader, which I thought could be an api to read public variables.

@pipermerriam
Copy link
Member

for @kclowes

contract.reader.getThing()

@carver
Copy link
Collaborator

carver commented Nov 12, 2018

Note that's a slight change from the API in the OP: contract.reader(transaction_dict).getThing(). (where transaction_dict has fields like from, gas, gasPrice, etc that can affect the function call.

I think I like the OP API better, but highly open to persuasion or alternatives

@pipermerriam
Copy link
Member

pipermerriam commented Nov 12, 2018

@carver I'm inclined to do something like this.

  • contract.reader.getThing()
    • equivalent to contract.functions.getThing().call()
  • contract.reader(transaction_dict).getThing()
    • equivalent to contract.functions.getThing().call(transaction_dict)

And maybe to alias contract.r to contract.reader for convenience.

@carver
Copy link
Collaborator

carver commented Nov 12, 2018

The non-parenthetical API option looks good to me. 👍


One-letter variables would be super out-of-character for the tool suite.

I think I could get behind it (same for f for functions, etc), but then I would probably want to have a big warning in the docs saying something like "These aliases are intended for 'quick-and-dirty' usage at a terminal, it's highly discouraged to use in production code. Use the full names instead".

... or maybe just not have the alias. Maybe we could shorten reader to read or have it be get instead?

@pipermerriam
Copy link
Member

Lets just leave out the alias.

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

No branches or pull requests

5 participants