Crate cido_ethereum

Source
Expand description

§Cido Ethereum

The ethereum implementation of the cido crate.

§Ethereum specific functionality

This crate exports a procedural macro called ethereum_contract that can be used to annotate unit structs. The following is an example of how to use the macro.

// A module should contain the macro as all the structs representing all the events and
// functions in this contract are created in the same namespace as the contract struct.
mod uniswap_v3 {
  pub const UNISWAP_V3_FACTORY: H160 =
      H160::from_hex_str("0x1F98431c8aD98523631AE4a59f267346ea31F984");

  #[ethereum_contract(
    // (required) path to abi json file from the directory that contains Cargo.toml
    source = "../abis/uniswap_v3_factory.json",
    // Events from the contract that we're interested in
    events = [PoolCreated],
    // Order of processing. If set to 1 then address is also required. If 2 or 3 then
    // the filters for following these events will need to be created in a generator
    order = 1,
    // Address of the contract if known. For now it only takes identifiers so a const will
    // need to be created that can be used here
    address = UNISWAP_V3_FACTORY,
  )]
  // The unit struct. This will have some internal fields added
  pub struct UniswapV3Factory;
}

The struct annotated with #[ethereum_contract(...)] will have all the functions from the abi added to it. They can be called after creating an instead of the struct by calling bind

async fn handle_event(cx: Context<'_, Uniswap>, meta: MetaEvent<Uniswap>) -> Result<(), UniswapError> {
  let factory = UniswapV3Factory::bind(cx.network(), meta.block_number(), UNISWAP_V3_FACTORY);
  let first_pair = factory.allPairs(0).await?;
}

A complete working example of using cido to index all of the uniswap-v2 events is in the examples folder under uniswap-v2.

Re-exports§

pub use cido::prelude::*;

Modules§

prelude

Structs§

AccessListItem
Represents an AccessListItem for a transaction
BlockHeader
The header of a block
BlockQuery
Struct that allows querying blocks from a node
Call
Call response
CallResult
Call Result
CallTrigger
Trigger returned when a call is matched
Create
Create response
CreateResult
Craete Result
EthCallArgs
Arguments required to make an eth_call
EthereumBlock
Implementation of a block for ethereum
EthereumBlockNumber
Represents the block height of a block. Valid range is 0..2**40
EthereumBlockNumberRange
Implementation of the BlockNumberRange trait for ethereum
EthereumCall
Represents the result of a function call on the block chain
EthereumCallFilter
Filter to emit a CallTrigger as an event for handling
EthereumError
Error returned by public functions. None of these are recoverable in handler code.
EthereumEventOrder
Implementation of the EventOrder trait for ethereum
EthereumInitConfig
Configuration for specifying rpc nodes, etc. for ethereum compatible networks
EthereumLogFilter
Matches any log that matches both the address (if specified) and event signature.
EthereumNetwork
Implementation of the Network trait for ethereum
EthereumTriggerGenerator
implementation of the TriggerGenerator trait for ethereum
FullBlockQuery
Struct that allows querying full blocks from a node
Log
Represents a log emitted by a contract
LogTrigger
Event emitted by a Log or AllLogs EthereumFilter
Receipt
Represents the result of a transaction once complete
Reward
Reward action
Suicide
Suicide
Trace
Trace-Filtering API trace type
Transaction
Represents a transaction within a block
TransactionTrigger
Event emitted by a matching Transaction or AllTransactions EthereumFilter
Void
Used to indicate that a transaction has no receipt information

Enums§

Action
Action
EthereumBlockFilter
Filters available to a block
EthereumBlockId
Different ways to refer to a block
EthereumEventIndex
Digestable information about an EthereumEventOrder
EthereumFilter
Filters supported by the Network implementation
EthereumTransactionFilter
Filters available to transactions
EthereumTrigger
All types of triggers available to this crate
Res
Response for call or create

Traits§

ReceiptData
Trait to indicate whether receipt data is included in the transaction data
TransactionData
Allows for a Block to be generic over how much transaction data it carries.

Type Aliases§

AbiAddress
Alias to H160
AbiHash
Alias to H256
AbiInt
Alias to U256
AbiUint
Alias to U256
H64
H64 wrapper for [u8; 8]
H160
H160 wrapper for [u8; 20]
H256
H256 wrapper for [u8; 32]
H512
H512 wrapper for [u8; 64]
H2048
H2048 wrapper for [u8; 256]
ReceiptBlock
Alias for EthereumBlock<Transaction<Receipt>> or a block that contains all transaction and receipt data
ReceiptTransaction
Alias for Transaction<Receipt> or a transaction that contains receipt data
TransactionBlock
Alias for EthereumBlock<Transaction<Void>> or a block that contains all transaction data but no receipt data
TransactionIdBlock
Alias for EthereumBlock<H256> or a block that contains only transaction hashes
U64
Alias to U<1>
U256
Alias to U<4>

Attribute Macros§

ethereum_contract
Proc macro for creating types and functions to interact with a contract from a json abi file