anvil::eth::api

Struct EthApi

Source
pub struct EthApi {
    pool: Arc<Pool>,
    pub backend: Arc<Backend>,
    is_mining: bool,
    signers: Arc<Vec<Box<dyn Signer>>>,
    fee_history_cache: FeeHistoryCache,
    fee_history_limit: u64,
    miner: Miner,
    logger: LoggingManager,
    filters: Filters,
    transaction_order: Arc<RwLock<TransactionOrder>>,
    net_listening: bool,
    instance_id: Arc<RwLock<B256>>,
}
Expand description

The entry point for executing eth api RPC call - The Eth RPC interface.

This type is cheap to clone and can be used concurrently

Fields§

§pool: Arc<Pool>

The transaction pool

§backend: Arc<Backend>

Holds all blockchain related data In-Memory only for now

§is_mining: bool

Whether this node is mining

§signers: Arc<Vec<Box<dyn Signer>>>

available signers

§fee_history_cache: FeeHistoryCache

data required for eth_feeHistory

§fee_history_limit: u64

max number of items kept in fee cache

§miner: Miner

access to the actual miner

This access is required in order to adjust miner settings based on requests received from custom RPC endpoints

§logger: LoggingManager

allows to enabled/disable logging

§filters: Filters

Tracks all active filters

§transaction_order: Arc<RwLock<TransactionOrder>>

How transactions are ordered in the pool

§net_listening: bool

Whether we’re listening for RPC calls

§instance_id: Arc<RwLock<B256>>

The instance ID. Changes on every reset.

Implementations§

Source§

impl EthApi

Source

pub fn new( pool: Arc<Pool>, backend: Arc<Backend>, signers: Arc<Vec<Box<dyn Signer>>>, fee_history_cache: FeeHistoryCache, fee_history_limit: u64, miner: Miner, logger: LoggingManager, filters: Filters, transactions_order: TransactionOrder, ) -> Self

Creates a new instance

Source

pub async fn execute(&self, request: EthRequest) -> ResponseResult

Executes the [EthRequest] and returns an RPC [ResponseResult].

Source

fn sign_request( &self, from: &Address, request: TypedTransactionRequest, ) -> Result<TypedTransaction, BlockchainError>

Source

async fn block_request( &self, block_number: Option<BlockId>, ) -> Result<BlockRequest, BlockchainError>

Source

async fn inner_raw_transaction( &self, hash: B256, ) -> Result<Option<Bytes>, BlockchainError>

Source

pub fn client_version(&self) -> Result<String, BlockchainError>

Returns the current client version.

Handler for ETH RPC call: web3_clientVersion

Source

pub fn sha3(&self, bytes: Bytes) -> Result<String, BlockchainError>

Returns Keccak-256 (not the standardized SHA3-256) of the given data.

Handler for ETH RPC call: web3_sha3

Source

pub fn protocol_version(&self) -> Result<u64, BlockchainError>

Returns protocol version encoded as a string (quotes are necessary).

Handler for ETH RPC call: eth_protocolVersion

Source

pub fn hashrate(&self) -> Result<U256, BlockchainError>

Returns the number of hashes per second that the node is mining with.

Handler for ETH RPC call: eth_hashrate

Source

pub fn author(&self) -> Result<Address, BlockchainError>

Returns the client coinbase address.

Handler for ETH RPC call: eth_coinbase

Source

pub fn is_mining(&self) -> Result<bool, BlockchainError>

Returns true if client is actively mining new blocks.

Handler for ETH RPC call: eth_mining

Source

pub fn eth_chain_id(&self) -> Result<Option<U64>, BlockchainError>

Returns the chain ID used for transaction signing at the current best block. None is returned if not available.

Handler for ETH RPC call: eth_chainId

Source

pub fn network_id(&self) -> Result<Option<String>, BlockchainError>

Returns the same as chain_id

Handler for ETH RPC call: eth_networkId

Source

pub fn net_listening(&self) -> Result<bool, BlockchainError>

Returns true if client is actively listening for network connections.

Handler for ETH RPC call: net_listening

Source

fn eth_gas_price(&self) -> Result<U256, BlockchainError>

Returns the current gas price

Source

pub fn gas_price(&self) -> u128

Returns the current gas price

Source

pub fn excess_blob_gas_and_price( &self, ) -> Result<Option<BlobExcessGasAndPrice>, BlockchainError>

Returns the excess blob gas and current blob gas price

Source

pub fn gas_max_priority_fee_per_gas(&self) -> Result<U256, BlockchainError>

Returns a fee per gas that is an estimate of how much you can pay as a priority fee, or ‘tip’, to get a transaction included in the current block.

Handler for ETH RPC call: eth_maxPriorityFeePerGas

Source

pub fn blob_base_fee(&self) -> Result<U256, BlockchainError>

Returns the base fee per blob required to send a EIP-4844 tx.

Handler for ETH RPC call: eth_blobBaseFee

Source

pub fn gas_limit(&self) -> U256

Returns the block gas limit

Source

pub fn accounts(&self) -> Result<Vec<Address>, BlockchainError>

Returns the accounts list

Handler for ETH RPC call: eth_accounts

Source

pub fn block_number(&self) -> Result<U256, BlockchainError>

Returns the number of most recent block.

Handler for ETH RPC call: eth_blockNumber

Source

pub async fn balance( &self, address: Address, block_number: Option<BlockId>, ) -> Result<U256, BlockchainError>

Returns balance of the given account.

Handler for ETH RPC call: eth_getBalance

Source

pub async fn get_account( &self, address: Address, block_number: Option<BlockId>, ) -> Result<Account, BlockchainError>

Returns the ethereum account.

Handler for ETH RPC call: eth_getAccount

Source

pub async fn storage_at( &self, address: Address, index: U256, block_number: Option<BlockId>, ) -> Result<B256, BlockchainError>

Returns content of the storage at given address.

Handler for ETH RPC call: eth_getStorageAt

Source

pub async fn block_by_hash( &self, hash: B256, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Returns block with given hash.

Handler for ETH RPC call: eth_getBlockByHash

Source

pub async fn block_by_hash_full( &self, hash: B256, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Returns a full block with given hash.

Handler for ETH RPC call: eth_getBlockByHash

Source

pub async fn block_by_number( &self, number: BlockNumber, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Returns block with given number.

Handler for ETH RPC call: eth_getBlockByNumber

Source

pub async fn block_by_number_full( &self, number: BlockNumber, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Returns a full block with given number

Handler for ETH RPC call: eth_getBlockByNumber

Source

pub async fn transaction_count( &self, address: Address, block_number: Option<BlockId>, ) -> Result<U256, BlockchainError>

Returns the number of transactions sent from given address at given time (block number).

Also checks the pending transactions if block_number is BlockId::Number(BlockNumber::Pending)

Handler for ETH RPC call: eth_getTransactionCount

Source

pub async fn block_transaction_count_by_hash( &self, hash: B256, ) -> Result<Option<U256>, BlockchainError>

Returns the number of transactions in a block with given hash.

Handler for ETH RPC call: eth_getBlockTransactionCountByHash

Source

pub async fn block_transaction_count_by_number( &self, block_number: BlockNumber, ) -> Result<Option<U256>, BlockchainError>

Returns the number of transactions in a block with given block number.

Handler for ETH RPC call: eth_getBlockTransactionCountByNumber

Source

pub async fn block_uncles_count_by_hash( &self, hash: B256, ) -> Result<U256, BlockchainError>

Returns the number of uncles in a block with given hash.

Handler for ETH RPC call: eth_getUncleCountByBlockHash

Source

pub async fn block_uncles_count_by_number( &self, block_number: BlockNumber, ) -> Result<U256, BlockchainError>

Returns the number of uncles in a block with given block number.

Handler for ETH RPC call: eth_getUncleCountByBlockNumber

Source

pub async fn get_code( &self, address: Address, block_number: Option<BlockId>, ) -> Result<Bytes, BlockchainError>

Returns the code at given address at given time (block number).

Handler for ETH RPC call: eth_getCode

Source

pub async fn get_proof( &self, address: Address, keys: Vec<B256>, block_number: Option<BlockId>, ) -> Result<EIP1186AccountProofResponse, BlockchainError>

Returns the account and storage values of the specified account including the Merkle-proof. This call can be used to verify that the data you are pulling from is not tampered with.

Handler for ETH RPC call: eth_getProof

Source

pub async fn sign_typed_data( &self, _address: Address, _data: Value, ) -> Result<String, BlockchainError>

Signs data via EIP-712.

Handler for ETH RPC call: eth_signTypedData

Source

pub async fn sign_typed_data_v3( &self, _address: Address, _data: Value, ) -> Result<String, BlockchainError>

Signs data via EIP-712.

Handler for ETH RPC call: eth_signTypedData_v3

Source

pub async fn sign_typed_data_v4( &self, address: Address, data: &TypedData, ) -> Result<String, BlockchainError>

Signs data via EIP-712, and includes full support of arrays and recursive data structures.

Handler for ETH RPC call: eth_signTypedData_v4

Source

pub async fn sign( &self, address: Address, content: impl AsRef<[u8]>, ) -> Result<String, BlockchainError>

The sign method calculates an Ethereum specific signature

Handler for ETH RPC call: eth_sign

Source

pub async fn sign_transaction( &self, request: WithOtherFields<TransactionRequest>, ) -> Result<String, BlockchainError>

Signs a transaction

Handler for ETH RPC call: eth_signTransaction

Source

pub async fn send_transaction( &self, request: WithOtherFields<TransactionRequest>, ) -> Result<TxHash, BlockchainError>

Sends a transaction

Handler for ETH RPC call: eth_sendTransaction

Source

pub async fn send_raw_transaction( &self, tx: Bytes, ) -> Result<TxHash, BlockchainError>

Sends signed transaction, returning its hash.

Handler for ETH RPC call: eth_sendRawTransaction

Source

pub async fn call( &self, request: WithOtherFields<TransactionRequest>, block_number: Option<BlockId>, overrides: Option<StateOverride>, ) -> Result<Bytes, BlockchainError>

Call contract, returning the output data.

Handler for ETH RPC call: eth_call

Source

pub async fn create_access_list( &self, request: WithOtherFields<TransactionRequest>, block_number: Option<BlockId>, ) -> Result<AccessListResult, BlockchainError>

This method creates an EIP2930 type accessList based on a given Transaction. The accessList contains all storage slots and addresses read and written by the transaction, except for the sender account and the precompiles.

It returns list of addresses and storage keys used by the transaction, plus the gas consumed when the access list is added. That is, it gives you the list of addresses and storage keys that will be used by that transaction, plus the gas consumed if the access list is included. Like eth_estimateGas, this is an estimation; the list could change when the transaction is actually mined. Adding an accessList to your transaction does not necessary result in lower gas usage compared to a transaction without an access list.

Handler for ETH RPC call: eth_createAccessList

Source

pub async fn estimate_gas( &self, request: WithOtherFields<TransactionRequest>, block_number: Option<BlockId>, overrides: Option<StateOverride>, ) -> Result<U256, BlockchainError>

Estimate gas needed for execution of given contract. If no block parameter is given, it will use the pending block by default

Handler for ETH RPC call: eth_estimateGas

Source

pub async fn transaction_by_hash( &self, hash: B256, ) -> Result<Option<AnyRpcTransaction>, BlockchainError>

Get transaction by its hash.

This will check the storage for a matching transaction, if no transaction exists in storage this will also scan the mempool for a matching pending transaction

Handler for ETH RPC call: eth_getTransactionByHash

Source

pub async fn transaction_by_block_hash_and_index( &self, hash: B256, index: Index, ) -> Result<Option<AnyRpcTransaction>, BlockchainError>

Returns transaction at given block hash and index.

Handler for ETH RPC call: eth_getTransactionByBlockHashAndIndex

Source

pub async fn transaction_by_block_number_and_index( &self, block: BlockNumber, idx: Index, ) -> Result<Option<AnyRpcTransaction>, BlockchainError>

Returns transaction by given block number and index.

Handler for ETH RPC call: eth_getTransactionByBlockNumberAndIndex

Source

pub async fn transaction_receipt( &self, hash: B256, ) -> Result<Option<ReceiptResponse>, BlockchainError>

Returns transaction receipt by transaction hash.

Handler for ETH RPC call: eth_getTransactionReceipt

Source

pub async fn block_receipts( &self, number: BlockId, ) -> Result<Option<Vec<ReceiptResponse>>, BlockchainError>

Returns block receipts by block number.

Handler for ETH RPC call: eth_getBlockReceipts

Source

pub async fn uncle_by_block_hash_and_index( &self, block_hash: B256, idx: Index, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Returns an uncles at given block and index.

Handler for ETH RPC call: eth_getUncleByBlockHashAndIndex

Source

pub async fn uncle_by_block_number_and_index( &self, block_number: BlockNumber, idx: Index, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Returns an uncles at given block and index.

Handler for ETH RPC call: eth_getUncleByBlockNumberAndIndex

Source

pub async fn logs(&self, filter: Filter) -> Result<Vec<Log>, BlockchainError>

Returns logs matching given filter object.

Handler for ETH RPC call: eth_getLogs

Source

pub fn work(&self) -> Result<Work, BlockchainError>

Returns the hash of the current block, the seedHash, and the boundary condition to be met.

Handler for ETH RPC call: eth_getWork

Source

pub fn syncing(&self) -> Result<bool, BlockchainError>

Returns the sync status, always be fails.

Handler for ETH RPC call: eth_syncing

Source

pub fn submit_work( &self, _: B64, _: B256, _: B256, ) -> Result<bool, BlockchainError>

Used for submitting a proof-of-work solution.

Handler for ETH RPC call: eth_submitWork

Source

pub fn submit_hashrate(&self, _: U256, _: B256) -> Result<bool, BlockchainError>

Used for submitting mining hashrate.

Handler for ETH RPC call: eth_submitHashrate

Source

pub async fn fee_history( &self, block_count: U256, newest_block: BlockNumber, reward_percentiles: Vec<f64>, ) -> Result<FeeHistory, BlockchainError>

Introduced in EIP-1559 for getting information on the appropriate priority fee to use.

Handler for ETH RPC call: eth_feeHistory

Source

pub fn max_priority_fee_per_gas(&self) -> Result<U256, BlockchainError>

Introduced in EIP-1159, a Geth-specific and simplified priority fee oracle. Leverages the already existing fee history cache.

Returns a suggestion for a gas tip cap for dynamic fee transactions.

Handler for ETH RPC call: eth_maxPriorityFeePerGas

Source

fn lowest_suggestion_tip(&self) -> u128

Returns the suggested fee cap.

Returns at least MIN_SUGGESTED_PRIORITY_FEE

Source

pub async fn new_filter( &self, filter: Filter, ) -> Result<String, BlockchainError>

Creates a filter object, based on filter options, to notify when the state changes (logs).

Handler for ETH RPC call: eth_newFilter

Source

pub async fn new_block_filter(&self) -> Result<String, BlockchainError>

Creates a filter in the node, to notify when a new block arrives.

Handler for ETH RPC call: eth_newBlockFilter

Source

pub async fn new_pending_transaction_filter( &self, ) -> Result<String, BlockchainError>

Creates a filter in the node, to notify when new pending transactions arrive.

Handler for ETH RPC call: eth_newPendingTransactionFilter

Source

pub async fn get_filter_changes(&self, id: &str) -> ResponseResult

Polling method for a filter, which returns an array of logs which occurred since last poll.

Handler for ETH RPC call: eth_getFilterChanges

Source

pub async fn get_filter_logs( &self, id: &str, ) -> Result<Vec<Log>, BlockchainError>

Returns an array of all logs matching filter with given id.

Handler for ETH RPC call: eth_getFilterLogs

Source

pub async fn uninstall_filter(&self, id: &str) -> Result<bool, BlockchainError>

Handler for ETH RPC call: eth_uninstallFilter

Source

pub async fn raw_transaction( &self, hash: B256, ) -> Result<Option<Bytes>, BlockchainError>

Returns EIP-2718 encoded raw transaction

Handler for RPC call: debug_getRawTransaction

Source

pub async fn raw_transaction_by_block_hash_and_index( &self, block_hash: B256, index: Index, ) -> Result<Option<Bytes>, BlockchainError>

Returns EIP-2718 encoded raw transaction by block hash and index

Handler for RPC call: eth_getRawTransactionByBlockHashAndIndex

Source

pub async fn raw_transaction_by_block_number_and_index( &self, block_number: BlockNumber, index: Index, ) -> Result<Option<Bytes>, BlockchainError>

Returns EIP-2718 encoded raw transaction by block number and index

Handler for RPC call: eth_getRawTransactionByBlockNumberAndIndex

Source

pub async fn debug_trace_transaction( &self, tx_hash: B256, opts: GethDebugTracingOptions, ) -> Result<GethTrace, BlockchainError>

Returns traces for the transaction hash for geth’s tracing endpoint

Handler for RPC call: debug_traceTransaction

Source

pub async fn debug_trace_call( &self, request: WithOtherFields<TransactionRequest>, block_number: Option<BlockId>, opts: GethDebugTracingCallOptions, ) -> Result<GethTrace, BlockchainError>

Returns traces for the transaction for geth’s tracing endpoint

Handler for RPC call: debug_traceCall

Source

pub async fn trace_transaction( &self, tx_hash: B256, ) -> Result<Vec<LocalizedTransactionTrace>, BlockchainError>

Returns traces for the transaction hash via parity’s tracing endpoint

Handler for RPC call: trace_transaction

Source

pub async fn trace_block( &self, block: BlockNumber, ) -> Result<Vec<LocalizedTransactionTrace>, BlockchainError>

Returns traces for the transaction hash via parity’s tracing endpoint

Handler for RPC call: trace_block

Source

pub async fn trace_filter( &self, filter: TraceFilter, ) -> Result<Vec<LocalizedTransactionTrace>, BlockchainError>

Returns filtered traces over blocks

Handler for RPC call: trace_filter

Source§

impl EthApi

Source

pub async fn anvil_impersonate_account( &self, address: Address, ) -> Result<(), BlockchainError>

Send transactions impersonating specific account and contract addresses.

Handler for ETH RPC call: anvil_impersonateAccount

Source

pub async fn anvil_stop_impersonating_account( &self, address: Address, ) -> Result<(), BlockchainError>

Stops impersonating an account if previously set with anvil_impersonateAccount.

Handler for ETH RPC call: anvil_stopImpersonatingAccount

Source

pub async fn anvil_auto_impersonate_account( &self, enabled: bool, ) -> Result<(), BlockchainError>

If set to true will make every account impersonated

Handler for ETH RPC call: anvil_autoImpersonateAccount

Source

pub fn anvil_get_auto_mine(&self) -> Result<bool, BlockchainError>

Returns true if auto mining is enabled, and false.

Handler for ETH RPC call: anvil_getAutomine

Source

pub fn anvil_get_interval_mining(&self) -> Result<Option<u64>, BlockchainError>

Returns the value of mining interval, if set.

Handler for ETH RPC call: anvil_getIntervalMining.

Source

pub async fn anvil_set_auto_mine( &self, enable_automine: bool, ) -> Result<(), BlockchainError>

Enables or disables, based on the single boolean argument, the automatic mining of new blocks with each new transaction submitted to the network.

Handler for ETH RPC call: evm_setAutomine

Source

pub async fn anvil_mine( &self, num_blocks: Option<U256>, interval: Option<U256>, ) -> Result<(), BlockchainError>

Mines a series of blocks.

Handler for ETH RPC call: anvil_mine

Source

pub fn anvil_set_interval_mining( &self, secs: u64, ) -> Result<(), BlockchainError>

Sets the mining behavior to interval with the given interval (seconds)

Handler for ETH RPC call: evm_setIntervalMining

Source

pub async fn anvil_drop_transaction( &self, tx_hash: B256, ) -> Result<Option<B256>, BlockchainError>

Removes transactions from the pool

Handler for RPC call: anvil_dropTransaction

Source

pub async fn anvil_drop_all_transactions(&self) -> Result<(), BlockchainError>

Removes all transactions from the pool

Handler for RPC call: anvil_dropAllTransactions

Source

pub async fn anvil_reset( &self, forking: Option<Forking>, ) -> Result<(), BlockchainError>

Reset the fork to a fresh forked state, and optionally update the fork config.

If forking is None then this will disable forking entirely.

Handler for RPC call: anvil_reset

Source

pub async fn anvil_set_chain_id( &self, chain_id: u64, ) -> Result<(), BlockchainError>

Source

pub async fn anvil_set_balance( &self, address: Address, balance: U256, ) -> Result<(), BlockchainError>

Modifies the balance of an account.

Handler for RPC call: anvil_setBalance

Source

pub async fn anvil_set_code( &self, address: Address, code: Bytes, ) -> Result<(), BlockchainError>

Sets the code of a contract.

Handler for RPC call: anvil_setCode

Source

pub async fn anvil_set_nonce( &self, address: Address, nonce: U256, ) -> Result<(), BlockchainError>

Sets the nonce of an address.

Handler for RPC call: anvil_setNonce

Source

pub async fn anvil_set_storage_at( &self, address: Address, slot: U256, val: B256, ) -> Result<bool, BlockchainError>

Writes a single slot of the account’s storage.

Handler for RPC call: anvil_setStorageAt

Source

pub async fn anvil_set_logging( &self, enable: bool, ) -> Result<(), BlockchainError>

Enable or disable logging.

Handler for RPC call: anvil_setLoggingEnabled

Source

pub async fn anvil_set_min_gas_price( &self, gas: U256, ) -> Result<(), BlockchainError>

Set the minimum gas price for the node.

Handler for RPC call: anvil_setMinGasPrice

Source

pub async fn anvil_set_next_block_base_fee_per_gas( &self, basefee: U256, ) -> Result<(), BlockchainError>

Sets the base fee of the next block.

Handler for RPC call: anvil_setNextBlockBaseFeePerGas

Source

pub async fn anvil_set_coinbase( &self, address: Address, ) -> Result<(), BlockchainError>

Sets the coinbase address.

Handler for RPC call: anvil_setCoinbase

Source

pub async fn anvil_dump_state( &self, preserve_historical_states: Option<bool>, ) -> Result<Bytes, BlockchainError>

Create a buffer that represents all state on the chain, which can be loaded to separate process by calling anvil_loadState

Handler for RPC call: anvil_dumpState

Source

pub async fn serialized_state( &self, preserve_historical_states: bool, ) -> Result<SerializableState, BlockchainError>

Returns the current state

Source

pub async fn anvil_load_state( &self, buf: Bytes, ) -> Result<bool, BlockchainError>

Append chain state buffer to current chain. Will overwrite any conflicting addresses or storage.

Handler for RPC call: anvil_loadState

Source

pub async fn anvil_node_info(&self) -> Result<NodeInfo, BlockchainError>

Retrieves the Anvil node configuration params.

Handler for RPC call: anvil_nodeInfo

Source

pub async fn anvil_metadata(&self) -> Result<Metadata, BlockchainError>

Retrieves metadata about the Anvil instance.

Handler for RPC call: anvil_metadata

Source

pub async fn anvil_remove_pool_transactions( &self, address: Address, ) -> Result<(), BlockchainError>

Source

pub async fn anvil_reorg( &self, options: ReorgOptions, ) -> Result<(), BlockchainError>

Reorg the chain to a specific depth and mine new blocks back to the canonical height.

e.g depth = 3 A -> B -> C -> D -> E A -> B -> C’ -> D’ -> E’

Depth specifies the height to reorg the chain back to. Depth must not exceed the current chain height, i.e. can’t reorg past the genesis block.

Optionally supply a list of transaction and block pairs that will populate the reorged blocks. The maximum block number of the pairs must not exceed the specified depth.

Handler for RPC call: anvil_reorg

Source

pub async fn evm_snapshot(&self) -> Result<U256, BlockchainError>

Snapshot the state of the blockchain at the current block.

Handler for RPC call: evm_snapshot

Source

pub async fn evm_revert(&self, id: U256) -> Result<bool, BlockchainError>

Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to.

Handler for RPC call: evm_revert

Source

pub async fn evm_increase_time( &self, seconds: U256, ) -> Result<i64, BlockchainError>

Jump forward in time by the given amount of time, in seconds.

Handler for RPC call: evm_increaseTime

Source

pub fn evm_set_next_block_timestamp( &self, seconds: u64, ) -> Result<(), BlockchainError>

Similar to evm_increaseTime but takes the exact timestamp that you want in the next block

Handler for RPC call: evm_setNextBlockTimestamp

Source

pub fn evm_set_time(&self, timestamp: u64) -> Result<u64, BlockchainError>

Sets the specific timestamp and returns the number of seconds between the given timestamp and the current time.

Handler for RPC call: evm_setTime

Source

pub fn evm_set_block_gas_limit( &self, gas_limit: U256, ) -> Result<bool, BlockchainError>

Set the next block gas limit

Handler for RPC call: evm_setBlockGasLimit

Source

pub fn evm_set_block_timestamp_interval( &self, seconds: u64, ) -> Result<(), BlockchainError>

Sets an interval for the block timestamp

Handler for RPC call: anvil_setBlockTimestampInterval

Source

pub fn evm_remove_block_timestamp_interval( &self, ) -> Result<bool, BlockchainError>

Sets an interval for the block timestamp

Handler for RPC call: anvil_removeBlockTimestampInterval

Source

pub async fn evm_mine( &self, opts: Option<MineOptions>, ) -> Result<String, BlockchainError>

Mine blocks, instantly.

Handler for RPC call: evm_mine

This will mine the blocks regardless of the configured mining mode. Note: ganache returns 0x0 here as placeholder for additional meta-data in the future.

Source

pub async fn evm_mine_detailed( &self, opts: Option<MineOptions>, ) -> Result<Vec<AnyRpcBlock>, BlockchainError>

Mine blocks, instantly and return the mined blocks.

Handler for RPC call: evm_mine_detailed

This will mine the blocks regardless of the configured mining mode.

Note: This behaves exactly as Self::evm_mine but returns different output, for compatibility reasons, this is a separate call since evm_mine is not an anvil original. and ganache may change the 0x0 placeholder.

Source

pub fn anvil_set_block(&self, block_number: U256) -> Result<(), BlockchainError>

Sets the reported block number

Handler for ETH RPC call: anvil_setBlock

Source

pub fn anvil_set_rpc_url(&self, url: String) -> Result<(), BlockchainError>

Sets the backend rpc url

Handler for ETH RPC call: anvil_setRpcUrl

Source

pub async fn anvil_enable_traces(&self) -> Result<(), BlockchainError>

Turn on call traces for transactions that are returned to the user when they execute a transaction (instead of just txhash/receipt)

Handler for ETH RPC call: anvil_enableTraces

Source

pub async fn eth_send_unsigned_transaction( &self, request: WithOtherFields<TransactionRequest>, ) -> Result<TxHash, BlockchainError>

Execute a transaction regardless of signature status

Handler for ETH RPC call: eth_sendUnsignedTransaction

Source

pub async fn txpool_status(&self) -> Result<TxpoolStatus, BlockchainError>

Returns the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. Ref: Here

Handler for ETH RPC call: txpool_status

Source

pub async fn txpool_inspect(&self) -> Result<TxpoolInspect, BlockchainError>

Returns a summary of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only.

See here for more details

Handler for ETH RPC call: txpool_inspect

Source

pub async fn txpool_content( &self, ) -> Result<TxpoolContent<AnyRpcTransaction>, BlockchainError>

Returns the details of all transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only.

See here for more details

Handler for ETH RPC call: txpool_inspect

Source§

impl EthApi

Source

pub fn get_capabilities(&self) -> Result<WalletCapabilities, BlockchainError>

Get the capabilities of the wallet.

See also EIP-5792.

Source

pub async fn wallet_send_transaction( &self, request: WithOtherFields<TransactionRequest>, ) -> Result<TxHash, BlockchainError>

Source

pub fn anvil_add_capability( &self, address: Address, ) -> Result<(), BlockchainError>

Add an address to the delegation capability of wallet.

This entails that the executor will now be able to sponsor transactions to this address.

Source

pub fn anvil_set_executor( &self, executor_pk: String, ) -> Result<Address, BlockchainError>

Source§

impl EthApi

Source

async fn on_blocking_task<C, F, R>(&self, c: C) -> Result<R, BlockchainError>
where C: FnOnce(Self) -> F, F: Future<Output = Result<R, BlockchainError>> + Send + 'static, R: Send + 'static,

Executes the future on a new blocking task.

Source

async fn do_evm_mine( &self, opts: Option<MineOptions>, ) -> Result<u64, BlockchainError>

Executes the evm_mine and returns the number of blocks mined

Source

async fn do_estimate_gas( &self, request: WithOtherFields<TransactionRequest>, block_number: Option<BlockId>, overrides: Option<StateOverride>, ) -> Result<u128, BlockchainError>

Source

fn do_estimate_gas_with_state( &self, request: WithOtherFields<TransactionRequest>, state: &dyn DatabaseRef<Error = DatabaseError>, block_env: BlockEnv, ) -> Result<u128, BlockchainError>

Estimates the gas usage of the request with the state.

This will execute the transaction request and find the best gas limit via binary search.

Source

pub fn set_transaction_order(&self, order: TransactionOrder)

Updates the TransactionOrder

Source

fn transaction_priority(&self, tx: &TypedTransaction) -> TransactionPriority

Returns the priority of the transaction based on the current TransactionOrder

Source

pub fn chain_id(&self) -> u64

Returns the chain ID used for transaction

Source

pub fn get_fork(&self) -> Option<ClientFork>

Returns the configured fork, if any.

Source

pub fn instance_id(&self) -> B256

Returns the current instance’s ID.

Source

pub fn reset_instance_id(&self)

Resets the instance ID.

Source

pub fn get_signer(&self, address: Address) -> Option<&Box<dyn Signer>>

Returns the first signer that can sign for the given address

Source

pub fn new_block_notifications(&self) -> NewBlockNotifications

Returns a new block event stream that yields Notifications when a new block was added

Source

pub fn new_ready_transactions(&self) -> Receiver<TxHash>

Returns a new listeners for ready transactions

Source

pub fn storage_info(&self) -> StorageInfo

Returns a new accessor for certain storage elements

Source

pub fn is_fork(&self) -> bool

Returns true if forked

Source

pub async fn mine_one(&self)

Mines exactly one block

Source

async fn pending_block(&self) -> AnyRpcBlock

Returns the pending block with tx hashes

Source

async fn pending_block_full(&self) -> Option<AnyRpcBlock>

Returns the full pending block with Transaction objects

Source

fn build_typed_tx_request( &self, request: WithOtherFields<TransactionRequest>, nonce: u64, ) -> Result<TypedTransactionRequest, BlockchainError>

Source

pub fn is_impersonated(&self, addr: Address) -> bool

Returns true if the addr is currently impersonated

Source

fn impersonated_signature(&self, request: &TypedTransactionRequest) -> Signature

The signature used to bypass signing via the eth_sendUnsignedTransaction cheat RPC

Source

async fn get_transaction_count( &self, address: Address, block_number: Option<BlockId>, ) -> Result<u64, BlockchainError>

Returns the nonce of the address depending on the block_number

Source

async fn request_nonce( &self, request: &TransactionRequest, from: Address, ) -> Result<(u64, u64), BlockchainError>

Returns the nonce for this request

This returns a tuple of (request nonce, highest nonce) If the nonce field of the request is None then the tuple will be (highest nonce, highest nonce).

This will also check the tx pool for pending transactions from the sender.

Source

fn add_pending_transaction( &self, pending_transaction: PendingTransaction, requires: Vec<TxMarker>, provides: Vec<TxMarker>, ) -> Result<TxHash, BlockchainError>

Adds the given transaction to the pool

Source

pub async fn state_root(&self) -> Option<B256>

Returns the current state root

Source

fn ensure_typed_transaction_supported( &self, tx: &TypedTransaction, ) -> Result<(), BlockchainError>

additional validation against hardfork

Source§

impl EthApi

Source

pub async fn erigon_get_header_by_number( &self, number: BlockNumber, ) -> Result<Option<AnyRpcBlock>, BlockchainError>

Otterscan currently requires this endpoint, even though it’s not part of the ots_*. Ref: https://github.com/otterscan/otterscan/blob/071d8c55202badf01804f6f8d53ef9311d4a9e47/src/useProvider.ts#L71

As a faster alternative to eth_getBlockByNumber (by excluding uncle block information), which is not relevant in the context of an anvil node

Source

pub async fn ots_get_api_level(&self) -> Result<u64, BlockchainError>

As per the latest Otterscan source code, at least version 8 is needed. Ref: https://github.com/otterscan/otterscan/blob/071d8c55202badf01804f6f8d53ef9311d4a9e47/src/params.ts#L1C2-L1C2

Source

pub async fn ots_get_internal_operations( &self, hash: B256, ) -> Result<Vec<InternalOperation>, BlockchainError>

Trace internal ETH transfers, contracts creation (CREATE/CREATE2) and self-destructs for a certain transaction.

Source

pub async fn ots_has_code( &self, address: Address, block_number: BlockNumber, ) -> Result<bool, BlockchainError>

Check if an ETH address contains code at a certain block number.

Source

pub async fn ots_trace_transaction( &self, hash: B256, ) -> Result<Vec<TraceEntry>, BlockchainError>

Trace a transaction and generate a trace call tree.

Source

pub async fn ots_get_transaction_error( &self, hash: B256, ) -> Result<Bytes, BlockchainError>

Given a transaction hash, returns its raw revert reason.

Source

pub async fn ots_get_block_details( &self, number: BlockNumber, ) -> Result<BlockDetails<AnyRpcHeader>, BlockchainError>

For simplicity purposes, we return the entire block instead of emptying the values that Otterscan doesn’t want. This is the original purpose of the endpoint (to save bandwidth), but it doesn’t seem necessary in the context of an anvil node

Source

pub async fn ots_get_block_details_by_hash( &self, hash: B256, ) -> Result<BlockDetails<AnyRpcHeader>, BlockchainError>

For simplicity purposes, we return the entire block instead of emptying the values that Otterscan doesn’t want. This is the original purpose of the endpoint (to save bandwidth), but it doesn’t seem necessary in the context of an anvil node

Source

pub async fn ots_get_block_transactions( &self, number: u64, page: usize, page_size: usize, ) -> Result<OtsBlockTransactions<AnyRpcTransaction, AnyRpcHeader>, BlockchainError>

Gets paginated transaction data for a certain block. Return data is similar to eth_getBlockBy* + eth_getTransactionReceipt.

Source

pub async fn ots_search_transactions_before( &self, address: Address, block_number: u64, page_size: usize, ) -> Result<TransactionsWithReceipts<Transaction<AnyTxEnvelope>>, BlockchainError>

Address history navigation. searches backwards from certain point in time.

Source

pub async fn ots_search_transactions_after( &self, address: Address, block_number: u64, page_size: usize, ) -> Result<TransactionsWithReceipts<Transaction<AnyTxEnvelope>>, BlockchainError>

Address history navigation. searches forward from certain point in time.

Source

pub async fn ots_get_transaction_by_sender_and_nonce( &self, address: Address, nonce: U256, ) -> Result<Option<B256>, BlockchainError>

Given a sender address and a nonce, returns the tx hash or null if not found. It returns only the tx hash on success, you can use the standard eth_getTransactionByHash after that to get the full transaction data.

Source

pub async fn ots_get_contract_creator( &self, addr: Address, ) -> Result<Option<ContractCreator>, BlockchainError>

Given an ETH contract address, returns the tx hash and the direct address who created the contract.

Source

pub async fn build_ots_block_details( &self, block: AnyRpcBlock, ) -> Result<BlockDetails<Header<AnyHeader>>, BlockchainError>

The response for ots_getBlockDetails includes an issuance object that requires computing the total gas spent in a given block.

The only way to do this with the existing API is to explicitly fetch all receipts, to get their gas_used. This would be extremely inefficient in a real blockchain RPC, but we can get away with that in this context.

The original spec also mentions we can hardcode transactions and logsBloom to an empty array to save bandwidth, because fields weren’t intended to be used in the Otterscan UI at this point.

This has two problems though:

  • It makes the endpoint too specific to Otterscan’s implementation
  • It breaks the abstraction built in OtsBlock<TX> which computes transaction_count based on the existing list.

Therefore we keep it simple by keeping the data in the response

Source

pub async fn build_ots_block_tx( &self, block: AnyRpcBlock, page: usize, page_size: usize, ) -> Result<OtsBlockTransactions<AnyRpcTransaction, AnyRpcHeader>, BlockchainError>

Fetches all receipts for the blocks’s transactions, as required by the ots_getBlockTransactions endpoint spec, and returns the final response object.

Source

pub async fn build_ots_search_transactions( &self, hashes: Vec<B256>, first_page: bool, last_page: bool, ) -> Result<TransactionsWithReceipts<Transaction<AnyTxEnvelope>>, BlockchainError>

Trait Implementations§

Source§

impl Clone for EthApi

Source§

fn clone(&self) -> EthApi

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for EthApi

§

impl !RefUnwindSafe for EthApi

§

impl Send for EthApi

§

impl Sync for EthApi

§

impl Unpin for EthApi

§

impl !UnwindSafe for EthApi

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> DynClone for T
where T: Clone,

§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
§

impl<T> Paint for T
where T: ?Sized,

§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color::Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color::Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color::White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightWhite].

§Example
println!("{}", value.bright_white());
§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color::Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color::Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color::White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling [Attribute] value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute::Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute::RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Strike].

§Example
println!("{}", value.strike());
§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi [Quirk] value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Linger].

§Example
println!("{}", value.linger());
§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk::Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::OnBright].

§Example
println!("{}", value.on_bright());
§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the [Condition] value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> TryClone for T
where T: Clone,

§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 136 bytes