timestampvm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ID = ids.NewID([32]byte{'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() (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) CreateHandlers

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

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

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) Initialize

func (vm *VM) Initialize(
	ctx *snow.Context,
	db database.Database,
	genesisData []byte,
	toEngine chan<- common.Message,
	_ []*common.Fx,
) error

Initialize this vm [ctx] is this vm's context [db] is 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, 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