adapter

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

README

adapter

The adapter module provides interfaces and base implementations for integrating different rollup sequencer implementations with the Publisher SDK.

Overview

The adapter pattern allows different rollup technologies to implement their specific logic while maintaining compatibility with the shared publisher's 2PC protocol.

Architecture

adapter/
├── interfaces.go    # Core adapter interfaces
├── base.go         # Base implementation with defaults
└── README.md

Interfaces

SequencerAdapter

The main interface that rollup sequencers must implement:

type SequencerAdapter interface {
// Identity
Name() string
ChainID() string

// Message handling for sequencers
OnXTRequest(ctx context.Context, req *pb.XTRequest) error
OnDecision(ctx context.Context, decision *pb.Decided) error

// Sequencer actions
SendVote(ctx context.Context, xtID *pb.XtID, vote bool) error
SubmitBlock(ctx context.Context, block *pb.Block) error

// Lifecycle
Start(ctx context.Context) error
Stop(ctx context.Context) error
}
BaseAdapter

Provides default implementations for common functionality:

type BaseAdapter struct {
name    string
version string
chainID string
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// Name returns the unique identifier of the rollup implementation (e.g., "optimism").
	Name() string
	// Version returns the version string of the rollup implementation.
	Version() string
	// ChainID returns the blockchain identifier that this rollup instance
	// is configured to operate on.
	ChainID() string

	// HandleXTRequest processes an incoming cross-chain transaction request (XTRequest).
	// The 'from' parameter indicates the sender's identifier.
	HandleXTRequest(ctx context.Context, from string, req *pb.XTRequest) error

	// HandleVote processes an incoming 2PC vote message.
	// The 'from' parameter indicates the sender's identifier.
	HandleVote(ctx context.Context, from string, vote *pb.Vote) error

	// HandleDecision processes an incoming 2PC decision message (commit/abort).
	// The 'from' parameter indicates the sender's identifier.
	HandleDecision(ctx context.Context, from string, decision *pb.Decided) error

	// HandleBlock processes an incoming block submission.
	// The 'from' parameter indicates the sender's identifier.
	HandleBlock(ctx context.Context, from string, block *pb.Block) error

	// OnStart is a lifecycle hook called when the adapter is starting.
	// Implementations can use this for initialization logic.
	OnStart(ctx context.Context) error

	// OnStop is a lifecycle hook called when the adapter is stopping.
	// Implementations can use this for cleanup logic.
	OnStop(ctx context.Context) error
}

Adapter defines the interface for a rollup-specific implementation that integrates with the shared publisher. It provides methods for identifying the rollup and handling various types of messages received from the publisher.

type BaseAdapter

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

BaseAdapter provides a default, embeddable implementation of the Adapter interface. It is intended to be used by rollup implementations to reduce boilerplate code.

The BaseAdapter provides no-op implementations for the lifecycle hooks (OnStart, OnStop) and basic getters for identity fields. Rollup-specific logic, especially for message handling, must be implemented by the consuming type that embeds BaseAdapter.

func NewBaseAdapter

func NewBaseAdapter(name, version, chainID string) *BaseAdapter

NewBaseAdapter creates a new instance of BaseAdapter with the provided identity information (name, version, and chain ID).

func (*BaseAdapter) ChainID

func (b *BaseAdapter) ChainID() string

ChainID returns the chain ID that the rollup is configured to operate on.

func (*BaseAdapter) Name

func (b *BaseAdapter) Name() string

Name returns the identifier of the rollup implementation.

func (*BaseAdapter) OnStart

func (b *BaseAdapter) OnStart(ctx context.Context) error

OnStart is a no-op lifecycle hook. It is called when the adapter starts. By default, it returns nil. Implementers can override this method to add custom startup logic for their rollup adapter.

func (*BaseAdapter) OnStop

func (b *BaseAdapter) OnStop(ctx context.Context) error

OnStop is a no-op lifecycle hook. It is called when the adapter stops. By default, it returns nil. Implementers can override this method to add custom shutdown or cleanup logic for their rollup adapter.

func (*BaseAdapter) Version

func (b *BaseAdapter) Version() string

Version returns the version of the rollup implementation.

Jump to

Keyboard shortcuts

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