Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
abi-gen/Py: fix call() return type incl. tx hash
Browse files Browse the repository at this point in the history
Previously, generated wrappers for contract methods were including type
hints that suggested that a call() (as opposed to a send_transaction())
might return either the underlying return type or a transaction hash.
This doesn't make sense because a call() will never return a TX hash.
Now, the type hint just has the return type of the underlying method.
  • Loading branch information
feuGeneA committed Nov 15, 2019
1 parent 99a4794 commit b42d8e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{~#if outputs~}}
{{#if outputs.length}}
{{#singleReturnValue}}
{{#returnType outputs.0.type outputs.0.components}}{{~/returnType~}}
{{/singleReturnValue}}
{{^singleReturnValue}}
Tuple[{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
{{~/singleReturnValue}}
{{else}}None
{{/if}}
{{else}}None{{/if~}}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class {{toPythonClassname this.languageSpecificName}}Method(ContractMethod):
return ({{> params }})

{{/if}}
def call(self, {{#if inputs}}{{> typed_params inputs=inputs}}, {{/if}}tx_params: Optional[TxParams] = None) -> {{> return_type outputs=outputs type='call'~}}:
def call(self, {{#if inputs}}{{> typed_params inputs=inputs}}, {{/if}}tx_params: Optional[TxParams] = None) -> {{> call_return_type outputs=outputs type='call'~}}:
"""Execute underlying contract method via eth_call.
{{sanitizeDevdocDetails this.name this.devdoc.details 8}}{{~#if this.devdoc.params~}}{{#each this.devdoc.params}}
{{makeParameterDocstringRole @key this 8}}{{/each}}{{/if}}
Expand Down
16 changes: 4 additions & 12 deletions packages/abi-gen/test-cli/output/python/abi_gen_dummy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@ def __init__(
super().__init__(web3_or_provider, contract_address, validator)
self.underlying_method = contract_function

def call(
self, tx_params: Optional[TxParams] = None
) -> Union[None, Union[HexBytes, bytes]]:
def call(self, tx_params: Optional[TxParams] = None) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
Expand Down Expand Up @@ -764,9 +762,7 @@ def __init__(
super().__init__(web3_or_provider, contract_address, validator)
self.underlying_method = contract_function

def call(
self, tx_params: Optional[TxParams] = None
) -> Union[int, Union[HexBytes, bytes]]:
def call(self, tx_params: Optional[TxParams] = None) -> int:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
Expand Down Expand Up @@ -810,9 +806,7 @@ def __init__(
super().__init__(web3_or_provider, contract_address, validator)
self.underlying_method = contract_function

def call(
self, tx_params: Optional[TxParams] = None
) -> Union[None, Union[HexBytes, bytes]]:
def call(self, tx_params: Optional[TxParams] = None) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
Expand Down Expand Up @@ -1420,9 +1414,7 @@ def validate_and_normalize_inputs(self, wad: int):
wad = int(wad)
return wad

def call(
self, wad: int, tx_params: Optional[TxParams] = None
) -> Union[None, Union[HexBytes, bytes]]:
def call(self, wad: int, tx_params: Optional[TxParams] = None) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
Expand Down

0 comments on commit b42d8e0

Please sign in to comment.