plugins.aea-ledger-ethereum.aea_
ledger_
ethereum.ethereum
Ethereum module wrapping the public and private key cryptography and ledger api.
get_
gas_
price_
strategy
get_gas_price_strategy(gas_price_strategy: Optional[str] = None, api_key: Optional[str] = None) -> Callable[[Web3, TxParams], Wei]
Get the gas price strategy.
SignedTransactionTranslator Objects
Translator for SignedTransaction.
to_
dict
Write SignedTransaction to dict.
from_
dict
Get SignedTransaction from dict.
AttributeDictTranslator Objects
Translator for AttributeDict.
to_
dict
Simplify to dict.
from_
dict
Get back attribute dict.
EthereumCrypto Objects
Class wrapping the Account Generation from Ethereum ledger.
__
init__
Instantiate an ethereum crypto object.
Arguments:
private_key_path
: the private key path of the agentpassword
: the password to encrypt/decrypt the private key.
private_
key
Return a private key.
Returns:
a private key string
public_
key
Return a public key in hex format.
Returns:
a public key string in hex format
address
Return the address for the key pair.
Returns:
a display_address str
load_
private_
key_
from_
path
| @classmethod
| load_private_key_from_path(cls, file_name: str, password: Optional[str] = None) -> Account
Load a private key in hex format from a file.
Arguments:
file_name
: the path to the hex file.password
: the password to encrypt/decrypt the private key.
Returns:
the Entity.
sign_
message
Sign a message in bytes string form.
Arguments:
message
: the message to be signedis_deprecated_mode
: if the deprecated signing is used
Returns:
signature of the message in string form
sign_
transaction
Sign a transaction in bytes string form.
Arguments:
transaction
: the transaction to be signed
Returns:
signed transaction
generate_
private_
key
Generate a key pair for ethereum network.
encrypt
Encrypt the private key and return in json.
Arguments:
password
: the password to decrypt.
Returns:
json string containing encrypted private key.
decrypt
Decrypt the private key and return in raw form.
Arguments:
keyfile_json
: json str containing encrypted private key.password
: the password to decrypt.
Returns:
the raw private key.
EthereumHelper Objects
Helper class usable as Mixin for EthereumApi or as standalone class.
is_
transaction_
settled
Check whether a transaction is settled or not.
Arguments:
tx_receipt
: the receipt associated to the transaction.
Returns:
True if the transaction has been settled, False o/w.
get_
contract_
address
Retrieve the contract_address
from a transaction receipt.
Arguments:
tx_receipt
: the receipt of the transaction.
Returns:
the contract address, if present
is_
transaction_
valid
| @staticmethod
| is_transaction_valid(tx: dict, seller: Address, client: Address, tx_nonce: str, amount: int) -> bool
Check whether a transaction is valid or not.
Arguments:
tx
: the transaction.seller
: the address of the seller.client
: the address of the client.tx_nonce
: the transaction nonce.amount
: the amount we expect to get from the transaction.
Returns:
True if the random_message is equals to tx['input']
generate_
tx_
nonce
Generate a unique hash to distinguish transactions with the same terms.
Arguments:
seller
: the address of the seller.client
: the address of the client.
Returns:
return the hash in hex.
get_
address_
from_
public_
key
Get the address from the public key.
Arguments:
public_key
: the public key
Returns:
str
recover_
message
| @classmethod
| recover_message(cls, message: bytes, signature: str, is_deprecated_mode: bool = False) -> Tuple[Address, ...]
Recover the addresses from the hash.
Arguments:
message
: the message we expectsignature
: the transaction signatureis_deprecated_mode
: if the deprecated signing was used
Returns:
the recovered addresses
recover_
public_
keys_
from_
message
| @classmethod
| recover_public_keys_from_message(cls, message: bytes, signature: str, is_deprecated_mode: bool = False) -> Tuple[str, ...]
Get the public key used to produce the signature
of the message
Arguments:
message
: raw bytes used to produce signaturesignature
: signature of the messageis_deprecated_mode
: if the deprecated signing was used
Returns:
the recovered public keys
get_
hash
Get the hash of a message.
Arguments:
message
: the message to be hashed.
Returns:
the hash of the message.
load_
contract_
interface
Load contract interface.
Arguments:
file_path
: the file path to the interface
Returns:
the interface
EthereumApi Objects
Class to interact with the Ethereum Web3 APIs.
__
init__
Initialize the Ethereum ledger APIs.
Arguments:
kwargs
: keyword arguments
api
Get the underlying API object.
get_
balance
Get the balance of a given account.
get_
state
Call a specified function on the ledger API.
get_
transfer_
transaction
| get_transfer_transaction(sender_address: Address, destination_address: Address, amount: int, tx_fee: int, tx_nonce: str, chain_id: Optional[int] = None, gas_price: Optional[str] = None, gas_price_strategy: Optional[str] = None, **kwargs: Any, ,) -> Optional[JSONLike]
Submit a transfer transaction to the ledger.
Arguments:
sender_address
: the sender address of the payer.destination_address
: the destination address of the payee.amount
: the amount of wealth to be transferred (in Wei).tx_fee
: the transaction fee (gas) to be used (in Wei).tx_nonce
: verifies the authenticity of the tx.chain_id
: the Chain ID of the Ethereum transaction.gas_price
: the gas price (in Wei)gas_price_strategy
: the gas price strategy to be used.kwargs
: keyword arguments
Returns:
the transfer transaction
update_
with_
gas_
estimate
Attempts to update the transaction with a gas estimate
Arguments:
transaction
: the transaction
Returns:
the updated transaction
send_
signed_
transaction
Send a signed transaction and wait for confirmation.
Arguments:
tx_signed
: the signed transaction
Returns:
tx_digest, if present
get_
transaction_
receipt
Get the transaction receipt for a transaction digest.
Arguments:
tx_digest
: the digest associated to the transaction.
Returns:
the tx receipt, if present
get_
transaction
Get the transaction for a transaction digest.
Arguments:
tx_digest
: the digest associated to the transaction.
Returns:
the tx, if present
get_
contract_
instance
| get_contract_instance(contract_interface: Dict[str, str], contract_address: Optional[str] = None) -> Any
Get the instance of a contract.
Arguments:
contract_interface
: the contract interface.contract_address
: the contract address.
Returns:
the contract instance
get_
deploy_
transaction
| get_deploy_transaction(contract_interface: Dict[str, str], deployer_address: Address, value: int = 0, gas: int = 0, gas_price: Optional[str] = None, gas_price_strategy: Optional[str] = None, **kwargs: Any, ,) -> Optional[JSONLike]
Get the transaction to deploy the smart contract.
Arguments:
contract_interface
: the contract interface.deployer_address
: The address that will deploy the contract.value
: value to send to contract (in Wei)gas
: the gas to be used (in Wei)gas_price
: the gas price (in Wei)gas_price_strategy
: the gas price strategy to be used.kwargs
: keyword arguments
Returns:
the transaction dictionary.
is_
valid_
address
Check if the address is valid.
Arguments:
address
: the address to validate
Returns:
whether the address is valid
EthereumFaucetApi Objects
Ethereum testnet faucet API.
get_
wealth
Get wealth from the faucet for the provided address.
Arguments:
address
: the address.url
: the url
LruLockWrapper Objects
Wrapper for LRU with threading.Lock.
__
init__
Init wrapper.
__
getitem__
Get item
__
setitem__
Set item.
__
contains__
Contain item.
__
delitem__
Del item.
set_
wrapper_
for_
web3py_
session_
cache
Wrap web3py session cache with threading.Lock.