Documentation ¶
Index ¶
- type Block
- func (b *Block) Accept() error
- func (b *Block) Height() uint64
- func (b *Block) Initialize(bytes []byte, vm *SnowmanVM)
- func (b *Block) Parent() snowman.Block
- func (b *Block) ParentID() ids.ID
- func (b *Block) Reject() error
- func (b *Block) Status() choices.Status
- func (b *Block) Verify() (bool, error)
- 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, error)
- func (svm *SnowmanVM) NewHandler(name string, service interface{}, lockOption ...common.LockOption) (*common.HTTPHandler, error)
- 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() error
- func (svm *SnowmanVM) SetPreference(id ids.ID) error
- func (svm *SnowmanVM) Shutdown() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { Metadata PrntID ids.ID `serialize:"true" json:"parentID"` // parent's ID Hght uint64 `serialize:"true" json:"height"` // This block's height. The genesis block is at height 0. VM *SnowmanVM }
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) Height ¶ added in v0.8.0
Height returns this block's height. The genesis block has height 0.
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 ¶ added in v0.8.0
Bootstrapped marks this VM as bootstrapped
func (*SnowmanVM) Bootstrapping ¶ added in v0.8.0
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, error)
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 ¶
SetDBInitialized marks the database as initialized
func (*SnowmanVM) SetPreference ¶
SetPreference sets the block with ID [ID] as the preferred block