ethrpc

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockNumberOrHash

type BlockNumberOrHash struct {
	BlockNumber *hexutil.Uint64 `json:"blockNumber,omitempty"`
	BlockHash   *common.Hash    `json:"blockHash,omitempty"`
}

BlockNumberOrHash represents a block number or hash parameter

func (*BlockNumberOrHash) UnmarshalJSON

func (b *BlockNumberOrHash) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling for block parameters Handles: "latest", "earliest", "pending", hex block numbers, and block hashes

type CallArgs

type CallArgs struct {
	From                 *common.Address `json:"from"`
	To                   *common.Address `json:"to"`
	Gas                  *hexutil.Uint64 `json:"gas"`
	GasPrice             *hexutil.Big    `json:"gasPrice"`
	MaxFeePerGas         *hexutil.Big    `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big    `json:"maxPriorityFeePerGas"`
	Value                *hexutil.Big    `json:"value"`
	Nonce                *hexutil.Uint64 `json:"nonce"`
	Data                 *hexutil.Bytes  `json:"data"`
	Input                *hexutil.Bytes  `json:"input"`
}

CallArgs represents the arguments to eth_call and eth_estimateGas

func (*CallArgs) GetData

func (args *CallArgs) GetData() []byte

GetData returns the input data, preferring 'input' over 'data' per EIP-2929

type Config

type Config struct {
	Enabled             bool          `yaml:"enabled" default:"false"`
	ChainID             uint64        `yaml:"chain_id" validate:"required_if=Enabled true"`
	RequestTimeout      time.Duration `yaml:"request_timeout"  default:"30s"`
	MinerInterval       time.Duration `yaml:"miner_interval"   default:"2s"`
	MinerMaxTxsPerBlock int           `yaml:"miner_max_txs_per_block" default:"500"`
	// SubmitterInterval controls how often the submitter drains pending
	// mempool entries by calling Canton. Kept tight by default so that
	// eth_sendRawTransaction → on-Canton latency stays close to Canton's
	// own commit time even though the HTTP call returns immediately.
	SubmitterInterval time.Duration `yaml:"submitter_interval" default:"500ms"`
	// SubmitterBatchSize caps the number of pending entries fetched in a
	// single submitter tick (0 = unlimited). Bounded so a backlog never
	// loads the entire pending queue into memory; the next tick picks up
	// whatever is left.
	SubmitterBatchSize int `yaml:"submitter_batch_size" default:"100"`
	// SubmitterConcurrency is the number of pending entries the submitter
	// processes in parallel within one tick. Canton commits typically take
	// 5-15s, so 10 parallel transfers give ~10x throughput vs sequential
	// without hammering Canton or saturating the gRPC connection.
	SubmitterConcurrency int `yaml:"submitter_concurrency" default:"10"`
}

Config contains Ethereum JSON-RPC facade settings for MetaMask compatibility

type EvmLog

type EvmLog struct {
	TxHash         []byte
	LogIndex       uint
	Address        []byte   // Contract address (20 bytes)
	Topics         [][]byte // Topic hashes (each 32 bytes)
	Data           []byte
	BlockNumber    uint64
	BlockHash      []byte
	TxIndex        uint
	Removed        bool
	BlockTimestamp uint64 // Unix seconds; set by the miner at block commit time
}

EvmLog represents a synthetic EVM log persisted for JSON-RPC responses.

type EvmTransaction

type EvmTransaction struct {
	TxHash       []byte
	FromAddress  string
	ToAddress    string
	Nonce        uint64
	Input        []byte
	ValueWei     string
	Status       uint8
	BlockNumber  uint64
	BlockHash    []byte
	TxIndex      uint
	GasUsed      uint64
	ErrorMessage string
}

EvmTransaction represents a synthetic EVM transaction persisted for JSON-RPC responses.

type FilterQuery

type FilterQuery struct {
	BlockHash *common.Hash    `json:"blockHash,omitempty"`
	FromBlock *hexutil.Uint64 `json:"fromBlock,omitempty"`
	ToBlock   *hexutil.Uint64 `json:"toBlock,omitempty"`
	Address   any             `json:"address,omitempty"` // single address or array
	Topics    []any           `json:"topics,omitempty"`
}

FilterQuery represents the filter for eth_getLogs

type MempoolEntry

type MempoolEntry struct {
	ID               int64
	TxHash           []byte // EVM transaction hash
	FromAddress      string // sender EVM address (hex)
	ContractAddress  string // ERC-20 contract address (hex); ToAddress in EVM tx
	RecipientAddress string // transfer target EVM address (hex); used in Transfer log
	Nonce            uint64
	Input            []byte // raw EVM calldata
	AmountData       []byte // big.Int.Bytes() of the transfer amount; used in Transfer log
	// Status is the lifecycle state observed when this record was loaded. For
	// entries returned by ClaimMempoolEntries it reflects the value the entry
	// held immediately before being sealed (completed or failed), so the miner
	// can synthesize the correct EVM transaction status (1 vs 0).
	Status       MempoolStatus
	ErrorMessage string // populated for failed entries; surfaced via the receipt
}

MempoolEntry is the intent log record written by SendRawTransaction, processed by the submitter, and consumed by the miner.

type MempoolStatus

type MempoolStatus string

MempoolStatus is the lifecycle state of a mempool intent entry.

const (
	MempoolPending   MempoolStatus = "pending"   // Canton transfer submitted, not yet confirmed
	MempoolCompleted MempoolStatus = "completed" // Canton transfer succeeded; awaiting miner
	MempoolFailed    MempoolStatus = "failed"    // Canton transfer failed
	MempoolMined     MempoolStatus = "mined"     // Included in a synthetic EVM block
)

type PendingBlock

type PendingBlock interface {
	Number() uint64
	Hash() []byte
	// ClaimMempoolEntries atomically marks up to maxTxsPerBlock completed
	// mempool entries as mined and returns them. This caps block size to
	// prevent excessively large blocks after traffic spikes or Canton downtime.
	ClaimMempoolEntries(ctx context.Context, maxTxsPerBlock int) ([]MempoolEntry, error)
	AddEvmTransaction(ctx context.Context, tx *EvmTransaction) error
	AddEvmLog(ctx context.Context, log *EvmLog) error
	Finalize(ctx context.Context) error
	Abort(ctx context.Context) error
}

PendingBlock represents an atomic context for constructing a synthetic EVM block. All writes are grouped in a single DB transaction that also holds an exclusive lock on the evm_state row, serializing concurrent miners automatically. Call Finalize to commit; Abort is a no-op after Finalize and is safe to defer.

type RPCBlock

type RPCBlock struct {
	Number           hexutil.Uint64   `json:"number"`
	Hash             common.Hash      `json:"hash"`
	ParentHash       common.Hash      `json:"parentHash"`
	Nonce            types.BlockNonce `json:"nonce"`
	Sha3Uncles       common.Hash      `json:"sha3Uncles"`
	LogsBloom        types.Bloom      `json:"logsBloom"`
	TransactionsRoot common.Hash      `json:"transactionsRoot"`
	StateRoot        common.Hash      `json:"stateRoot"`
	ReceiptsRoot     common.Hash      `json:"receiptsRoot"`
	Miner            common.Address   `json:"miner"`
	Difficulty       *hexutil.Big     `json:"difficulty"`
	TotalDifficulty  *hexutil.Big     `json:"totalDifficulty"`
	ExtraData        hexutil.Bytes    `json:"extraData"`
	Size             hexutil.Uint64   `json:"size"`
	GasLimit         hexutil.Uint64   `json:"gasLimit"`
	GasUsed          hexutil.Uint64   `json:"gasUsed"`
	Timestamp        hexutil.Uint64   `json:"timestamp"`
	Transactions     []any            `json:"transactions"`
	Uncles           []common.Hash    `json:"uncles"`
	BaseFeePerGas    *hexutil.Big     `json:"baseFeePerGas,omitempty"`
}

RPCBlock represents a block in JSON-RPC format

type RPCReceipt

type RPCReceipt struct {
	TransactionHash   common.Hash     `json:"transactionHash"`
	TransactionIndex  hexutil.Uint    `json:"transactionIndex"`
	BlockHash         common.Hash     `json:"blockHash"`
	BlockNumber       hexutil.Uint64  `json:"blockNumber"`
	From              common.Address  `json:"from"`
	To                *common.Address `json:"to"`
	CumulativeGasUsed hexutil.Uint64  `json:"cumulativeGasUsed"`
	GasUsed           hexutil.Uint64  `json:"gasUsed"`
	ContractAddress   *common.Address `json:"contractAddress"`
	Logs              []*types.Log    `json:"logs"`
	LogsBloom         types.Bloom     `json:"logsBloom"`
	Status            hexutil.Uint64  `json:"status"`
	EffectiveGasPrice hexutil.Uint64  `json:"effectiveGasPrice"`
	Type              hexutil.Uint64  `json:"type"`
	// RevertReason is a non-standard, optional, human-readable failure cause
	// surfaced for status=0 receipts. Real EVM nodes don't include this — the
	// reason is encoded in revert data — but our Canton-backed receipts have
	// no on-chain revert data to encode, so we expose the Canton error message
	// directly. Standard Ethereum clients ignore unknown fields; tools that
	// care (Loop wallet, our own scripts) can render the cause to the user.
	RevertReason string `json:"revertReason,omitempty"`
}

RPCReceipt represents a transaction receipt in JSON-RPC format

type RPCTransaction

type RPCTransaction struct {
	Hash             common.Hash     `json:"hash"`
	Nonce            hexutil.Uint64  `json:"nonce"`
	BlockHash        *common.Hash    `json:"blockHash"`
	BlockNumber      *hexutil.Uint64 `json:"blockNumber"`
	TransactionIndex *hexutil.Uint   `json:"transactionIndex"`
	From             common.Address  `json:"from"`
	To               *common.Address `json:"to"`
	Value            *hexutil.Big    `json:"value"`
	GasPrice         *hexutil.Big    `json:"gasPrice"`
	Gas              hexutil.Uint64  `json:"gas"`
	Input            hexutil.Bytes   `json:"input"`
	V                *hexutil.Big    `json:"v"`
	R                *hexutil.Big    `json:"r"`
	S                *hexutil.Big    `json:"s"`
	Type             hexutil.Uint64  `json:"type"`
	ChainID          *hexutil.Big    `json:"chainId,omitempty"`
}

RPCTransaction represents a transaction in JSON-RPC format

type SyncStatus

type SyncStatus struct {
	StartingBlock hexutil.Uint64 `json:"startingBlock"`
	CurrentBlock  hexutil.Uint64 `json:"currentBlock"`
	HighestBlock  hexutil.Uint64 `json:"highestBlock"`
}

SyncStatus represents the syncing status response

Directories

Path Synopsis
Package submitter drains pending mempool entries by submitting the corresponding ERC-20 transfer to Canton.
Package submitter drains pending mempool entries by submitting the corresponding ERC-20 transfer to Canton.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL