Module moody.m.ori20
Generated wrapper for Ori20 Solidity contract.
Expand source code
"""Generated wrapper for Ori20 Solidity contract."""
# pylint: disable=too-many-arguments
import json
import time
from typing import ( # pylint: disable=unused-import
Optional,
Tuple,
Union,
)
from eth_utils import to_checksum_address
from hexbytes import HexBytes
from web3.contract import ContractFunction
from web3.datastructures import AttributeDict
from web3.exceptions import ContractLogicError
from moody import Bolors
from moody.libeb import MiliDoS
from moody.m.bases import ContractMethod, Validator, ContractBase
from moody.m.tx_params import TxParams
# Try to import a custom validator class definition; if there isn't one,
# declare one that we can instantiate for the default argument to the
# constructor for Ori20 below.
try:
# both mypy and pylint complain about what we're doing here, but this
# works just fine, so their messages have been disabled here.
from . import ( # type: ignore # pylint: disable=import-self
Ori20Validator,
)
except ImportError:
class Ori20Validator( # type: ignore
Validator
):
"""No-op input validator."""
try:
from .middleware import MIDDLEWARE # type: ignore
except ImportError:
pass
class AddMinterMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the addMinter method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, account: str) -> any:
"""Validate the inputs to the addMinter method."""
self.validator.assert_valid(
method_name='addMinter',
parameter_name='account',
argument_value=account,
)
account = self.validate_and_checksum_address(account)
return (account)
def block_send(self, account: str, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(account)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -add_minter")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: add_minter")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(account) = self.validate_and_normalize_inputs(account)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account).transact(tx_params.as_dict())
def build_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(account) = self.validate_and_normalize_inputs(account)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account).buildTransaction(tx_params.as_dict())
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(account) = self.validate_and_normalize_inputs(account)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account).estimateGas(tx_params.as_dict())
class AllowanceMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the allowance method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, owner: str, spender: str) -> any:
"""Validate the inputs to the allowance method."""
self.validator.assert_valid(
method_name='allowance',
parameter_name='owner',
argument_value=owner,
)
owner = self.validate_and_checksum_address(owner)
self.validator.assert_valid(
method_name='allowance',
parameter_name='spender',
argument_value=spender,
)
spender = self.validate_and_checksum_address(spender)
return (owner, spender)
def block_call(self, owner: str, spender: str, debug: bool = False) -> int:
_fn = self._underlying_method(owner, spender)
returned = _fn.call({
'from': self._operate
})
return int(returned)
def estimate_gas(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(owner, spender) = self.validate_and_normalize_inputs(owner, spender)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(owner, spender).estimateGas(tx_params.as_dict())
class ApproveMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the approve method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, spender: str, amount: int) -> any:
"""Validate the inputs to the approve method."""
self.validator.assert_valid(
method_name='approve',
parameter_name='spender',
argument_value=spender,
)
spender = self.validate_and_checksum_address(spender)
self.validator.assert_valid(
method_name='approve',
parameter_name='amount',
argument_value=amount,
)
# safeguard against fractional inputs
amount = int(amount)
return (spender, amount)
def block_send(self, spender: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(spender, amount)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -approve")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: approve")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, amount).transact(tx_params.as_dict())
def build_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, amount).estimateGas(tx_params.as_dict())
class BalanceOfMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the balanceOf method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, account: str) -> any:
"""Validate the inputs to the balanceOf method."""
self.validator.assert_valid(
method_name='balanceOf',
parameter_name='account',
argument_value=account,
)
account = self.validate_and_checksum_address(account)
return (account)
def block_call(self, account: str, debug: bool = False) -> int:
_fn = self._underlying_method(account)
returned = _fn.call({
'from': self._operate
})
return int(returned)
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(account) = self.validate_and_normalize_inputs(account)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account).estimateGas(tx_params.as_dict())
class BurnMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the burn method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, amount: int) -> any:
"""Validate the inputs to the burn method."""
self.validator.assert_valid(
method_name='burn',
parameter_name='amount',
argument_value=amount,
)
# safeguard against fractional inputs
amount = int(amount)
return (amount)
def block_send(self, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(amount)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -burn")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: burn")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(amount) = self.validate_and_normalize_inputs(amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(amount).transact(tx_params.as_dict())
def build_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(amount) = self.validate_and_normalize_inputs(amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, amount: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(amount) = self.validate_and_normalize_inputs(amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(amount).estimateGas(tx_params.as_dict())
class BurnFromMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the burnFrom method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, account: str, amount: int) -> any:
"""Validate the inputs to the burnFrom method."""
self.validator.assert_valid(
method_name='burnFrom',
parameter_name='account',
argument_value=account,
)
account = self.validate_and_checksum_address(account)
self.validator.assert_valid(
method_name='burnFrom',
parameter_name='amount',
argument_value=amount,
)
# safeguard against fractional inputs
amount = int(amount)
return (account, amount)
def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(account, amount)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -burn_from")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: burn_from")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(account, amount) = self.validate_and_normalize_inputs(account, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account, amount).transact(tx_params.as_dict())
def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(account, amount) = self.validate_and_normalize_inputs(account, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(account, amount) = self.validate_and_normalize_inputs(account, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account, amount).estimateGas(tx_params.as_dict())
class CapMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the cap method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> int:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return int(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class DecimalsMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the decimals method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> int:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return int(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class DecreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the decreaseAllowance method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, spender: str, subtracted_value: int) -> any:
"""Validate the inputs to the decreaseAllowance method."""
self.validator.assert_valid(
method_name='decreaseAllowance',
parameter_name='spender',
argument_value=spender,
)
spender = self.validate_and_checksum_address(spender)
self.validator.assert_valid(
method_name='decreaseAllowance',
parameter_name='subtractedValue',
argument_value=subtracted_value,
)
# safeguard against fractional inputs
subtracted_value = int(subtracted_value)
return (spender, subtracted_value)
def block_send(self, spender: str, subtracted_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(spender, subtracted_value)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -decrease_allowance")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: decrease_allowance")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, subtracted_value).transact(tx_params.as_dict())
def build_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, subtracted_value).buildTransaction(tx_params.as_dict())
def estimate_gas(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, subtracted_value).estimateGas(tx_params.as_dict())
class GetDecimalsMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the getDecimals method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> int:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return int(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class IncreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the increaseAllowance method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, spender: str, added_value: int) -> any:
"""Validate the inputs to the increaseAllowance method."""
self.validator.assert_valid(
method_name='increaseAllowance',
parameter_name='spender',
argument_value=spender,
)
spender = self.validate_and_checksum_address(spender)
self.validator.assert_valid(
method_name='increaseAllowance',
parameter_name='addedValue',
argument_value=added_value,
)
# safeguard against fractional inputs
added_value = int(added_value)
return (spender, added_value)
def block_send(self, spender: str, added_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(spender, added_value)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -increase_allowance")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: increase_allowance")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, added_value).transact(tx_params.as_dict())
def build_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, added_value).buildTransaction(tx_params.as_dict())
def estimate_gas(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(spender, added_value).estimateGas(tx_params.as_dict())
class IsMinterMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the isMinter method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, account: str) -> any:
"""Validate the inputs to the isMinter method."""
self.validator.assert_valid(
method_name='isMinter',
parameter_name='account',
argument_value=account,
)
account = self.validate_and_checksum_address(account)
return (account)
def block_call(self, account: str, debug: bool = False) -> bool:
_fn = self._underlying_method(account)
returned = _fn.call({
'from': self._operate
})
return bool(returned)
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(account) = self.validate_and_normalize_inputs(account)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account).estimateGas(tx_params.as_dict())
class MintMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the mint method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, account: str, amount: int) -> any:
"""Validate the inputs to the mint method."""
self.validator.assert_valid(
method_name='mint',
parameter_name='account',
argument_value=account,
)
account = self.validate_and_checksum_address(account)
self.validator.assert_valid(
method_name='mint',
parameter_name='amount',
argument_value=amount,
)
# safeguard against fractional inputs
amount = int(amount)
return (account, amount)
def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(account, amount)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -mint")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: mint")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(account, amount) = self.validate_and_normalize_inputs(account, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account, amount).transact(tx_params.as_dict())
def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(account, amount) = self.validate_and_normalize_inputs(account, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(account, amount) = self.validate_and_normalize_inputs(account, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(account, amount).estimateGas(tx_params.as_dict())
class NameMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the name method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> str:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return str(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class RenounceMinterMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the renounceMinter method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_send(self, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method()
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -renounce_minter")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: renounce_minter")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().transact(tx_params.as_dict())
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().buildTransaction(tx_params.as_dict())
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class SymbolMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the symbol method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> str:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return str(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class TokenNameMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the tokenName method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> str:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return str(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class TokenSymbolMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the tokenSymbol method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> str:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return str(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class TotalSupplyMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the totalSupply method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction):
"""Persist instance data."""
super().__init__(elib, contract_address)
self._underlying_method = contract_function
def block_call(self, debug: bool = False) -> int:
_fn = self._underlying_method()
returned = _fn.call({
'from': self._operate
})
return int(returned)
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method().estimateGas(tx_params.as_dict())
class TransferMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the transfer method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, recipient: str, amount: int) -> any:
"""Validate the inputs to the transfer method."""
self.validator.assert_valid(
method_name='transfer',
parameter_name='recipient',
argument_value=recipient,
)
recipient = self.validate_and_checksum_address(recipient)
self.validator.assert_valid(
method_name='transfer',
parameter_name='amount',
argument_value=amount,
)
# safeguard against fractional inputs
amount = int(amount)
return (recipient, amount)
def block_send(self, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(recipient, amount)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -transfer")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: transfer")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(recipient, amount).transact(tx_params.as_dict())
def build_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(recipient, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(recipient, amount).estimateGas(tx_params.as_dict())
class TransferFromMethod(ContractMethod): # pylint: disable=invalid-name
"""Various interfaces to the transferFrom method."""
def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None):
"""Persist instance data."""
super().__init__(elib, contract_address, validator)
self._underlying_method = contract_function
def validate_and_normalize_inputs(self, sender: str, recipient: str, amount: int) -> any:
"""Validate the inputs to the transferFrom method."""
self.validator.assert_valid(
method_name='transferFrom',
parameter_name='sender',
argument_value=sender,
)
sender = self.validate_and_checksum_address(sender)
self.validator.assert_valid(
method_name='transferFrom',
parameter_name='recipient',
argument_value=recipient,
)
recipient = self.validate_and_checksum_address(recipient)
self.validator.assert_valid(
method_name='transferFrom',
parameter_name='amount',
argument_value=amount,
)
# safeguard against fractional inputs
amount = int(amount)
return (sender, recipient, amount)
def block_send(self, sender: str, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool:
"""Execute underlying contract method via eth_call.
:param tx_params: transaction parameters
:returns: the return value of the underlying method.
"""
_fn = self._underlying_method(sender, recipient, amount)
try:
_t = _fn.buildTransaction({
'from': self._operate,
'gas': gas,
'gasPrice': price
})
_t['nonce'] = self._web3_eth.getTransactionCount(self._operate)
if val > 0:
_t['value'] = val
if debug:
print(f"======== Signing ✅ by {self._operate}")
print(f"======== Transaction ✅ check")
print(_t)
if 'data' in _t:
signed = self._web3_eth.account.sign_transaction(_t)
txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = None
if receiptListen is True:
print("======== awaiting Confirmation 🚸️ -transfer_from")
tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash)
if debug:
print("======== TX Result ✅")
print(tx_receipt)
print(f"======== TX blockHash ✅")
if receiptListen is True and tx_receipt is not None:
print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}")
else:
print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}")
if receiptListen is False:
time.sleep(self._wait)
except ContractLogicError as er:
print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: transfer_from")
except ValueError as err:
if "message" in err.args[0]:
message = err.args[0]["message"]
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}")
else:
print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def send_transaction(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
"""Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
"""
(sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(sender, recipient, amount).transact(tx_params.as_dict())
def build_transaction(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
"""Construct calldata to be used as input to the method."""
(sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(sender, recipient, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
"""Estimate gas consumption of method call."""
(sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount)
tx_params = super().normalize_tx_params(tx_params)
return self._underlying_method(sender, recipient, amount).estimateGas(tx_params.as_dict())
class SignatureGenerator:
_function_signatures = {}
def __init__(self, abi: any):
for func in [obj for obj in abi if obj['type'] == 'function']:
name = func['name']
types = [input['type'] for input in func['inputs']]
self._function_signatures[name] = '{}({})'.format(name, ','.join(types))
def add_minter(self) -> str:
return self._function_signatures["addMinter"]
def allowance(self) -> str:
return self._function_signatures["allowance"]
def approve(self) -> str:
return self._function_signatures["approve"]
def balance_of(self) -> str:
return self._function_signatures["balanceOf"]
def burn(self) -> str:
return self._function_signatures["burn"]
def burn_from(self) -> str:
return self._function_signatures["burnFrom"]
def cap(self) -> str:
return self._function_signatures["cap"]
def decimals(self) -> str:
return self._function_signatures["decimals"]
def decrease_allowance(self) -> str:
return self._function_signatures["decreaseAllowance"]
def get_decimals(self) -> str:
return self._function_signatures["getDecimals"]
def increase_allowance(self) -> str:
return self._function_signatures["increaseAllowance"]
def is_minter(self) -> str:
return self._function_signatures["isMinter"]
def mint(self) -> str:
return self._function_signatures["mint"]
def name(self) -> str:
return self._function_signatures["name"]
def renounce_minter(self) -> str:
return self._function_signatures["renounceMinter"]
def symbol(self) -> str:
return self._function_signatures["symbol"]
def token_name(self) -> str:
return self._function_signatures["tokenName"]
def token_symbol(self) -> str:
return self._function_signatures["tokenSymbol"]
def total_supply(self) -> str:
return self._function_signatures["totalSupply"]
def transfer(self) -> str:
return self._function_signatures["transfer"]
def transfer_from(self) -> str:
return self._function_signatures["transferFrom"]
# pylint: disable=too-many-public-methods,too-many-instance-attributes
class Ori20(ContractBase):
"""Wrapper class for Ori20 Solidity contract."""
_fn_add_minter: AddMinterMethod
"""Constructor-initialized instance of
:class:`AddMinterMethod`.
"""
_fn_allowance: AllowanceMethod
"""Constructor-initialized instance of
:class:`AllowanceMethod`.
"""
_fn_approve: ApproveMethod
"""Constructor-initialized instance of
:class:`ApproveMethod`.
"""
_fn_balance_of: BalanceOfMethod
"""Constructor-initialized instance of
:class:`BalanceOfMethod`.
"""
_fn_burn: BurnMethod
"""Constructor-initialized instance of
:class:`BurnMethod`.
"""
_fn_burn_from: BurnFromMethod
"""Constructor-initialized instance of
:class:`BurnFromMethod`.
"""
_fn_cap: CapMethod
"""Constructor-initialized instance of
:class:`CapMethod`.
"""
_fn_decimals: DecimalsMethod
"""Constructor-initialized instance of
:class:`DecimalsMethod`.
"""
_fn_decrease_allowance: DecreaseAllowanceMethod
"""Constructor-initialized instance of
:class:`DecreaseAllowanceMethod`.
"""
_fn_get_decimals: GetDecimalsMethod
"""Constructor-initialized instance of
:class:`GetDecimalsMethod`.
"""
_fn_increase_allowance: IncreaseAllowanceMethod
"""Constructor-initialized instance of
:class:`IncreaseAllowanceMethod`.
"""
_fn_is_minter: IsMinterMethod
"""Constructor-initialized instance of
:class:`IsMinterMethod`.
"""
_fn_mint: MintMethod
"""Constructor-initialized instance of
:class:`MintMethod`.
"""
_fn_name: NameMethod
"""Constructor-initialized instance of
:class:`NameMethod`.
"""
_fn_renounce_minter: RenounceMinterMethod
"""Constructor-initialized instance of
:class:`RenounceMinterMethod`.
"""
_fn_symbol: SymbolMethod
"""Constructor-initialized instance of
:class:`SymbolMethod`.
"""
_fn_token_name: TokenNameMethod
"""Constructor-initialized instance of
:class:`TokenNameMethod`.
"""
_fn_token_symbol: TokenSymbolMethod
"""Constructor-initialized instance of
:class:`TokenSymbolMethod`.
"""
_fn_total_supply: TotalSupplyMethod
"""Constructor-initialized instance of
:class:`TotalSupplyMethod`.
"""
_fn_transfer: TransferMethod
"""Constructor-initialized instance of
:class:`TransferMethod`.
"""
_fn_transfer_from: TransferFromMethod
"""Constructor-initialized instance of
:class:`TransferFromMethod`.
"""
def __init__(
self,
core_lib: MiliDoS,
contract_address: str,
validator: Ori20Validator = None,
):
"""Get an instance of wrapper for smart contract.
"""
# pylint: disable=too-many-statements
super().__init__()
self.contract_address = contract_address
web3 = core_lib.w3
if not validator:
validator = Ori20Validator(web3, contract_address)
# if any middleware was imported, inject it
try:
MIDDLEWARE
except NameError:
pass
else:
try:
for middleware in MIDDLEWARE:
web3.middleware_onion.inject(
middleware['function'], layer=middleware['layer'],
)
except ValueError as value_error:
if value_error.args == ("You can't add the same un-named instance twice",):
pass
self._web3_eth = web3.eth
functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=Ori20.abi()).functions
self.SIGNATURES = SignatureGenerator(Ori20.abi())
self._fn_add_minter = AddMinterMethod(core_lib, contract_address, functions.addMinter, validator)
self._fn_allowance = AllowanceMethod(core_lib, contract_address, functions.allowance, validator)
self._fn_approve = ApproveMethod(core_lib, contract_address, functions.approve, validator)
self._fn_balance_of = BalanceOfMethod(core_lib, contract_address, functions.balanceOf, validator)
self._fn_burn = BurnMethod(core_lib, contract_address, functions.burn, validator)
self._fn_burn_from = BurnFromMethod(core_lib, contract_address, functions.burnFrom, validator)
self._fn_cap = CapMethod(core_lib, contract_address, functions.cap)
self._fn_decimals = DecimalsMethod(core_lib, contract_address, functions.decimals)
self._fn_decrease_allowance = DecreaseAllowanceMethod(core_lib, contract_address, functions.decreaseAllowance, validator)
self._fn_get_decimals = GetDecimalsMethod(core_lib, contract_address, functions.getDecimals)
self._fn_increase_allowance = IncreaseAllowanceMethod(core_lib, contract_address, functions.increaseAllowance, validator)
self._fn_is_minter = IsMinterMethod(core_lib, contract_address, functions.isMinter, validator)
self._fn_mint = MintMethod(core_lib, contract_address, functions.mint, validator)
self._fn_name = NameMethod(core_lib, contract_address, functions.name)
self._fn_renounce_minter = RenounceMinterMethod(core_lib, contract_address, functions.renounceMinter)
self._fn_symbol = SymbolMethod(core_lib, contract_address, functions.symbol)
self._fn_token_name = TokenNameMethod(core_lib, contract_address, functions.tokenName)
self._fn_token_symbol = TokenSymbolMethod(core_lib, contract_address, functions.tokenSymbol)
self._fn_total_supply = TotalSupplyMethod(core_lib, contract_address, functions.totalSupply)
self._fn_transfer = TransferMethod(core_lib, contract_address, functions.transfer, validator)
self._fn_transfer_from = TransferFromMethod(core_lib, contract_address, functions.transferFrom, validator)
def event_approval(
self, tx_hash: Union[HexBytes, bytes]
) -> Tuple[AttributeDict]:
"""
Implementation of event approval in contract Ori20
Get log entry for Approval event.
:param tx_hash: hash of transaction emitting Approval event
"""
tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash)
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.Approval().processReceipt(tx_receipt)
def event_minter_added(
self, tx_hash: Union[HexBytes, bytes]
) -> Tuple[AttributeDict]:
"""
Implementation of event minter_added in contract Ori20
Get log entry for MinterAdded event.
:param tx_hash: hash of transaction emitting MinterAdded event
"""
tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash)
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.MinterAdded().processReceipt(tx_receipt)
def event_minter_removed(
self, tx_hash: Union[HexBytes, bytes]
) -> Tuple[AttributeDict]:
"""
Implementation of event minter_removed in contract Ori20
Get log entry for MinterRemoved event.
:param tx_hash: hash of transaction emitting MinterRemoved event
"""
tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash)
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.MinterRemoved().processReceipt(tx_receipt)
def event_transfer(
self, tx_hash: Union[HexBytes, bytes]
) -> Tuple[AttributeDict]:
"""
Implementation of event transfer in contract Ori20
Get log entry for Transfer event.
:param tx_hash: hash of transaction emitting Transfer event
"""
tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash)
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.Transfer().processReceipt(tx_receipt)
def add_minter(self, account: str) -> None:
"""
Implementation of add_minter in contract Ori20
Method of the function
"""
return self._fn_add_minter.block_send(account, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def allowance(self, owner: str, spender: str) -> int:
"""
Implementation of allowance in contract Ori20
Method of the function
"""
return self._fn_allowance.block_call(owner, spender)
def approve(self, spender: str, amount: int) -> bool:
"""
Implementation of approve in contract Ori20
Method of the function
"""
return self._fn_approve.block_send(spender, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def balance_of(self, account: str) -> int:
"""
Implementation of balance_of in contract Ori20
Method of the function
"""
return self._fn_balance_of.block_call(account)
def burn(self, amount: int) -> None:
"""
Implementation of burn in contract Ori20
Method of the function
"""
return self._fn_burn.block_send(amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def burn_from(self, account: str, amount: int) -> None:
"""
Implementation of burn_from in contract Ori20
Method of the function
"""
return self._fn_burn_from.block_send(account, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def cap(self) -> int:
"""
Implementation of cap in contract Ori20
Method of the function
"""
return self._fn_cap.block_call()
def decimals(self) -> int:
"""
Implementation of decimals in contract Ori20
Method of the function
"""
return self._fn_decimals.block_call()
def decrease_allowance(self, spender: str, subtracted_value: int) -> bool:
"""
Implementation of decrease_allowance in contract Ori20
Method of the function
"""
return self._fn_decrease_allowance.block_send(spender, subtracted_value, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def get_decimals(self) -> int:
"""
Implementation of get_decimals in contract Ori20
Method of the function
"""
return self._fn_get_decimals.block_call()
def increase_allowance(self, spender: str, added_value: int) -> bool:
"""
Implementation of increase_allowance in contract Ori20
Method of the function
"""
return self._fn_increase_allowance.block_send(spender, added_value, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def is_minter(self, account: str) -> bool:
"""
Implementation of is_minter in contract Ori20
Method of the function
"""
return self._fn_is_minter.block_call(account)
def mint(self, account: str, amount: int) -> bool:
"""
Implementation of mint in contract Ori20
Method of the function
"""
return self._fn_mint.block_send(account, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def name(self) -> str:
"""
Implementation of name in contract Ori20
Method of the function
"""
return self._fn_name.block_call()
def renounce_minter(self) -> None:
"""
Implementation of renounce_minter in contract Ori20
Method of the function
"""
return self._fn_renounce_minter.block_send(self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def symbol(self) -> str:
"""
Implementation of symbol in contract Ori20
Method of the function
"""
return self._fn_symbol.block_call()
def token_name(self) -> str:
"""
Implementation of token_name in contract Ori20
Method of the function
"""
return self._fn_token_name.block_call()
def token_symbol(self) -> str:
"""
Implementation of token_symbol in contract Ori20
Method of the function
"""
return self._fn_token_symbol.block_call()
def total_supply(self) -> int:
"""
Implementation of total_supply in contract Ori20
Method of the function
"""
return self._fn_total_supply.block_call()
def transfer(self, recipient: str, amount: int) -> bool:
"""
Implementation of transfer in contract Ori20
Method of the function
"""
return self._fn_transfer.block_send(recipient, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def transfer_from(self, sender: str, recipient: str, amount: int) -> bool:
"""
Implementation of transfer_from in contract Ori20
Method of the function
"""
return self._fn_transfer_from.block_send(sender, recipient, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def CallContractWait(self, t_long: int) -> "Ori20":
self._fn_add_minter.setWait(t_long)
self._fn_allowance.setWait(t_long)
self._fn_approve.setWait(t_long)
self._fn_balance_of.setWait(t_long)
self._fn_burn.setWait(t_long)
self._fn_burn_from.setWait(t_long)
self._fn_cap.setWait(t_long)
self._fn_decimals.setWait(t_long)
self._fn_decrease_allowance.setWait(t_long)
self._fn_get_decimals.setWait(t_long)
self._fn_increase_allowance.setWait(t_long)
self._fn_is_minter.setWait(t_long)
self._fn_mint.setWait(t_long)
self._fn_name.setWait(t_long)
self._fn_renounce_minter.setWait(t_long)
self._fn_symbol.setWait(t_long)
self._fn_token_name.setWait(t_long)
self._fn_token_symbol.setWait(t_long)
self._fn_total_supply.setWait(t_long)
self._fn_transfer.setWait(t_long)
self._fn_transfer_from.setWait(t_long)
return self
@staticmethod
def abi():
"""Return the ABI to the underlying contract."""
return json.loads(
'[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"addMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"cap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenName","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenSymbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]'
# noqa: E501 (line-too-long)
)
# pylint: disable=too-many-lines
Classes
class AddMinterMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the addMinter method.
Persist instance data.
Expand source code
class AddMinterMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the addMinter method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, account: str) -> any: """Validate the inputs to the addMinter method.""" self.validator.assert_valid( method_name='addMinter', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) return (account) def block_send(self, account: str, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(account) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -add_minter") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: add_minter") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).transact(tx_params.as_dict()) def build_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).buildTransaction(tx_params.as_dict()) def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, account: str, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> NoneType
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, account: str, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(account) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -add_minter") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: add_minter") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, account: str, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).buildTransaction(tx_params.as_dict())
def estimate_gas(self, account: str, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).estimateGas(tx_params.as_dict())
def send_transaction(self, account: str, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, account: str) ‑>
-
Validate the inputs to the addMinter method.
Expand source code
def validate_and_normalize_inputs(self, account: str) -> any: """Validate the inputs to the addMinter method.""" self.validator.assert_valid( method_name='addMinter', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) return (account)
Inherited members
class AllowanceMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the allowance method.
Persist instance data.
Expand source code
class AllowanceMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the allowance method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, owner: str, spender: str) -> any: """Validate the inputs to the allowance method.""" self.validator.assert_valid( method_name='allowance', parameter_name='owner', argument_value=owner, ) owner = self.validate_and_checksum_address(owner) self.validator.assert_valid( method_name='allowance', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) return (owner, spender) def block_call(self, owner: str, spender: str, debug: bool = False) -> int: _fn = self._underlying_method(owner, spender) returned = _fn.call({ 'from': self._operate }) return int(returned) def estimate_gas(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (owner, spender) = self.validate_and_normalize_inputs(owner, spender) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(owner, spender).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, owner: str, spender: str, debug: bool = False) ‑> int
-
Expand source code
def block_call(self, owner: str, spender: str, debug: bool = False) -> int: _fn = self._underlying_method(owner, spender) returned = _fn.call({ 'from': self._operate }) return int(returned)
def estimate_gas(self, owner: str, spender: str, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (owner, spender) = self.validate_and_normalize_inputs(owner, spender) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(owner, spender).estimateGas(tx_params.as_dict())
def validate_and_normalize_inputs(self, owner: str, spender: str) ‑>
-
Validate the inputs to the allowance method.
Expand source code
def validate_and_normalize_inputs(self, owner: str, spender: str) -> any: """Validate the inputs to the allowance method.""" self.validator.assert_valid( method_name='allowance', parameter_name='owner', argument_value=owner, ) owner = self.validate_and_checksum_address(owner) self.validator.assert_valid( method_name='allowance', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) return (owner, spender)
Inherited members
class ApproveMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the approve method.
Persist instance data.
Expand source code
class ApproveMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the approve method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, spender: str, amount: int) -> any: """Validate the inputs to the approve method.""" self.validator.assert_valid( method_name='approve', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) self.validator.assert_valid( method_name='approve', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (spender, amount) def block_send(self, spender: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(spender, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -approve") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: approve") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (spender, amount) = self.validate_and_normalize_inputs(spender, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, amount).transact(tx_params.as_dict()) def build_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (spender, amount) = self.validate_and_normalize_inputs(spender, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, amount).buildTransaction(tx_params.as_dict()) def estimate_gas(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (spender, amount) = self.validate_and_normalize_inputs(spender, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, amount).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, spender: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> bool
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, spender: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(spender, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -approve") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: approve") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, spender: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (spender, amount) = self.validate_and_normalize_inputs(spender, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, spender: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (spender, amount) = self.validate_and_normalize_inputs(spender, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, amount).estimateGas(tx_params.as_dict())
def send_transaction(self, spender: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (spender, amount) = self.validate_and_normalize_inputs(spender, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, amount).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, spender: str, amount: int) ‑>
-
Validate the inputs to the approve method.
Expand source code
def validate_and_normalize_inputs(self, spender: str, amount: int) -> any: """Validate the inputs to the approve method.""" self.validator.assert_valid( method_name='approve', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) self.validator.assert_valid( method_name='approve', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (spender, amount)
Inherited members
class BalanceOfMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the balanceOf method.
Persist instance data.
Expand source code
class BalanceOfMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the balanceOf method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, account: str) -> any: """Validate the inputs to the balanceOf method.""" self.validator.assert_valid( method_name='balanceOf', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) return (account) def block_call(self, account: str, debug: bool = False) -> int: _fn = self._underlying_method(account) returned = _fn.call({ 'from': self._operate }) return int(returned) def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, account: str, debug: bool = False) ‑> int
-
Expand source code
def block_call(self, account: str, debug: bool = False) -> int: _fn = self._underlying_method(account) returned = _fn.call({ 'from': self._operate }) return int(returned)
def estimate_gas(self, account: str, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).estimateGas(tx_params.as_dict())
def validate_and_normalize_inputs(self, account: str) ‑>
-
Validate the inputs to the balanceOf method.
Expand source code
def validate_and_normalize_inputs(self, account: str) -> any: """Validate the inputs to the balanceOf method.""" self.validator.assert_valid( method_name='balanceOf', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) return (account)
Inherited members
class BurnFromMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the burnFrom method.
Persist instance data.
Expand source code
class BurnFromMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the burnFrom method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, account: str, amount: int) -> any: """Validate the inputs to the burnFrom method.""" self.validator.assert_valid( method_name='burnFrom', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) self.validator.assert_valid( method_name='burnFrom', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (account, amount) def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(account, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -burn_from") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: burn_from") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).transact(tx_params.as_dict()) def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).buildTransaction(tx_params.as_dict()) def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> NoneType
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(account, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -burn_from") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: burn_from") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, account: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, account: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).estimateGas(tx_params.as_dict())
def send_transaction(self, account: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, account: str, amount: int) ‑>
-
Validate the inputs to the burnFrom method.
Expand source code
def validate_and_normalize_inputs(self, account: str, amount: int) -> any: """Validate the inputs to the burnFrom method.""" self.validator.assert_valid( method_name='burnFrom', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) self.validator.assert_valid( method_name='burnFrom', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (account, amount)
Inherited members
class BurnMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the burn method.
Persist instance data.
Expand source code
class BurnMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the burn method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, amount: int) -> any: """Validate the inputs to the burn method.""" self.validator.assert_valid( method_name='burn', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (amount) def block_send(self, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -burn") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: burn") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (amount) = self.validate_and_normalize_inputs(amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(amount).transact(tx_params.as_dict()) def build_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (amount) = self.validate_and_normalize_inputs(amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(amount).buildTransaction(tx_params.as_dict()) def estimate_gas(self, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (amount) = self.validate_and_normalize_inputs(amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(amount).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> NoneType
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -burn") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: burn") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (amount) = self.validate_and_normalize_inputs(amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (amount) = self.validate_and_normalize_inputs(amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(amount).estimateGas(tx_params.as_dict())
def send_transaction(self, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (amount) = self.validate_and_normalize_inputs(amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(amount).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, amount: int) ‑>
-
Validate the inputs to the burn method.
Expand source code
def validate_and_normalize_inputs(self, amount: int) -> any: """Validate the inputs to the burn method.""" self.validator.assert_valid( method_name='burn', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (amount)
Inherited members
class CapMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the cap method.
Persist instance data.
Expand source code
class CapMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the cap method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> int
-
Expand source code
def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class DecimalsMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the decimals method.
Persist instance data.
Expand source code
class DecimalsMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the decimals method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> int
-
Expand source code
def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class DecreaseAllowanceMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the decreaseAllowance method.
Persist instance data.
Expand source code
class DecreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the decreaseAllowance method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, spender: str, subtracted_value: int) -> any: """Validate the inputs to the decreaseAllowance method.""" self.validator.assert_valid( method_name='decreaseAllowance', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) self.validator.assert_valid( method_name='decreaseAllowance', parameter_name='subtractedValue', argument_value=subtracted_value, ) # safeguard against fractional inputs subtracted_value = int(subtracted_value) return (spender, subtracted_value) def block_send(self, spender: str, subtracted_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(spender, subtracted_value) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -decrease_allowance") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: decrease_allowance") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, subtracted_value).transact(tx_params.as_dict()) def build_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, subtracted_value).buildTransaction(tx_params.as_dict()) def estimate_gas(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, subtracted_value).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, spender: str, subtracted_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> bool
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, spender: str, subtracted_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(spender, subtracted_value) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -decrease_allowance") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: decrease_allowance") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, spender: str, subtracted_value: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, subtracted_value).buildTransaction(tx_params.as_dict())
def estimate_gas(self, spender: str, subtracted_value: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, subtracted_value).estimateGas(tx_params.as_dict())
def send_transaction(self, spender: str, subtracted_value: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, subtracted_value).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, spender: str, subtracted_value: int) ‑>
-
Validate the inputs to the decreaseAllowance method.
Expand source code
def validate_and_normalize_inputs(self, spender: str, subtracted_value: int) -> any: """Validate the inputs to the decreaseAllowance method.""" self.validator.assert_valid( method_name='decreaseAllowance', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) self.validator.assert_valid( method_name='decreaseAllowance', parameter_name='subtractedValue', argument_value=subtracted_value, ) # safeguard against fractional inputs subtracted_value = int(subtracted_value) return (spender, subtracted_value)
Inherited members
class GetDecimalsMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the getDecimals method.
Persist instance data.
Expand source code
class GetDecimalsMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the getDecimals method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> int
-
Expand source code
def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class IncreaseAllowanceMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the increaseAllowance method.
Persist instance data.
Expand source code
class IncreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the increaseAllowance method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, spender: str, added_value: int) -> any: """Validate the inputs to the increaseAllowance method.""" self.validator.assert_valid( method_name='increaseAllowance', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) self.validator.assert_valid( method_name='increaseAllowance', parameter_name='addedValue', argument_value=added_value, ) # safeguard against fractional inputs added_value = int(added_value) return (spender, added_value) def block_send(self, spender: str, added_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(spender, added_value) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -increase_allowance") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: increase_allowance") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, added_value).transact(tx_params.as_dict()) def build_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, added_value).buildTransaction(tx_params.as_dict()) def estimate_gas(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, added_value).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, spender: str, added_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> bool
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, spender: str, added_value: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(spender, added_value) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -increase_allowance") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: increase_allowance") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, spender: str, added_value: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, added_value).buildTransaction(tx_params.as_dict())
def estimate_gas(self, spender: str, added_value: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, added_value).estimateGas(tx_params.as_dict())
def send_transaction(self, spender: str, added_value: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(spender, added_value).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, spender: str, added_value: int) ‑>
-
Validate the inputs to the increaseAllowance method.
Expand source code
def validate_and_normalize_inputs(self, spender: str, added_value: int) -> any: """Validate the inputs to the increaseAllowance method.""" self.validator.assert_valid( method_name='increaseAllowance', parameter_name='spender', argument_value=spender, ) spender = self.validate_and_checksum_address(spender) self.validator.assert_valid( method_name='increaseAllowance', parameter_name='addedValue', argument_value=added_value, ) # safeguard against fractional inputs added_value = int(added_value) return (spender, added_value)
Inherited members
class IsMinterMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the isMinter method.
Persist instance data.
Expand source code
class IsMinterMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the isMinter method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, account: str) -> any: """Validate the inputs to the isMinter method.""" self.validator.assert_valid( method_name='isMinter', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) return (account) def block_call(self, account: str, debug: bool = False) -> bool: _fn = self._underlying_method(account) returned = _fn.call({ 'from': self._operate }) return bool(returned) def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, account: str, debug: bool = False) ‑> bool
-
Expand source code
def block_call(self, account: str, debug: bool = False) -> bool: _fn = self._underlying_method(account) returned = _fn.call({ 'from': self._operate }) return bool(returned)
def estimate_gas(self, account: str, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account) = self.validate_and_normalize_inputs(account) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account).estimateGas(tx_params.as_dict())
def validate_and_normalize_inputs(self, account: str) ‑>
-
Validate the inputs to the isMinter method.
Expand source code
def validate_and_normalize_inputs(self, account: str) -> any: """Validate the inputs to the isMinter method.""" self.validator.assert_valid( method_name='isMinter', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) return (account)
Inherited members
class MintMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the mint method.
Persist instance data.
Expand source code
class MintMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the mint method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, account: str, amount: int) -> any: """Validate the inputs to the mint method.""" self.validator.assert_valid( method_name='mint', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) self.validator.assert_valid( method_name='mint', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (account, amount) def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(account, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -mint") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: mint") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).transact(tx_params.as_dict()) def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).buildTransaction(tx_params.as_dict()) def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> bool
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, account: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(account, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -mint") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: mint") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, account: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, account: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).estimateGas(tx_params.as_dict())
def send_transaction(self, account: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (account, amount) = self.validate_and_normalize_inputs(account, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(account, amount).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, account: str, amount: int) ‑>
-
Validate the inputs to the mint method.
Expand source code
def validate_and_normalize_inputs(self, account: str, amount: int) -> any: """Validate the inputs to the mint method.""" self.validator.assert_valid( method_name='mint', parameter_name='account', argument_value=account, ) account = self.validate_and_checksum_address(account) self.validator.assert_valid( method_name='mint', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (account, amount)
Inherited members
class NameMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the name method.
Persist instance data.
Expand source code
class NameMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the name method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> str
-
Expand source code
def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class Ori20 (core_lib: MiliDoS, contract_address: str, validator: Ori20Validator = None)
-
Wrapper class for Ori20 Solidity contract.
Get an instance of wrapper for smart contract.
Expand source code
class Ori20(ContractBase): """Wrapper class for Ori20 Solidity contract.""" _fn_add_minter: AddMinterMethod """Constructor-initialized instance of :class:`AddMinterMethod`. """ _fn_allowance: AllowanceMethod """Constructor-initialized instance of :class:`AllowanceMethod`. """ _fn_approve: ApproveMethod """Constructor-initialized instance of :class:`ApproveMethod`. """ _fn_balance_of: BalanceOfMethod """Constructor-initialized instance of :class:`BalanceOfMethod`. """ _fn_burn: BurnMethod """Constructor-initialized instance of :class:`BurnMethod`. """ _fn_burn_from: BurnFromMethod """Constructor-initialized instance of :class:`BurnFromMethod`. """ _fn_cap: CapMethod """Constructor-initialized instance of :class:`CapMethod`. """ _fn_decimals: DecimalsMethod """Constructor-initialized instance of :class:`DecimalsMethod`. """ _fn_decrease_allowance: DecreaseAllowanceMethod """Constructor-initialized instance of :class:`DecreaseAllowanceMethod`. """ _fn_get_decimals: GetDecimalsMethod """Constructor-initialized instance of :class:`GetDecimalsMethod`. """ _fn_increase_allowance: IncreaseAllowanceMethod """Constructor-initialized instance of :class:`IncreaseAllowanceMethod`. """ _fn_is_minter: IsMinterMethod """Constructor-initialized instance of :class:`IsMinterMethod`. """ _fn_mint: MintMethod """Constructor-initialized instance of :class:`MintMethod`. """ _fn_name: NameMethod """Constructor-initialized instance of :class:`NameMethod`. """ _fn_renounce_minter: RenounceMinterMethod """Constructor-initialized instance of :class:`RenounceMinterMethod`. """ _fn_symbol: SymbolMethod """Constructor-initialized instance of :class:`SymbolMethod`. """ _fn_token_name: TokenNameMethod """Constructor-initialized instance of :class:`TokenNameMethod`. """ _fn_token_symbol: TokenSymbolMethod """Constructor-initialized instance of :class:`TokenSymbolMethod`. """ _fn_total_supply: TotalSupplyMethod """Constructor-initialized instance of :class:`TotalSupplyMethod`. """ _fn_transfer: TransferMethod """Constructor-initialized instance of :class:`TransferMethod`. """ _fn_transfer_from: TransferFromMethod """Constructor-initialized instance of :class:`TransferFromMethod`. """ def __init__( self, core_lib: MiliDoS, contract_address: str, validator: Ori20Validator = None, ): """Get an instance of wrapper for smart contract. """ # pylint: disable=too-many-statements super().__init__() self.contract_address = contract_address web3 = core_lib.w3 if not validator: validator = Ori20Validator(web3, contract_address) # if any middleware was imported, inject it try: MIDDLEWARE except NameError: pass else: try: for middleware in MIDDLEWARE: web3.middleware_onion.inject( middleware['function'], layer=middleware['layer'], ) except ValueError as value_error: if value_error.args == ("You can't add the same un-named instance twice",): pass self._web3_eth = web3.eth functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=Ori20.abi()).functions self.SIGNATURES = SignatureGenerator(Ori20.abi()) self._fn_add_minter = AddMinterMethod(core_lib, contract_address, functions.addMinter, validator) self._fn_allowance = AllowanceMethod(core_lib, contract_address, functions.allowance, validator) self._fn_approve = ApproveMethod(core_lib, contract_address, functions.approve, validator) self._fn_balance_of = BalanceOfMethod(core_lib, contract_address, functions.balanceOf, validator) self._fn_burn = BurnMethod(core_lib, contract_address, functions.burn, validator) self._fn_burn_from = BurnFromMethod(core_lib, contract_address, functions.burnFrom, validator) self._fn_cap = CapMethod(core_lib, contract_address, functions.cap) self._fn_decimals = DecimalsMethod(core_lib, contract_address, functions.decimals) self._fn_decrease_allowance = DecreaseAllowanceMethod(core_lib, contract_address, functions.decreaseAllowance, validator) self._fn_get_decimals = GetDecimalsMethod(core_lib, contract_address, functions.getDecimals) self._fn_increase_allowance = IncreaseAllowanceMethod(core_lib, contract_address, functions.increaseAllowance, validator) self._fn_is_minter = IsMinterMethod(core_lib, contract_address, functions.isMinter, validator) self._fn_mint = MintMethod(core_lib, contract_address, functions.mint, validator) self._fn_name = NameMethod(core_lib, contract_address, functions.name) self._fn_renounce_minter = RenounceMinterMethod(core_lib, contract_address, functions.renounceMinter) self._fn_symbol = SymbolMethod(core_lib, contract_address, functions.symbol) self._fn_token_name = TokenNameMethod(core_lib, contract_address, functions.tokenName) self._fn_token_symbol = TokenSymbolMethod(core_lib, contract_address, functions.tokenSymbol) self._fn_total_supply = TotalSupplyMethod(core_lib, contract_address, functions.totalSupply) self._fn_transfer = TransferMethod(core_lib, contract_address, functions.transfer, validator) self._fn_transfer_from = TransferFromMethod(core_lib, contract_address, functions.transferFrom, validator) def event_approval( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event approval in contract Ori20 Get log entry for Approval event. :param tx_hash: hash of transaction emitting Approval event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.Approval().processReceipt(tx_receipt) def event_minter_added( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event minter_added in contract Ori20 Get log entry for MinterAdded event. :param tx_hash: hash of transaction emitting MinterAdded event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.MinterAdded().processReceipt(tx_receipt) def event_minter_removed( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event minter_removed in contract Ori20 Get log entry for MinterRemoved event. :param tx_hash: hash of transaction emitting MinterRemoved event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.MinterRemoved().processReceipt(tx_receipt) def event_transfer( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event transfer in contract Ori20 Get log entry for Transfer event. :param tx_hash: hash of transaction emitting Transfer event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.Transfer().processReceipt(tx_receipt) def add_minter(self, account: str) -> None: """ Implementation of add_minter in contract Ori20 Method of the function """ return self._fn_add_minter.block_send(account, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def allowance(self, owner: str, spender: str) -> int: """ Implementation of allowance in contract Ori20 Method of the function """ return self._fn_allowance.block_call(owner, spender) def approve(self, spender: str, amount: int) -> bool: """ Implementation of approve in contract Ori20 Method of the function """ return self._fn_approve.block_send(spender, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def balance_of(self, account: str) -> int: """ Implementation of balance_of in contract Ori20 Method of the function """ return self._fn_balance_of.block_call(account) def burn(self, amount: int) -> None: """ Implementation of burn in contract Ori20 Method of the function """ return self._fn_burn.block_send(amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def burn_from(self, account: str, amount: int) -> None: """ Implementation of burn_from in contract Ori20 Method of the function """ return self._fn_burn_from.block_send(account, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def cap(self) -> int: """ Implementation of cap in contract Ori20 Method of the function """ return self._fn_cap.block_call() def decimals(self) -> int: """ Implementation of decimals in contract Ori20 Method of the function """ return self._fn_decimals.block_call() def decrease_allowance(self, spender: str, subtracted_value: int) -> bool: """ Implementation of decrease_allowance in contract Ori20 Method of the function """ return self._fn_decrease_allowance.block_send(spender, subtracted_value, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def get_decimals(self) -> int: """ Implementation of get_decimals in contract Ori20 Method of the function """ return self._fn_get_decimals.block_call() def increase_allowance(self, spender: str, added_value: int) -> bool: """ Implementation of increase_allowance in contract Ori20 Method of the function """ return self._fn_increase_allowance.block_send(spender, added_value, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def is_minter(self, account: str) -> bool: """ Implementation of is_minter in contract Ori20 Method of the function """ return self._fn_is_minter.block_call(account) def mint(self, account: str, amount: int) -> bool: """ Implementation of mint in contract Ori20 Method of the function """ return self._fn_mint.block_send(account, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def name(self) -> str: """ Implementation of name in contract Ori20 Method of the function """ return self._fn_name.block_call() def renounce_minter(self) -> None: """ Implementation of renounce_minter in contract Ori20 Method of the function """ return self._fn_renounce_minter.block_send(self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def symbol(self) -> str: """ Implementation of symbol in contract Ori20 Method of the function """ return self._fn_symbol.block_call() def token_name(self) -> str: """ Implementation of token_name in contract Ori20 Method of the function """ return self._fn_token_name.block_call() def token_symbol(self) -> str: """ Implementation of token_symbol in contract Ori20 Method of the function """ return self._fn_token_symbol.block_call() def total_supply(self) -> int: """ Implementation of total_supply in contract Ori20 Method of the function """ return self._fn_total_supply.block_call() def transfer(self, recipient: str, amount: int) -> bool: """ Implementation of transfer in contract Ori20 Method of the function """ return self._fn_transfer.block_send(recipient, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def transfer_from(self, sender: str, recipient: str, amount: int) -> bool: """ Implementation of transfer_from in contract Ori20 Method of the function """ return self._fn_transfer_from.block_send(sender, recipient, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt) def CallContractWait(self, t_long: int) -> "Ori20": self._fn_add_minter.setWait(t_long) self._fn_allowance.setWait(t_long) self._fn_approve.setWait(t_long) self._fn_balance_of.setWait(t_long) self._fn_burn.setWait(t_long) self._fn_burn_from.setWait(t_long) self._fn_cap.setWait(t_long) self._fn_decimals.setWait(t_long) self._fn_decrease_allowance.setWait(t_long) self._fn_get_decimals.setWait(t_long) self._fn_increase_allowance.setWait(t_long) self._fn_is_minter.setWait(t_long) self._fn_mint.setWait(t_long) self._fn_name.setWait(t_long) self._fn_renounce_minter.setWait(t_long) self._fn_symbol.setWait(t_long) self._fn_token_name.setWait(t_long) self._fn_token_symbol.setWait(t_long) self._fn_total_supply.setWait(t_long) self._fn_transfer.setWait(t_long) self._fn_transfer_from.setWait(t_long) return self @staticmethod def abi(): """Return the ABI to the underlying contract.""" return json.loads( '[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"addMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"cap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenName","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenSymbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long) )
Ancestors
Static methods
def abi()
-
Return the ABI to the underlying contract.
Expand source code
@staticmethod def abi(): """Return the ABI to the underlying contract.""" return json.loads( '[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"addMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"cap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenName","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenSymbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long) )
Methods
def CallContractWait(self, t_long: int) ‑> Ori20
-
Expand source code
def CallContractWait(self, t_long: int) -> "Ori20": self._fn_add_minter.setWait(t_long) self._fn_allowance.setWait(t_long) self._fn_approve.setWait(t_long) self._fn_balance_of.setWait(t_long) self._fn_burn.setWait(t_long) self._fn_burn_from.setWait(t_long) self._fn_cap.setWait(t_long) self._fn_decimals.setWait(t_long) self._fn_decrease_allowance.setWait(t_long) self._fn_get_decimals.setWait(t_long) self._fn_increase_allowance.setWait(t_long) self._fn_is_minter.setWait(t_long) self._fn_mint.setWait(t_long) self._fn_name.setWait(t_long) self._fn_renounce_minter.setWait(t_long) self._fn_symbol.setWait(t_long) self._fn_token_name.setWait(t_long) self._fn_token_symbol.setWait(t_long) self._fn_total_supply.setWait(t_long) self._fn_transfer.setWait(t_long) self._fn_transfer_from.setWait(t_long) return self
def add_minter(self, account: str) ‑> NoneType
-
Implementation of add_minter in contract Ori20 Method of the function
Expand source code
def add_minter(self, account: str) -> None: """ Implementation of add_minter in contract Ori20 Method of the function """ return self._fn_add_minter.block_send(account, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def allowance(self, owner: str, spender: str) ‑> int
-
Implementation of allowance in contract Ori20 Method of the function
Expand source code
def allowance(self, owner: str, spender: str) -> int: """ Implementation of allowance in contract Ori20 Method of the function """ return self._fn_allowance.block_call(owner, spender)
def approve(self, spender: str, amount: int) ‑> bool
-
Implementation of approve in contract Ori20 Method of the function
Expand source code
def approve(self, spender: str, amount: int) -> bool: """ Implementation of approve in contract Ori20 Method of the function """ return self._fn_approve.block_send(spender, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def balance_of(self, account: str) ‑> int
-
Implementation of balance_of in contract Ori20 Method of the function
Expand source code
def balance_of(self, account: str) -> int: """ Implementation of balance_of in contract Ori20 Method of the function """ return self._fn_balance_of.block_call(account)
def burn(self, amount: int) ‑> NoneType
-
Implementation of burn in contract Ori20 Method of the function
Expand source code
def burn(self, amount: int) -> None: """ Implementation of burn in contract Ori20 Method of the function """ return self._fn_burn.block_send(amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def burn_from(self, account: str, amount: int) ‑> NoneType
-
Implementation of burn_from in contract Ori20 Method of the function
Expand source code
def burn_from(self, account: str, amount: int) -> None: """ Implementation of burn_from in contract Ori20 Method of the function """ return self._fn_burn_from.block_send(account, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def cap(self) ‑> int
-
Implementation of cap in contract Ori20 Method of the function
Expand source code
def cap(self) -> int: """ Implementation of cap in contract Ori20 Method of the function """ return self._fn_cap.block_call()
def decimals(self) ‑> int
-
Implementation of decimals in contract Ori20 Method of the function
Expand source code
def decimals(self) -> int: """ Implementation of decimals in contract Ori20 Method of the function """ return self._fn_decimals.block_call()
def decrease_allowance(self, spender: str, subtracted_value: int) ‑> bool
-
Implementation of decrease_allowance in contract Ori20 Method of the function
Expand source code
def decrease_allowance(self, spender: str, subtracted_value: int) -> bool: """ Implementation of decrease_allowance in contract Ori20 Method of the function """ return self._fn_decrease_allowance.block_send(spender, subtracted_value, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def event_approval(self, tx_hash: Union[hexbytes.main.HexBytes, bytes]) ‑> Tuple[web3.datastructures.AttributeDict]
-
Implementation of event approval in contract Ori20 Get log entry for Approval event. :param tx_hash: hash of transaction emitting Approval event
Expand source code
def event_approval( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event approval in contract Ori20 Get log entry for Approval event. :param tx_hash: hash of transaction emitting Approval event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.Approval().processReceipt(tx_receipt)
def event_minter_added(self, tx_hash: Union[hexbytes.main.HexBytes, bytes]) ‑> Tuple[web3.datastructures.AttributeDict]
-
Implementation of event minter_added in contract Ori20 Get log entry for MinterAdded event. :param tx_hash: hash of transaction emitting MinterAdded event
Expand source code
def event_minter_added( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event minter_added in contract Ori20 Get log entry for MinterAdded event. :param tx_hash: hash of transaction emitting MinterAdded event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.MinterAdded().processReceipt(tx_receipt)
def event_minter_removed(self, tx_hash: Union[hexbytes.main.HexBytes, bytes]) ‑> Tuple[web3.datastructures.AttributeDict]
-
Implementation of event minter_removed in contract Ori20 Get log entry for MinterRemoved event. :param tx_hash: hash of transaction emitting MinterRemoved event
Expand source code
def event_minter_removed( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event minter_removed in contract Ori20 Get log entry for MinterRemoved event. :param tx_hash: hash of transaction emitting MinterRemoved event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.MinterRemoved().processReceipt(tx_receipt)
def event_transfer(self, tx_hash: Union[hexbytes.main.HexBytes, bytes]) ‑> Tuple[web3.datastructures.AttributeDict]
-
Implementation of event transfer in contract Ori20 Get log entry for Transfer event. :param tx_hash: hash of transaction emitting Transfer event
Expand source code
def event_transfer( self, tx_hash: Union[HexBytes, bytes] ) -> Tuple[AttributeDict]: """ Implementation of event transfer in contract Ori20 Get log entry for Transfer event. :param tx_hash: hash of transaction emitting Transfer event """ tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Ori20.abi()).events.Transfer().processReceipt(tx_receipt)
def get_decimals(self) ‑> int
-
Implementation of get_decimals in contract Ori20 Method of the function
Expand source code
def get_decimals(self) -> int: """ Implementation of get_decimals in contract Ori20 Method of the function """ return self._fn_get_decimals.block_call()
def increase_allowance(self, spender: str, added_value: int) ‑> bool
-
Implementation of increase_allowance in contract Ori20 Method of the function
Expand source code
def increase_allowance(self, spender: str, added_value: int) -> bool: """ Implementation of increase_allowance in contract Ori20 Method of the function """ return self._fn_increase_allowance.block_send(spender, added_value, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def is_minter(self, account: str) ‑> bool
-
Implementation of is_minter in contract Ori20 Method of the function
Expand source code
def is_minter(self, account: str) -> bool: """ Implementation of is_minter in contract Ori20 Method of the function """ return self._fn_is_minter.block_call(account)
def mint(self, account: str, amount: int) ‑> bool
-
Implementation of mint in contract Ori20 Method of the function
Expand source code
def mint(self, account: str, amount: int) -> bool: """ Implementation of mint in contract Ori20 Method of the function """ return self._fn_mint.block_send(account, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def name(self) ‑> str
-
Implementation of name in contract Ori20 Method of the function
Expand source code
def name(self) -> str: """ Implementation of name in contract Ori20 Method of the function """ return self._fn_name.block_call()
def renounce_minter(self) ‑> NoneType
-
Implementation of renounce_minter in contract Ori20 Method of the function
Expand source code
def renounce_minter(self) -> None: """ Implementation of renounce_minter in contract Ori20 Method of the function """ return self._fn_renounce_minter.block_send(self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def symbol(self) ‑> str
-
Implementation of symbol in contract Ori20 Method of the function
Expand source code
def symbol(self) -> str: """ Implementation of symbol in contract Ori20 Method of the function """ return self._fn_symbol.block_call()
def token_name(self) ‑> str
-
Implementation of token_name in contract Ori20 Method of the function
Expand source code
def token_name(self) -> str: """ Implementation of token_name in contract Ori20 Method of the function """ return self._fn_token_name.block_call()
def token_symbol(self) ‑> str
-
Implementation of token_symbol in contract Ori20 Method of the function
Expand source code
def token_symbol(self) -> str: """ Implementation of token_symbol in contract Ori20 Method of the function """ return self._fn_token_symbol.block_call()
def total_supply(self) ‑> int
-
Implementation of total_supply in contract Ori20 Method of the function
Expand source code
def total_supply(self) -> int: """ Implementation of total_supply in contract Ori20 Method of the function """ return self._fn_total_supply.block_call()
def transfer(self, recipient: str, amount: int) ‑> bool
-
Implementation of transfer in contract Ori20 Method of the function
Expand source code
def transfer(self, recipient: str, amount: int) -> bool: """ Implementation of transfer in contract Ori20 Method of the function """ return self._fn_transfer.block_send(recipient, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
def transfer_from(self, sender: str, recipient: str, amount: int) ‑> bool
-
Implementation of transfer_from in contract Ori20 Method of the function
Expand source code
def transfer_from(self, sender: str, recipient: str, amount: int) -> bool: """ Implementation of transfer_from in contract Ori20 Method of the function """ return self._fn_transfer_from.block_send(sender, recipient, amount, self.call_contract_fee_amount, self.call_contract_fee_price, 0, self.call_contract_debug_flag, self.call_contract_enforce_tx_receipt)
class Ori20Validator (web3_or_provider: web3.main.Web3, contract_address: str)
-
No-op input validator.
Initialize the instance.
Expand source code
class Ori20Validator( # type: ignore Validator ): """No-op input validator."""
Ancestors
Inherited members
class RenounceMinterMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the renounceMinter method.
Persist instance data.
Expand source code
class RenounceMinterMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the renounceMinter method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_send(self, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method() try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -renounce_minter") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: renounce_minter") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().transact(tx_params.as_dict()) def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().buildTransaction(tx_params.as_dict()) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> NoneType
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> None: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method() try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -renounce_minter") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: renounce_minter") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().buildTransaction(tx_params.as_dict())
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
def send_transaction(self, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().transact(tx_params.as_dict())
Inherited members
class SignatureGenerator (abi:
) -
Expand source code
class SignatureGenerator: _function_signatures = {} def __init__(self, abi: any): for func in [obj for obj in abi if obj['type'] == 'function']: name = func['name'] types = [input['type'] for input in func['inputs']] self._function_signatures[name] = '{}({})'.format(name, ','.join(types)) def add_minter(self) -> str: return self._function_signatures["addMinter"] def allowance(self) -> str: return self._function_signatures["allowance"] def approve(self) -> str: return self._function_signatures["approve"] def balance_of(self) -> str: return self._function_signatures["balanceOf"] def burn(self) -> str: return self._function_signatures["burn"] def burn_from(self) -> str: return self._function_signatures["burnFrom"] def cap(self) -> str: return self._function_signatures["cap"] def decimals(self) -> str: return self._function_signatures["decimals"] def decrease_allowance(self) -> str: return self._function_signatures["decreaseAllowance"] def get_decimals(self) -> str: return self._function_signatures["getDecimals"] def increase_allowance(self) -> str: return self._function_signatures["increaseAllowance"] def is_minter(self) -> str: return self._function_signatures["isMinter"] def mint(self) -> str: return self._function_signatures["mint"] def name(self) -> str: return self._function_signatures["name"] def renounce_minter(self) -> str: return self._function_signatures["renounceMinter"] def symbol(self) -> str: return self._function_signatures["symbol"] def token_name(self) -> str: return self._function_signatures["tokenName"] def token_symbol(self) -> str: return self._function_signatures["tokenSymbol"] def total_supply(self) -> str: return self._function_signatures["totalSupply"] def transfer(self) -> str: return self._function_signatures["transfer"] def transfer_from(self) -> str: return self._function_signatures["transferFrom"]
Methods
def add_minter(self) ‑> str
-
Expand source code
def add_minter(self) -> str: return self._function_signatures["addMinter"]
def allowance(self) ‑> str
-
Expand source code
def allowance(self) -> str: return self._function_signatures["allowance"]
def approve(self) ‑> str
-
Expand source code
def approve(self) -> str: return self._function_signatures["approve"]
def balance_of(self) ‑> str
-
Expand source code
def balance_of(self) -> str: return self._function_signatures["balanceOf"]
def burn(self) ‑> str
-
Expand source code
def burn(self) -> str: return self._function_signatures["burn"]
def burn_from(self) ‑> str
-
Expand source code
def burn_from(self) -> str: return self._function_signatures["burnFrom"]
def cap(self) ‑> str
-
Expand source code
def cap(self) -> str: return self._function_signatures["cap"]
def decimals(self) ‑> str
-
Expand source code
def decimals(self) -> str: return self._function_signatures["decimals"]
def decrease_allowance(self) ‑> str
-
Expand source code
def decrease_allowance(self) -> str: return self._function_signatures["decreaseAllowance"]
def get_decimals(self) ‑> str
-
Expand source code
def get_decimals(self) -> str: return self._function_signatures["getDecimals"]
def increase_allowance(self) ‑> str
-
Expand source code
def increase_allowance(self) -> str: return self._function_signatures["increaseAllowance"]
def is_minter(self) ‑> str
-
Expand source code
def is_minter(self) -> str: return self._function_signatures["isMinter"]
def mint(self) ‑> str
-
Expand source code
def mint(self) -> str: return self._function_signatures["mint"]
def name(self) ‑> str
-
Expand source code
def name(self) -> str: return self._function_signatures["name"]
def renounce_minter(self) ‑> str
-
Expand source code
def renounce_minter(self) -> str: return self._function_signatures["renounceMinter"]
def symbol(self) ‑> str
-
Expand source code
def symbol(self) -> str: return self._function_signatures["symbol"]
def token_name(self) ‑> str
-
Expand source code
def token_name(self) -> str: return self._function_signatures["tokenName"]
def token_symbol(self) ‑> str
-
Expand source code
def token_symbol(self) -> str: return self._function_signatures["tokenSymbol"]
def total_supply(self) ‑> str
-
Expand source code
def total_supply(self) -> str: return self._function_signatures["totalSupply"]
def transfer(self) ‑> str
-
Expand source code
def transfer(self) -> str: return self._function_signatures["transfer"]
def transfer_from(self) ‑> str
-
Expand source code
def transfer_from(self) -> str: return self._function_signatures["transferFrom"]
class SymbolMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the symbol method.
Persist instance data.
Expand source code
class SymbolMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the symbol method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> str
-
Expand source code
def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class TokenNameMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the tokenName method.
Persist instance data.
Expand source code
class TokenNameMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the tokenName method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> str
-
Expand source code
def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class TokenSymbolMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the tokenSymbol method.
Persist instance data.
Expand source code
class TokenSymbolMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the tokenSymbol method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> str
-
Expand source code
def block_call(self, debug: bool = False) -> str: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return str(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class TotalSupplyMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction)
-
Various interfaces to the totalSupply method.
Persist instance data.
Expand source code
class TotalSupplyMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the totalSupply method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction): """Persist instance data.""" super().__init__(elib, contract_address) self._underlying_method = contract_function def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned) def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_call(self, debug: bool = False) ‑> int
-
Expand source code
def block_call(self, debug: bool = False) -> int: _fn = self._underlying_method() returned = _fn.call({ 'from': self._operate }) return int(returned)
def estimate_gas(self, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" tx_params = super().normalize_tx_params(tx_params) return self._underlying_method().estimateGas(tx_params.as_dict())
Inherited members
class TransferFromMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the transferFrom method.
Persist instance data.
Expand source code
class TransferFromMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the transferFrom method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, sender: str, recipient: str, amount: int) -> any: """Validate the inputs to the transferFrom method.""" self.validator.assert_valid( method_name='transferFrom', parameter_name='sender', argument_value=sender, ) sender = self.validate_and_checksum_address(sender) self.validator.assert_valid( method_name='transferFrom', parameter_name='recipient', argument_value=recipient, ) recipient = self.validate_and_checksum_address(recipient) self.validator.assert_valid( method_name='transferFrom', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (sender, recipient, amount) def block_send(self, sender: str, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(sender, recipient, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -transfer_from") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: transfer_from") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(sender, recipient, amount).transact(tx_params.as_dict()) def build_transaction(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(sender, recipient, amount).buildTransaction(tx_params.as_dict()) def estimate_gas(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(sender, recipient, amount).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, sender: str, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> bool
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, sender: str, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(sender, recipient, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -transfer_from") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: transfer_from") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, sender: str, recipient: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(sender, recipient, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, sender: str, recipient: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(sender, recipient, amount).estimateGas(tx_params.as_dict())
def send_transaction(self, sender: str, recipient: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, sender: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (sender, recipient, amount) = self.validate_and_normalize_inputs(sender, recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(sender, recipient, amount).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, sender: str, recipient: str, amount: int) ‑>
-
Validate the inputs to the transferFrom method.
Expand source code
def validate_and_normalize_inputs(self, sender: str, recipient: str, amount: int) -> any: """Validate the inputs to the transferFrom method.""" self.validator.assert_valid( method_name='transferFrom', parameter_name='sender', argument_value=sender, ) sender = self.validate_and_checksum_address(sender) self.validator.assert_valid( method_name='transferFrom', parameter_name='recipient', argument_value=recipient, ) recipient = self.validate_and_checksum_address(recipient) self.validator.assert_valid( method_name='transferFrom', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (sender, recipient, amount)
Inherited members
class TransferMethod (elib: MiliDoS, contract_address: str, contract_function: web3.contract.ContractFunction, validator: Validator = None)
-
Various interfaces to the transfer method.
Persist instance data.
Expand source code
class TransferMethod(ContractMethod): # pylint: disable=invalid-name """Various interfaces to the transfer method.""" def __init__(self, elib: MiliDoS, contract_address: str, contract_function: ContractFunction, validator: Validator = None): """Persist instance data.""" super().__init__(elib, contract_address, validator) self._underlying_method = contract_function def validate_and_normalize_inputs(self, recipient: str, amount: int) -> any: """Validate the inputs to the transfer method.""" self.validator.assert_valid( method_name='transfer', parameter_name='recipient', argument_value=recipient, ) recipient = self.validate_and_checksum_address(recipient) self.validator.assert_valid( method_name='transfer', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (recipient, amount) def block_send(self, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(recipient, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -transfer") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: transfer") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token") def send_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (recipient, amount) = self.validate_and_normalize_inputs(recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(recipient, amount).transact(tx_params.as_dict()) def build_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (recipient, amount) = self.validate_and_normalize_inputs(recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(recipient, amount).buildTransaction(tx_params.as_dict()) def estimate_gas(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (recipient, amount) = self.validate_and_normalize_inputs(recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(recipient, amount).estimateGas(tx_params.as_dict())
Ancestors
Methods
def block_send(self, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) ‑> bool
-
Execute underlying contract method via eth_call.
:param tx_params: transaction parameters :returns: the return value of the underlying method.
Expand source code
def block_send(self, recipient: str, amount: int, gas: int, price: int, val: int = 0, debug: bool = False, receiptListen: bool = False) -> bool: """Execute underlying contract method via eth_call. :param tx_params: transaction parameters :returns: the return value of the underlying method. """ _fn = self._underlying_method(recipient, amount) try: _t = _fn.buildTransaction({ 'from': self._operate, 'gas': gas, 'gasPrice': price }) _t['nonce'] = self._web3_eth.getTransactionCount(self._operate) if val > 0: _t['value'] = val if debug: print(f"======== Signing ✅ by {self._operate}") print(f"======== Transaction ✅ check") print(_t) if 'data' in _t: signed = self._web3_eth.account.sign_transaction(_t) txHash = self._web3_eth.sendRawTransaction(signed.rawTransaction) tx_receipt = None if receiptListen is True: print("======== awaiting Confirmation 🚸️ -transfer") tx_receipt = self._web3_eth.waitForTransactionReceipt(txHash) if debug: print("======== TX Result ✅") print(tx_receipt) print(f"======== TX blockHash ✅") if receiptListen is True and tx_receipt is not None: print(f"{Bolors.OK}{tx_receipt.blockHash.hex()}{Bolors.RESET}") else: print(f"{Bolors.WARNING}{txHash.hex()}{Bolors.RESET}") if receiptListen is False: time.sleep(self._wait) except ContractLogicError as er: print(f"{Bolors.FAIL}Error {er} {Bolors.RESET}: transfer") except ValueError as err: if "message" in err.args[0]: message = err.args[0]["message"] print(f"{Bolors.FAIL}Error Revert {Bolors.RESET} on set_asset_token: {message}") else: print(f"{Bolors.FAIL}Error Revert {Bolors.RESET}: set_asset_token")
def build_transaction(self, recipient: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> dict
-
Construct calldata to be used as input to the method.
Expand source code
def build_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict: """Construct calldata to be used as input to the method.""" (recipient, amount) = self.validate_and_normalize_inputs(recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(recipient, amount).buildTransaction(tx_params.as_dict())
def estimate_gas(self, recipient: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> int
-
Estimate gas consumption of method call.
Expand source code
def estimate_gas(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int: """Estimate gas consumption of method call.""" (recipient, amount) = self.validate_and_normalize_inputs(recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(recipient, amount).estimateGas(tx_params.as_dict())
def send_transaction(self, recipient: str, amount: int, tx_params: Union[TxParams, NoneType] = None) ‑> Union[hexbytes.main.HexBytes, bytes]
-
Execute underlying contract method via eth_sendTransaction.
:param tx_params: transaction parameters
Expand source code
def send_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: """Execute underlying contract method via eth_sendTransaction. :param tx_params: transaction parameters """ (recipient, amount) = self.validate_and_normalize_inputs(recipient, amount) tx_params = super().normalize_tx_params(tx_params) return self._underlying_method(recipient, amount).transact(tx_params.as_dict())
def validate_and_normalize_inputs(self, recipient: str, amount: int) ‑>
-
Validate the inputs to the transfer method.
Expand source code
def validate_and_normalize_inputs(self, recipient: str, amount: int) -> any: """Validate the inputs to the transfer method.""" self.validator.assert_valid( method_name='transfer', parameter_name='recipient', argument_value=recipient, ) recipient = self.validate_and_checksum_address(recipient) self.validator.assert_valid( method_name='transfer', parameter_name='amount', argument_value=amount, ) # safeguard against fractional inputs amount = int(amount) return (recipient, amount)
Inherited members