Documentation ¶
Index ¶
- type Block
- type Metadata
- type SnowmanState
- type SnowmanVM
- func (svm *SnowmanVM) Bootstrapped() error
- func (svm *SnowmanVM) Bootstrapping() error
- func (svm *SnowmanVM) DBInitialized() bool
- func (svm *SnowmanVM) GetBlock(ID ids.ID) (snowman.Block, error)
- func (svm *SnowmanVM) Initialize(ctx *snow.Context, db database.Database, ...) error
- func (svm *SnowmanVM) LastAccepted() ids.ID
- func (svm *SnowmanVM) NewHandler(name string, service interface{}, lockOption ...common.LockOption) *common.HTTPHandler
- func (svm *SnowmanVM) NotifyBlockReady()
- func (svm *SnowmanVM) ParseBlock(bytes []byte) (snowman.Block, error)
- func (svm *SnowmanVM) Preferred() ids.ID
- func (svm *SnowmanVM) SaveBlock(db database.Database, block snowman.Block) error
- func (svm *SnowmanVM) SetDBInitialized()
- func (svm *SnowmanVM) SetPreference(ID ids.ID)
- func (svm *SnowmanVM) Shutdown() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
Block contains fields and methods common to block's in a Snowman blockchain. Block is meant to be a building-block (pun intended). When you write a VM, your blocks can (and should) embed a core.Block to take care of some bioler-plate code. Block's methods can be over-written by structs that embed this struct.
func (*Block) Accept ¶
Accept sets this block's status to Accepted and sets lastAccepted to this block's ID and saves this info to b.vm.DB Recall that b.vm.DB.Commit() must be called to persist to the DB
func (*Block) Initialize ¶
Initialize sets [b.bytes] to bytes, sets [b.id] to hash([b.bytes]) Checks if [b]'s status is already stored in state. If so, [b] gets that status. Otherwise [b]'s status is Unknown.
func (*Block) Reject ¶
Reject sets this block's status to Rejected and saves the status in state Recall that b.vm.DB.Commit() must be called to persist to the DB
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata contains the data common to all blocks and transactions
func (*Metadata) Initialize ¶
Initialize sets [i.bytes] to bytes, sets [i.id] to a hash of [i.bytes] and sets [i.status] to choices.Processing
type SnowmanState ¶
type SnowmanState interface { state.State GetBlock(database.Database, ids.ID) (snowman.Block, error) PutBlock(database.Database, snowman.Block) error GetLastAccepted(database.Database) (ids.ID, error) PutLastAccepted(database.Database, ids.ID) error }
SnowmanState is a wrapper around state.State In additions to the methods exposed by state.State, SnowmanState exposes a few methods needed for managing state in a snowman vm
func NewSnowmanState ¶
NewSnowmanState returns a new SnowmanState
type SnowmanVM ¶
type SnowmanVM struct { State SnowmanState // VersionDB on top of underlying database // Important note: In order for writes to [DB] to be persisted, // DB.Commit() must be called // We use a versionDB here so user can do atomic commits as they see fit DB *versiondb.Database // The context of this vm Ctx *snow.Context // ID of the last accepted block LastAcceptedID ids.ID // channel to send messages to the consensus engine ToEngine chan<- common.Message // contains filtered or unexported fields }
SnowmanVM provides the core functionality shared by most snowman vms
func (*SnowmanVM) Bootstrapped ¶
Bootstrapped marks this VM as bootstrapped
func (*SnowmanVM) Bootstrapping ¶
Bootstrapping marks this VM as bootstrapping
func (*SnowmanVM) DBInitialized ¶
DBInitialized returns true iff [svm]'s database has values in it already
func (*SnowmanVM) Initialize ¶
func (svm *SnowmanVM) Initialize( ctx *snow.Context, db database.Database, unmarshalBlockFunc func([]byte) (snowman.Block, error), toEngine chan<- common.Message, ) error
Initialize this vm. If there is data in [db], sets [svm.lastAccepted] using data in the database, and sets [svm.preferred] to the last accepted block.
func (*SnowmanVM) LastAccepted ¶
LastAccepted returns the block most recently accepted
func (*SnowmanVM) NewHandler ¶
func (svm *SnowmanVM) NewHandler(name string, service interface{}, lockOption ...common.LockOption) *common.HTTPHandler
NewHandler returns a new Handler for a service where:
- The handler's functionality is defined by [service] [service] should be a gorilla RPC service (see https://www.gorillatoolkit.org/pkg/rpc/v2)
- The name of the service is [name]
- The LockOption is the first element of [lockOption] By default the LockOption is WriteLock [lockOption] should have either 0 or 1 elements. Elements beside the first are ignored.
func (*SnowmanVM) NotifyBlockReady ¶
func (svm *SnowmanVM) NotifyBlockReady()
NotifyBlockReady tells the consensus engine that a new block is ready to be created
func (*SnowmanVM) ParseBlock ¶
ParseBlock parses bytes to a block
func (*SnowmanVM) SetDBInitialized ¶
func (svm *SnowmanVM) SetDBInitialized()
SetDBInitialized marks the database as initialized
func (*SnowmanVM) SetPreference ¶
SetPreference sets the block with ID [ID] as the preferred block