timestampvm

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: BSD-3-Clause Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ID = ids.ID{'t', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p'}
)

ID is a unique identifier for this VM

Functions

This section is empty.

Types

type APIBlock

type APIBlock struct {
	Timestamp json.Uint64 `json:"timestamp"` // Timestamp of most recent block
	Data      string      `json:"data"`      // Data in the most recent block. Base 58 repr. of 5 bytes.
	ID        string      `json:"id"`        // String repr. of ID of the most recent block
	ParentID  string      `json:"parentID"`  // String repr. of ID of the most recent block's parent
}

APIBlock is the API representation of a block

type Block

type Block struct {
	*core.Block `serialize:"true"`
	Data        [dataLen]byte `serialize:"true"`
	Timestamp   int64         `serialize:"true"`
}

Block is a block on the chain. Each block contains: 1) A piece of data (a string) 2) A timestamp

func (*Block) Verify

func (b *Block) Verify() error

Verify returns nil iff this block is valid. To be valid, it must be that: b.parent.Timestamp < b.Timestamp <= [local time] + 1 hour

type Factory

type Factory struct{}

Factory ...

func (*Factory) New

func (f *Factory) New(*snow.Context) (interface{}, error)

New ...

type GetBlockArgs

type GetBlockArgs struct {
	// ID of the block we're getting.
	// If left blank, gets the latest block
	ID string
}

GetBlockArgs are the arguments to GetBlock

type GetBlockReply

type GetBlockReply struct {
	APIBlock
}

GetBlockReply is the reply from GetBlock

type ProposeBlockArgs

type ProposeBlockArgs struct {
	// Data in the block. Must be base 58 encoding of 32 bytes.
	Data string `json:"data"`
}

ProposeBlockArgs are the arguments to function ProposeValue

type ProposeBlockReply

type ProposeBlockReply struct{ Success bool }

ProposeBlockReply is the reply from function ProposeBlock

type Service

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

Service is the API service for this VM

func (*Service) GetBlock

func (s *Service) GetBlock(_ *http.Request, args *GetBlockArgs, reply *GetBlockReply) error

GetBlock gets the block whose ID is [args.ID] If [args.ID] is empty, get the latest block

func (*Service) ProposeBlock

func (s *Service) ProposeBlock(_ *http.Request, args *ProposeBlockArgs, reply *ProposeBlockReply) error

ProposeBlock is an API method to propose a new block whose data is [args].Data. [args].Data must be a string repr. of a 32 byte array

type VM

type VM struct {
	core.SnowmanVM
	// contains filtered or unexported fields
}

VM implements the snowman.VM interface Each block in this chain contains a Unix timestamp and a piece of data (a string)

func (*VM) BuildBlock

func (vm *VM) BuildBlock() (snowman.Block, error)

BuildBlock returns a block that this vm wants to add to consensus

func (*VM) Connected added in v1.4.9

func (vm *VM) Connected(id ids.ShortID) error

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers() (map[string]*common.HTTPHandler, error)

CreateHandlers returns a map where: Keys: The path extension for this VM's API (empty in this case) Values: The handler for the API

func (*VM) CreateStaticHandlers

func (vm *VM) CreateStaticHandlers() (map[string]*common.HTTPHandler, error)

CreateStaticHandlers returns a map where: Keys: The path extension for this VM's static API Values: The handler for that static API We return nil because this VM has no static API

func (*VM) Disconnected added in v1.4.9

func (vm *VM) Disconnected(id ids.ShortID) error

func (*VM) HealthCheck

func (vm *VM) HealthCheck() (interface{}, error)

Health implements the common.VM interface

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx *snow.Context,
	dbManager manager.Manager,
	genesisData []byte,
	upgradeData []byte,
	configData []byte,
	toEngine chan<- common.Message,
	_ []*common.Fx,
) error

Initialize this vm [ctx] is this vm's context [dbManager] is the manager of this vm's database [toEngine] is used to notify the consensus engine that new blocks are

ready to be added to consensus

The data in the genesis block is [genesisData]

func (*VM) NewBlock

func (vm *VM) NewBlock(parentID ids.ID, height uint64, data [dataLen]byte, timestamp time.Time) (*Block, error)

NewBlock returns a new Block where: - the block's parent is [parentID] - the block's data is [data] - the block's timestamp is [timestamp] The block is persisted in storage

func (*VM) ParseBlock

func (vm *VM) ParseBlock(bytes []byte) (snowman.Block, error)

ParseBlock parses bytes to a snowman.Block This function is used by the vm's state to unmarshal blocks saved in state

Jump to

Keyboard shortcuts

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