Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToData(input []byte) [DataLen]byte
- type Block
- func (b *Block) Accept(_ context.Context) error
- func (b *Block) Bytes() []byte
- func (b *Block) Data() []byte
- func (b *Block) Height() uint64
- func (b *Block) ID() ids.ID
- func (b *Block) Initialize(bytes []byte, status choices.Status, vm *VM)
- func (b *Block) Parent() ids.ID
- func (b *Block) Reject(_ context.Context) error
- func (b *Block) SetStatus(status choices.Status)
- func (b *Block) Status() choices.Status
- func (b *Block) Timestamp() time.Time
- func (b *Block) Verify(_ context.Context) error
- type BlockState
- type ChainSupply
- type Factory
- type GetBlockArgs
- type GetBlockReply
- type QueryDataArgs
- type Service
- type SingletonState
- type State
- type StaticService
- type VM
- func (*VM) AppGossip(_ context.Context, _ ids.NodeID, _ []byte) error
- func (*VM) AppRequest(_ context.Context, _ ids.NodeID, _ uint32, _ time.Time, _ []byte) error
- func (*VM) AppRequestFailed(_ context.Context, _ ids.NodeID, _ uint32) error
- func (*VM) AppResponse(_ context.Context, _ ids.NodeID, _ uint32, _ []byte) error
- func (vm *VM) BuildBlock(ctx context.Context) (snowman.Block, error)
- func (*VM) Connected(_ context.Context, _ ids.NodeID, _ *version.Application) error
- func (vm *VM) CreateHandlers(_ context.Context) (map[string]*common.HTTPHandler, error)
- func (*VM) CreateStaticHandlers(_ context.Context) (map[string]*common.HTTPHandler, error)
- func (*VM) CrossChainAppRequest(_ context.Context, _ ids.ID, _ uint32, _ time.Time, _ []byte) error
- func (*VM) CrossChainAppRequestFailed(_ context.Context, _ ids.ID, _ uint32) error
- func (*VM) CrossChainAppResponse(_ context.Context, _ ids.ID, _ uint32, _ []byte) error
- func (*VM) Disconnected(_ context.Context, _ ids.NodeID) error
- func (vm *VM) GetBlock(_ context.Context, blkID ids.ID) (snowman.Block, error)
- func (*VM) HealthCheck(_ context.Context) (interface{}, error)
- func (vm *VM) Initialize(ctx context.Context, snowCtx *snow.Context, dbManager manager.Manager, ...) error
- func (vm *VM) LastAccepted(_ context.Context) (ids.ID, error)
- func (vm *VM) NewBlock(parentID ids.ID, height uint64, data []byte, timestamp time.Time) (*Block, error)
- func (vm *VM) NotifyBlockReady()
- func (vm *VM) ParseBlock(_ context.Context, bytes []byte) (snowman.Block, error)
- func (vm *VM) SetPreference(_ context.Context, id ids.ID) error
- func (vm *VM) SetState(_ context.Context, state snow.State) error
- func (vm *VM) Shutdown(_ context.Context) error
- func (*VM) Version(_ context.Context) (string, error)
- type ValuePool
- type ZcashBlock
Constants ¶
const ( DataLen = 32 Name = "zcash" MaxMempoolSize = 4096 )
const (
// CodecVersion is the current default codec version
CodecVersion = 0
)
const (
IsInitializedKey byte = iota
)
Variables ¶
var (
Codec codec.Manager
)
Codecs do serialization and deserialization
var (
Version = &version.Semantic{
Major: 1,
Minor: 3,
Patch: 3,
}
)
Functions ¶
Types ¶
type Block ¶
type Block struct { 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. Tmstmp int64 `serialize:"true" json:"timestamp"` // Time this block was proposed at Dt []byte `serialize:"true" json:"data"` // Arbitrary data // contains filtered or unexported fields }
Block is a block on the chain. Each block contains: 1) ParentID 2) Height 3) Timestamp 4) A piece of data (a string)
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
func (*Block) Initialize ¶
Initialize sets [b.bytes] to bytes, [b.id] to hash([b.bytes]), [b.status] to [status] and [b.vm] to [vm]
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 BlockState ¶
type BlockState interface { GetBlock(blkID ids.ID) (*Block, error) GetBlockByHeight(ID uint64) (*Block, error) PutBlock(blk *Block) error GetLastAccepted() (ids.ID, error) SetLastAccepted(ids.ID) error QueryData(ID uint64) (ZcashBlock, error) }
BlockState defines methods to manage state with Blocks and LastAcceptedIDs.
func NewBlockState ¶
func NewBlockState(db database.Database, vm *VM) BlockState
NewBlockState returns BlockState with a new cache and given db
type ChainSupply ¶
type GetBlockArgs ¶
type GetBlockArgs struct { // ID of the block we're getting. // If left blank, gets the latest block ID *ids.ID `json:"id"` }
GetBlockArgs are the arguments to GetBlock
type GetBlockReply ¶
type GetBlockReply struct { Timestamp json.Uint64 `json:"timestamp"` // Timestamp of block Data ZcashBlock `json:"data"` // Data of zcash block Height json.Uint64 `json:"height"` // Height of block ID ids.ID `json:"id"` // String repr. of ID of block ParentID ids.ID `json:"parentID"` // String repr. of ID of block's parent }
GetBlockReply is the reply from GetBlock
type QueryDataArgs ¶
type QueryDataArgs struct {
ID uint64 `json:"id"`
}
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) GetBlockByHeight ¶
func (s *Service) GetBlockByHeight(_ *http.Request, args *QueryDataArgs, reply *GetBlockReply) error
GetBlock gets the block whose ID is [args.ID] If [args.ID] is empty, get the latest block
type SingletonState ¶
SingletonState is a thin wrapper around a database to provide, caching, serialization, and deserialization of singletons.
func NewSingletonState ¶
func NewSingletonState(db database.Database) SingletonState
type State ¶
type State interface { // SingletonState is defined in avalanchego, // it is used to understand if db is initialized already. SingletonState BlockState Commit() error Close() error }
State is a wrapper around avax.SingleTonState and BlockState State also exposes a few methods needed for managing database commits and close.
type StaticService ¶
type StaticService struct{}
StaticService defines the base service for the timestamp vm
type VM ¶
type VM struct {
// 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) AppRequest ¶
This VM doesn't (currently) have any app-specific messages
func (*VM) AppRequestFailed ¶
This VM doesn't (currently) have any app-specific messages
func (*VM) AppResponse ¶
This VM doesn't (currently) have any app-specific messages
func (*VM) BuildBlock ¶
BuildBlock returns a block that this vm wants to add to consensus
func (*VM) CreateHandlers ¶
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 ¶
CreateStaticHandlers returns a map where: Keys: The path extension for this VM's static API Values: The handler for that static API
func (*VM) CrossChainAppRequest ¶
func (*VM) CrossChainAppRequestFailed ¶
func (*VM) CrossChainAppResponse ¶
func (*VM) HealthCheck ¶
Health implements the common.VM interface
func (*VM) Initialize ¶
func (vm *VM) Initialize( ctx context.Context, snowCtx *snow.Context, dbManager manager.Manager, genesisData []byte, _ []byte, _ []byte, toEngine chan<- common.Message, _ []*common.Fx, _ common.AppSender, ) 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) LastAccepted ¶
LastAccepted returns the block most recently accepted
func (*VM) NewBlock ¶
func (vm *VM) NewBlock(parentID ids.ID, height uint64, data []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]
func (*VM) NotifyBlockReady ¶
func (vm *VM) NotifyBlockReady()
NotifyBlockReady tells the consensus engine that a new block is ready to be created
func (*VM) ParseBlock ¶
ParseBlock parses bytes to a snowman.Block This function is used by the vm's state to unmarshal blocks saved in state and by the consensus layer when it receives the byte representation of a block from another node
func (*VM) SetPreference ¶
SetPreference sets the block with ID [ID] as the preferred block
type ZcashBlock ¶
type ZcashBlock struct { Hash string `json:"hash"` Confirmations int `json:"confirmations"` Size int `json:"size"` Height int `json:"height"` Version int `json:"version"` MerkleRoot string `json:"merkleroot"` BlockCommitments string `json:"blockcommitments"` AuthDataRoot string `json:"authdataroot"` FinalSaplingRoot string `json:"finalsaplingroot"` ChainHistoryRoot string `json:"chainhistoryroot"` Tx []string `json:"tx"` Time int `json:"time"` Nonce string `json:"nonce"` Solution string `json:"solution"` Bits string `json:"bits"` Difficulty float64 `json:"difficulty"` ChainWork string `json:"chainwork"` Anchor string `json:"anchor"` ChainSupply ChainSupply `json:"chainSupply"` ValuePools []ValuePool `json:"valuePools"` PreviousBlockHash string `json:"previousblockhash"` NextBlockHash string `json:"nextblockhash"` }