blockrecord

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2019 License: ISC Imports: 8 Imported by: 2

Documentation

Overview

the structure of the block header

includes functions to pack/unpack []byte form

Index

Constants

View Source
const (
	Version            = 2
	MinimumVersion     = 1
	MinimumBlockNumber = 2 // 1 => genesis block
)

currently supported block version (used by proofer)

View Source
const (
	MinimumTransactions = 2
	MaximumTransactions = 10000
)

maximum transactions in a block limited by uint16 field

View Source
const (
	VersionSize          = 2                   // Block version number
	TransactionCountSize = 2                   // Count of transactions
	NumberSize           = 8                   // This block's number
	PreviousBlockSize    = blockdigest.Length  // 256-bit Argon2d hash of the previous block header
	MerkleRootSize       = merkle.DigestLength // 256-bit SHA3 hash based on all of the transactions in the block
	TimestampSize        = 8                   // Current timestamp as seconds since 1970-01-01T00:00 UTC
	DifficultySize       = 8                   // Current target difficulty in compact format
	NonceSize            = 8                   // 64-bit number (starts at 0)
)

byte sizes for various fields

Variables

This section is empty.

Functions

func FoundationTxId added in v0.7.0

func FoundationTxId(header *Header, digest blockdigest.Digest) merkle.Digest

create the foundation record its TxId is sha3-256 . concat blockDigest leBlockNumberUint64

Types

type Header struct {
	Version          uint16                 `json:"version"`
	TransactionCount uint16                 `json:"transactionCount"`
	Number           uint64                 `json:"number,string"`
	PreviousBlock    blockdigest.Digest     `json:"previousBlock"`
	MerkleRoot       merkle.Digest          `json:"merkleRoot"`
	Timestamp        uint64                 `json:"timestamp,string"`
	Difficulty       *difficulty.Difficulty `json:"difficulty"`
	Nonce            NonceType              `json:"nonce"`
}

the unpacked header structure the types here must match Bitcoin header types

func ExtractHeader added in v0.8.0

func ExtractHeader(block []byte) (*Header, blockdigest.Digest, []byte, error)

extract a header from the front of a []byte

func (*Header) Pack

func (header *Header) Pack() PackedHeader

turn a record into an array of bytes

type NonceType

type NonceType uint64

type for nonce

func (NonceType) MarshalText

func (nonce NonceType) MarshalText() ([]byte, error)

convert a nonce to little endian hex for JSON

func (*NonceType) UnmarshalText

func (nonce *NonceType) UnmarshalText(b []byte) error

convert a nonce little endian hex string to nonce value

type PackedBlock

type PackedBlock []byte

packed records are just a byte slice

type PackedHeader

type PackedHeader [totalBlockSize]byte

use fix size array to simplify validation

func (PackedHeader) Digest

func (record PackedHeader) Digest() blockdigest.Digest

digest for a packed header make sure to truncate bytes to correct length

func (PackedHeader) Unpack

func (record PackedHeader) Unpack() (*Header, error)

turn a byte slice into a record

Jump to

Keyboard shortcuts

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