mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package prism
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
// Prism consensus interface
|
|
type Prism interface {
|
|
// Initialize prism consensus
|
|
Initialize(context.Context, *Config) error
|
|
|
|
// Propose proposes a value
|
|
Propose(context.Context, []byte) error
|
|
|
|
// Vote votes on a proposal
|
|
Vote(context.Context, ids.ID, bool) error
|
|
|
|
// GetProposal gets a proposal
|
|
GetProposal(context.Context, ids.ID) (Proposal, error)
|
|
}
|
|
|
|
// NodeConfig defines prism node configuration
|
|
type NodeConfig struct {
|
|
ProposerNodes int
|
|
VoterNodes int
|
|
TransactionNodes int
|
|
BlockSize int
|
|
}
|
|
|
|
// Proposal defines a proposal
|
|
type Proposal struct {
|
|
ID ids.ID
|
|
Height uint64
|
|
Data []byte
|
|
Votes int
|
|
Accepted bool
|
|
}
|
|
|
|
// Engine defines prism consensus engine
|
|
type Engine struct {
|
|
config *Config
|
|
}
|
|
|
|
// New creates a new prism engine
|
|
func New(config *Config) *Engine {
|
|
return &Engine{
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
// Initialize initializes the engine
|
|
func (e *Engine) Initialize(ctx context.Context, config *Config) error {
|
|
e.config = config
|
|
return nil
|
|
}
|
|
|
|
// Propose proposes a value
|
|
func (e *Engine) Propose(ctx context.Context, data []byte) error {
|
|
return nil
|
|
}
|
|
|
|
// Vote votes on a proposal
|
|
func (e *Engine) Vote(ctx context.Context, proposalID ids.ID, accept bool) error {
|
|
return nil
|
|
}
|
|
|
|
// GetProposal gets a proposal
|
|
func (e *Engine) GetProposal(ctx context.Context, proposalID ids.ID) (Proposal, error) {
|
|
return Proposal{}, nil
|
|
}
|