Skip to content

Commit

Permalink
Fixed privKey to account type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaven committed Jul 1, 2024
1 parent 6dfe53c commit b91acff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions PyEthHelper/EthContractHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def LoadContract(
return contract


def IsAccountType(obj: Any) -> bool:
return (obj is not None) and hasattr(obj, 'address') and hasattr(obj, 'key')


def _EstimateGas(
executable: Union[ ContractConstructor, ContractFunction ],
value: int,
Expand Down Expand Up @@ -168,8 +172,8 @@ def _FillMessage(
privKey: Union[ None, str, Account ],
feeCalculator: Callable[[int, int], Tuple[int, int]],
) -> dict:
if (privKey is not None) and (not isinstance(privKey, Account)):
privKey: Account = Account.from_key(privKey)
if (privKey is not None) and (not IsAccountType(privKey)):
privKey = Account.from_key(privKey)

msg = {
'nonce': w3.eth.get_transaction_count(privKey.address),
Expand Down Expand Up @@ -201,8 +205,8 @@ def _SignTx(
gas = tx['gas']
value = tx['value']

if not isinstance(privKey, Account):
privKey: Account = Account.from_key(privKey)
if not IsAccountType(privKey):
privKey = Account.from_key(privKey)
balance = w3.eth.get_balance(privKey.address)

maxFee = maxFeePerGas * gas
Expand Down Expand Up @@ -273,8 +277,8 @@ def _DoTransaction(
) -> TxReceipt:
logger = logging.getLogger(__name__ + '.' + _DoTransaction.__name__)

if (privKey is not None) and (not isinstance(privKey, Account)):
privKey: Account = Account.from_key(privKey)
if (privKey is not None) and (not IsAccountType(privKey)):
privKey = Account.from_key(privKey)

gas = _DetermineGas(executable, gas, value)
msg = _FillMessage(w3, gas, value, privKey, feeCalculator)
Expand Down
2 changes: 1 addition & 1 deletion PyEthHelper/_Meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



__version__ = '0.1.2'
__version__ = '0.1.3'

PKG_AUTHOR = 'Languages, Systems, and Data Lab at UC Santa Cruz'
PKG_NAME = 'PyEthHelper'
Expand Down

0 comments on commit b91acff

Please sign in to comment.