Skip to content

Commit

Permalink
Move validate_payable check to lower level bse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-maverick committed Sep 16, 2018
1 parent deb5806 commit 130e786
Showing 1 changed file with 23 additions and 41 deletions.
64 changes: 23 additions & 41 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,6 @@ def estimateGas(self, transaction=None):

class Caller:
def __getattr__(self, function_name):
function_abi = get_function_abi_from_contract_abi(
contract.abi,
function_name
)
validate_payable(estimate_transaction, function_abi)

callable_fn = functools.partial(
estimate_gas_for_function,
contract.address,
Expand Down Expand Up @@ -511,12 +505,6 @@ def call(self, transaction=None):

class Caller:
def __getattr__(self, function_name):
function_abi = get_function_abi_from_contract_abi(
contract.abi,
function_name
)
validate_payable(call_transaction, function_abi)

callable_fn = functools.partial(
call_contract_function,
contract.web3,
Expand Down Expand Up @@ -602,12 +590,6 @@ def transact(self, transaction=None):

class Transactor:
def __getattr__(self, function_name):
function_abi = get_function_abi_from_contract_abi(
contract.abi,
function_name
)
validate_payable(transact_transaction, function_abi)

callable_fn = functools.partial(
transact_with_contract_function,
contract.address,
Expand Down Expand Up @@ -655,12 +637,6 @@ def buildTransaction(self, transaction=None):

class Caller:
def __getattr__(self, function_name):
function_abi = get_function_abi_from_contract_abi(
contract.abi,
function_name
)
validate_payable(built_transaction, function_abi)

callable_fn = functools.partial(
build_transaction_for_function,
contract.address,
Expand Down Expand Up @@ -1131,8 +1107,6 @@ def call(self, transaction=None, block_identifier='latest'):
"Please ensure that this contract instance has an address."
)

validate_payable(call_transaction, self.abi)

block_id = parse_block_identifier(self.web3, block_identifier)

return call_contract_function(
Expand Down Expand Up @@ -1173,8 +1147,6 @@ def transact(self, transaction=None):
"Please ensure that this contract instance has an address."
)

validate_payable(transact_transaction, self.abi)

return transact_with_contract_function(
self.address,
self.web3,
Expand Down Expand Up @@ -1213,8 +1185,6 @@ def estimateGas(self, transaction=None):
"Please ensure that this contract instance has an address."
)

validate_payable(estimate_gas_transaction, self.abi)

return estimate_gas_for_function(
self.address,
self.web3,
Expand Down Expand Up @@ -1254,8 +1224,6 @@ def buildTransaction(self, transaction=None):
"Please ensure that this contract instance has an address."
)

validate_payable(built_transaction, self.abi)

return build_transaction_for_function(
self.address,
self.web3,
Expand Down Expand Up @@ -1386,6 +1354,11 @@ def call_contract_function(
Helper function for interacting with a contract function using the
`eth_call` API.
"""
if fn_abi is None:
fn_abi = find_matching_fn_abi(contract_abi, function_identifier, args, kwargs)

validate_payable(transaction, fn_abi)

call_transaction = prepare_transaction(
address,
web3,
Expand All @@ -1402,9 +1375,6 @@ def call_contract_function(
else:
return_data = web3.eth.call(call_transaction, block_identifier=block_id)

if fn_abi is None:
fn_abi = find_matching_fn_abi(contract_abi, function_identifier, args, kwargs)

output_types = get_abi_output_types(fn_abi)

try:
Expand Down Expand Up @@ -1479,6 +1449,12 @@ def transact_with_contract_function(
Helper function for interacting with a contract function by sending a
transaction.
"""

if fn_abi is None:
fn_abi = find_matching_fn_abi(contract_abi, function_name, args, kwargs)

validate_payable(transaction, fn_abi)

transact_transaction = prepare_transaction(
address,
web3,
Expand Down Expand Up @@ -1508,6 +1484,12 @@ def estimate_gas_for_function(
Don't call this directly, instead use :meth:`Contract.estimateGas`
on your contract instance.
"""

if fn_abi is None:
fn_abi = find_matching_fn_abi(contract_abi, fn_identifier, args, kwargs)

validate_payable(transaction, fn_abi)

estimate_transaction = prepare_transaction(
address,
web3,
Expand Down Expand Up @@ -1537,6 +1519,12 @@ def build_transaction_for_function(
Don't call this directly, instead use :meth:`Contract.buildTransaction`
on your contract instance.
"""

if fn_abi is None:
fn_abi = find_matching_fn_abi(contract_abi, function_name, args, kwargs)

validate_payable(transaction, fn_abi)

prepared_transaction = prepare_transaction(
address,
web3,
Expand Down Expand Up @@ -1594,9 +1582,3 @@ def validate_payable(transaction, abi):
"with payable=False. Please ensure that "
"transaction's value is 0."
)


def get_function_abi_from_contract_abi(contract_abi, function_name):
for abi in contract_abi:
if abi['name'] == function_name:
return abi

0 comments on commit 130e786

Please sign in to comment.