arch

package
v0.0.0-...-56b3d09 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAction = errors.New("invalid action")
	// ErrInvalidActionId = errors.New("invalid action ID")
	// ErrInvalidTableId         = errors.New("invalid table ID")
	ErrCalldataIsNotTableRead = errors.New("calldata is not a table read operation")
)

Functions

func CanPopulateStruct

func CanPopulateStruct(dstType reflect.Type, srcType reflect.Type) error

CanPopulateStruct returns an error if it is not possible to populate a struct with the values returned by the Get<field name> methods in src.

func ConvertStruct

func ConvertStruct(dst interface{}, src interface{}) error

ConvertStruct copies the fields from src to dst if they have the same name and type. All fields in dst must be set.

func PopulateStruct

func PopulateStruct(dst interface{}, src interface{}) error

PopulateStruct sets all the fields in dst to the values returned by the Get<field name> methods in src.

func RunBlockTicks

func RunBlockTicks(c Core)

func RunSingleTick

func RunSingleTick(c Core)

Types

type Action

type Action interface{}

type ActionBatch

type ActionBatch struct {
	BlockNumber uint64
	Actions     []Action
}

Holds all the actions included to a specific core in a specific block

func NewActionBatch

func NewActionBatch(blockNumber uint64, actions []Action) ActionBatch

NewActionBatch creates a new ActionBatch instance.

func (ActionBatch) Len

func (a ActionBatch) Len() int

Len returns the number of actions in the batch.

type ActionSchema

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

type ActionSchemas

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

func NewActionSchemas

func NewActionSchemas(
	abi *abi.ABI,
	schemas []datamod.TableSchema,
	types map[string]reflect.Type,
) (ActionSchemas, error)

NewActionSchemas creates a new ActionSchemas instance.

func NewActionSchemasFromRaw

func NewActionSchemasFromRaw(
	abiJson string,
	schemasJson string,
	types map[string]reflect.Type,
) (ActionSchemas, error)

NewActionSchemasFromRaw creates a new ActionSchemas instance from raw JSON strings.

func (ActionSchemas) ABI

func (a ActionSchemas) ABI() *abi.ABI

ABI returns the ABI of the interface.

func (ActionSchemas) ActionIdFromAction

func (a ActionSchemas) ActionIdFromAction(action Action) (ValidActionId, bool)

ActionIdFromAction returns the action ID of the given action.

func (ActionSchemas) ActionIdFromName

func (a ActionSchemas) ActionIdFromName(name string) (ValidActionId, bool)

ActionIdFromName returns the action ID of the action with the given name.

func (*ActionSchemas) ActionToCalldata

func (a *ActionSchemas) ActionToCalldata(action Action) ([]byte, error)

ActionToCalldata converts an action to calldata. The same encoding is used for log data.

func (*ActionSchemas) ActionToLog

func (a *ActionSchemas) ActionToLog(action Action) (types.Log, error)

ActionToLog converts an action to a log.

func (*ActionSchemas) CalldataToAction

func (a *ActionSchemas) CalldataToAction(calldata []byte) (Action, error)

CalldataToAction converts calldata to an action.

func (*ActionSchemas) DecodeAction

func (a *ActionSchemas) DecodeAction(actionId ValidActionId, data []byte) (Action, error)

DecodeAction decodes the given calldata into an action.

func (*ActionSchemas) EncodeAction

func (a *ActionSchemas) EncodeAction(action Action) (ValidActionId, []byte, error)

EncodeAction encodes an action into a byte slice.

func (*ActionSchemas) ExecuteAction

func (a *ActionSchemas) ExecuteAction(action Action, target Core) error

ExecuteAction executes the given action on the given target.

func (ActionSchemas) GetActionSchema

func (a ActionSchemas) GetActionSchema(actionId ValidActionId) ActionSchema

GetActionSchema returns the schema of the action with the given ID.

func (*ActionSchemas) LogToAction

func (a *ActionSchemas) LogToAction(log types.Log) (Action, error)

LogToAction converts a log to an action.

func (ActionSchemas) NewActionId

func (a ActionSchemas) NewActionId(id RawIdType) (ValidActionId, bool)

NewActionId wraps a valid ID in a ValidActionId.

type ArchSchemas

type ArchSchemas struct {
	Actions ActionSchemas
	Tables  TableSchemas
}

type BaseCore

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

func (*BaseCore) BlockNumber

func (b *BaseCore) BlockNumber() uint64

func (*BaseCore) Datastore

func (b *BaseCore) Datastore() lib.Datastore

func (*BaseCore) ExpectTick

func (b *BaseCore) ExpectTick() bool

func (*BaseCore) InBlockTickIndex

func (b *BaseCore) InBlockTickIndex() uint64

func (*BaseCore) KV

func (b *BaseCore) KV() lib.KeyValueStore

func (*BaseCore) Rebasing

func (b *BaseCore) Rebasing() bool

func (*BaseCore) SetBlockNumber

func (b *BaseCore) SetBlockNumber(blockNumber uint64)

func (*BaseCore) SetInBlockTickIndex

func (b *BaseCore) SetInBlockTickIndex(index uint64)

func (*BaseCore) SetKV

func (b *BaseCore) SetKV(kv lib.KeyValueStore)

func (*BaseCore) SetRebasing

func (b *BaseCore) SetRebasing(rebasing bool)

func (*BaseCore) Tick

func (b *BaseCore) Tick()

func (*BaseCore) TicksPerBlock

func (b *BaseCore) TicksPerBlock() uint64

type CanonicalTickAction

type CanonicalTickAction struct{}

type Core

type Core interface {
	SetKV(kv lib.KeyValueStore) // Set the key-value store
	KV() lib.KeyValueStore      // Get the key-value store
	// ExecuteAction(Action) error // Execute the given action
	SetBlockNumber(uint64) // Set the block number
	BlockNumber() uint64   // Get the block number
	// RunSingleTick()             // Run a single tick
	// RunBlockTicks()             // Run all ticks in a block
	Tick()                      // Run a single tick
	TicksPerBlock() uint64      // Get the number of ticks per block
	ExpectTick() bool           // Check if a tick is expected
	SetInBlockTickIndex(uint64) // Set the in-block tick index
	InBlockTickIndex() uint64   // Get the in-block tick index
}

type ISetRebasing

type ISetRebasing interface {
	SetRebasing(bool)
}

type RawIdType

type RawIdType = [4]byte

type TableSchema

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

type TableSchemas

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

func NewTableSchemas

func NewTableSchemas(
	abi *abi.ABI,
	schemas []datamod.TableSchema,
	types map[string]reflect.Type,
	getters map[string]interface{},
) (TableSchemas, error)

NewTableSchemas creates a new TableSchemas instance.

func NewTableSchemasFromRaw

func NewTableSchemasFromRaw(
	abiJson string,
	schemasJson string,
	types map[string]reflect.Type,
	getters map[string]interface{},
) (TableSchemas, error)

NewTableSchemasFromRaw creates a new TableSchemas instance from raw JSON strings.

func (TableSchemas) ABI

func (a TableSchemas) ABI() *abi.ABI

ABI returns the ABI of the interface.

func (TableSchemas) GetTableSchema

func (t TableSchemas) GetTableSchema(tableId ValidTableId) TableSchema

GetTableSchema returns the schema of the table with the given ID.

func (TableSchemas) NewTableId

func (t TableSchemas) NewTableId(id RawIdType) (ValidTableId, bool)

NewTableId wraps a valid ID in a ValidTableId.

func (TableSchemas) Read

func (t TableSchemas) Read(datastore lib.Datastore, tableId ValidTableId, keys ...interface{}) (interface{}, error)

read reads a row from the datastore.

func (*TableSchemas) ReadPacked

func (t *TableSchemas) ReadPacked(datastore lib.Datastore, calldata []byte) ([]byte, error)

ReadPacked reads a row from the datastore and packs it into an ABI-encoded byte slice.

func (TableSchemas) TableIdFromName

func (t TableSchemas) TableIdFromName(name string) (ValidTableId, bool)

TableIdFromName returns the table ID for the given name, if valid.

func (*TableSchemas) TargetTableId

func (t *TableSchemas) TargetTableId(calldata []byte) (ValidTableId, bool)

TableIdFromCalldata returns the table ID of the table targeted by the given calldata. If the calldata does not encode a table read, the second return value is false.

type ValidActionId

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

func (ValidActionId) Raw

func (v ValidActionId) Raw() RawIdType

Raw returns the raw ID.

type ValidTableId

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

func (ValidTableId) Raw

func (v ValidTableId) Raw() RawIdType

Raw returns the raw ID.

Jump to

Keyboard shortcuts

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