plugins.aea-ledger-solana.aea_ledger_solana.helper
This module contains the helpers for the solana ledger.
BlockhashCache Objects
class BlockhashCache()
Minimal TTL cache for a recent blockhash.
Inlined because solana.blockhash.BlockhashCache was removed in
solana-py 0.33.0 (coinciding with the drop of the cachetools<5 pin
that this plugin needs to shed to coexist with modern tomte[tox]).
__init__
def __init__(ttl: int = 60) -> None
Initialise with a time-to-live in seconds.
set
def set(blockhash: str, slot: int) -> None
Store a blockhash and its slot.
get
def get() -> str
Return the cached blockhash or raise if stale/missing.
SolanaHelper Objects
class SolanaHelper(Helper)
Helper class usable as Mixin for SolanaApi or as standalone class.
BlockhashCache
defined in SolanaAPi.init
load_contract_interface
@classmethod
def load_contract_interface(
cls,
idl_file_path: Optional[Path] = None,
program_keypair: Optional[Crypto] = None,
program_address: Optional[str] = None,
rpc_api: Optional[str] = None,
bytecode_path: Optional[Path] = None) -> Dict[str, Any]
Load contract interface.
Arguments:
idl_file_path: the file path to the IDLprogram_keypair: the program keypairprogram_address: the program addressrpc_api: the rpc apibytecode_path: the file path to the bytecode
Returns:
the interface
is_transaction_valid
@staticmethod
def is_transaction_valid(tx: JSONLike, 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.
noqa: DAR202
Returns:
True if the random_message is equals to tx['input']
is_transaction_settled
@staticmethod
def is_transaction_settled(tx_receipt: JSONLike) -> bool
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_hash
@staticmethod
def get_hash(message: bytes) -> str
Get the hash of a message.
Arguments:
message: the message to be hashed.
Returns:
the hash of the message as a hex string.
recover_message
@classmethod
def recover_message(cls,
message: bytes,
signature: str,
is_deprecated_mode: bool = False) -> Tuple[Address, ...]
Recover the addresses from the hash.
TOBEIMPLEMENTED
Arguments:
message: the message we expectsignature: the transaction signatureis_deprecated_mode: if the deprecated signing was used
noqa: DAR202
Returns:
the recovered addresses
recover_public_keys_from_message
@classmethod
def 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
TOBEIMPLEMENTED
Arguments:
message: raw bytes used to produce signaturesignature: signature of the messageis_deprecated_mode: if the deprecated signing was used
noqa: DAR202
Returns:
the recovered public keys
generate_tx_nonce
@staticmethod
def generate_tx_nonce(seller: Address, client: Address) -> str
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.
to_transaction_format
@staticmethod
def to_transaction_format(tx: dict) -> Any
Check whether a transaction is valid or not.
to_dict_format
@staticmethod
def to_dict_format(tx) -> JSONLike
Check whether a transaction is valid or not.
Arguments:
tx: the transaction.
Returns:
True if the random_message is equals to tx['input']
get_contract_address
@staticmethod
def get_contract_address(tx_receipt: JSONLike) -> Optional[str]
Retrieve the contract_addresses from a transaction receipt.
Solana can have many contract addresses in one tx
Arguments:
tx_receipt: the receipt of the transaction.
Returns:
the contract address, if present
get_address_from_public_key
@classmethod
def get_address_from_public_key(cls, public_key: str) -> str
Get the address from the public key.
Arguments:
public_key: the public key
Returns:
str
is_valid_address
@classmethod
def is_valid_address(cls, address: str) -> bool
Check if the address is valid.
Arguments:
address: the address to validate
Returns:
whether the address is valid