rpc

package
v0.0.0-...-02745fe Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StandardTimeout        = 5 * time.Second // Standard timeout for RPC requests
	BlockQueryLimit uint64 = 256             // Maximum number of blocks to query in a single request
	HeaderChanSize         = 4               // Size of the header channel
)

Functions

func DampenLatency

func DampenLatency[T any](in <-chan T, out chan<- T, interval time.Duration, delay time.Duration)

DampenLatency dampens the latency of a channel by adding a delay to cushion latency variability.

Types

type ActionBatchSubscription

type ActionBatchSubscription struct {
	// contains filtered or unexported fields
}

ActionBatchSubscription is a subscription to action batches emitted by a core contract.

func SubscribeActionBatches

func SubscribeActionBatches(
	ethcli EthCli,
	actionSchemas arch.ActionSchemas,
	coreAddress common.Address,
	startingBlockNumber uint64,
	actionBatchesChan chan<- arch.ActionBatch,
	txHashesChan chan<- common.Hash,
) *ActionBatchSubscription

SubscribeActionBatches subscribes to action batches emitted by the core contract at coreAddress.

func (*ActionBatchSubscription) Err

func (s *ActionBatchSubscription) Err() <-chan error

Err returns the subscription error channel. Only one value will ever be sent. The error channel is closed by Unsubscribe.

func (*ActionBatchSubscription) Unsubscribe

func (s *ActionBatchSubscription) Unsubscribe()

Unsubscribe unsubscribes from the action batch subscription and closes the error channel. It does not close the action batch channel.

type ActionSender

type ActionSender struct {
	// contains filtered or unexported fields
}

ActionSender sends actions to a core contract.

func NewActionSender

func NewActionSender(
	ethcli EthCli,
	actionSchemas arch.ActionSchemas,
	gasEstimator ethereum.GasEstimator,
	contractAddress common.Address,
	from common.Address,
	nonce uint64,
	signerFn bind.SignerFn,
) *ActionSender

NewActionSender creates a new ActionSender.

func (*ActionSender) SendAction

func (a *ActionSender) SendAction(action arch.Action) (*types.Transaction, error)

SendAction sends and action to the contract.

func (*ActionSender) SendActions

func (a *ActionSender) SendActions(actionBatch []arch.Action) (*types.Transaction, error)

SendActions sends multiple actions to the contract in a single transaction.

func (*ActionSender) StartSendingActions

func (a *ActionSender) StartSendingActions(actionsChan <-chan []arch.Action, txUpdateChan chan<- *ActionTxUpdate) (<-chan error, func())

StartSendingActions starts sending actions from the given channel.

type ActionTxStatus

type ActionTxStatus uint8
const (
	ActionTxStatus_Unsent ActionTxStatus = iota
	ActionTxStatus_Pending
	ActionTxStatus_Included
	ActionTxStatus_Failed
)

func (*ActionTxStatus) String

func (c *ActionTxStatus) String() string

type ActionTxUpdate

type ActionTxUpdate struct {
	Actions []arch.Action
	TxHash  common.Hash
	Nonce   uint64
	Status  ActionTxStatus
	Err     error
}

type EthCli

type EthCli interface {
	bind.ContractBackend
	ethereum.ChainReader
	ethereum.ChainStateReader
	ethereum.PendingStateReader
	ethereum.LogFilterer
	ethereum.TransactionReader
	ethereum.TransactionSender
	BlockNumber(ctx context.Context) (uint64, error)
}

type IO

type IO struct {
	// contains filtered or unexported fields
}

func NewIO

func NewIO(
	ethcli EthCli,
	blockTime time.Duration,
	schemas arch.ArchSchemas,
	auth *bind.TransactOpts,
	gameAddress, coreAddress common.Address,
	startingBlockNumber uint64,
	dampenDelay time.Duration,
) *IO

NewIO creates a new IO.

func (*IO) ActionBatchOutChan

func (io *IO) ActionBatchOutChan() <-chan arch.ActionBatch

func (*IO) ActionInChan

func (io *IO) ActionInChan() chan<- []arch.Action

func (*IO) Hinter

func (io *IO) Hinter() *TxHinter

func (*IO) NewClient

func (io *IO) NewClient(
	kv lib.KeyValueStore,
	core arch.Core,
) *client.Client

Create a new client.Client using IO for sending and receiving transactions.

func (*IO) RegisterCancelFn

func (io *IO) RegisterCancelFn(fn func())

func (*IO) SetTxUpdateHook

func (io *IO) SetTxUpdateHook(fn func(*ActionTxUpdate))

func (*IO) Stop

func (io *IO) Stop()

type TableGetter

type TableGetter struct {
	// contains filtered or unexported fields
}

TableGetter reads a table from the core contract.

func NewTableReader

func NewTableReader(
	ethcli EthCli,
	tableSchemas arch.TableSchemas,
	coreAddress common.Address,
) *TableGetter

NewTableReader creates a new TableGetter.

func (*TableGetter) Read

func (t *TableGetter) Read(tableName string, keys ...interface{}) (interface{}, error)

ReadTable reads a table from the contract.

type TxHinter

type TxHinter struct {
	// contains filtered or unexported fields
}

func NewTxHinter

func NewTxHinter(ethcli EthCli, txUpdateChan <-chan *ActionTxUpdate) *TxHinter

NewTxHinter creates a new TxHinter. The TxHinter is used to get the actions sent by all monitored pending transactions.

func (*TxHinter) GetHints

func (txh *TxHinter) GetHints() (uint64, [][]arch.Action)

GetHints returns the actions sent by all monitored pending transactions.

func (*TxHinter) HintNonce

func (txh *TxHinter) HintNonce() uint64

HintNonce returns the nonce of the last hint. The hint is incremented every time the hints change.

func (*TxHinter) Start

func (txh *TxHinter) Start(updateInterval time.Duration)

Start starts updating the TxHinter at the given interval.

func (*TxHinter) Update

func (txh *TxHinter) Update() bool

Update triggers an update in the underlying TxMonitor.

type TxMonitor

type TxMonitor struct {
	// contains filtered or unexported fields
}

func NewTxMonitor

func NewTxMonitor(ethcli EthCli) *TxMonitor

NewTxMonitor creates a new TxMonitor. The TxMonitor is used to monitor the status of transactions. All included or stale transactions are discarded.

func (*TxMonitor) AddTxHash

func (txm *TxMonitor) AddTxHash(txHash common.Hash)

AddTxHash adds a transaction hash to be monitored.

func (*TxMonitor) HasTx

func (txm *TxMonitor) HasTx(txHash common.Hash) bool

HasTx returns whether a transaction is being monitored.

func (*TxMonitor) IsPending

func (txm *TxMonitor) IsPending(tx *types.Transaction) bool

IsPending returns whether a transaction is pending.

func (*TxMonitor) PendingTxs

func (txm *TxMonitor) PendingTxs() []common.Hash

PendingTxs returns the hash all of monitored transactions that are currently pending.

func (*TxMonitor) PendingTxsCount

func (txm *TxMonitor) PendingTxsCount() int

PendingTxsCount returns the number of transactions monitored that are currently pending.

func (*TxMonitor) RemoveTx

func (txm *TxMonitor) RemoveTx(txHash common.Hash)

RemoveTx removes a transaction hash from the monitor.

func (*TxMonitor) Update

func (txm *TxMonitor) Update() bool

Update triggers and update of the status of all monitored transactions.

Jump to

Keyboard shortcuts

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