blocks

package
v0.0.0-...-af0e9f7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Open    BlockType = "open"
	Receive           = "receive"
	Send              = "send"
	Change            = "change"
)
View Source
const LiveGenesisBlockHash types.BlockHash = "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"
View Source
const LiveGenesisSourceHash types.BlockHash = "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"
View Source
const TestPrivateKey string = "34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4"

Variables

View Source
var GenesisAmount uint128.Uint128 = uint128.FromInts(0xffffffffffffffff, 0xffffffffffffffff)
View Source
var LiveGenesisBlock = FromJson([]byte(`{
	"type":           "open",
	"source":         "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA",
	"representative": "nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3",
	"account":        "nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3",
	"work":           "62f05417dd3fb691",
	"signature":      "9F0C933C8ADE004D808EA1985FA746A7E95BA2A38F867640F53EC8F180BDFE9E2C1268DEAD7C2664F356E37ABA362BC58E46DBA03E523A7B5A19E4B6EB12BB02"
}`)).(*OpenBlock)
View Source
var TestGenesisBlock = FromJson([]byte(`{
	"type": "open",
	"source": "B0311EA55708D6A53C75CDBF88300259C6D018522FE3D4D0A242E431F9E8B6D0",
	"representative": "nano_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo",
	"account": "nano_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo",
	"work": "9680625b39d3363d",
	"signature": "ECDA914373A2F0CA1296475BAEE40500A7F0A7AD72A5A80C81D7FAB7F6C802B2CC7DB50F5DD0FB25B2EF11761FA7344A158DD5A700B21BD47DE5BD0F63153A02"
}`)).(*OpenBlock)
View Source
var WorkThreshold = uint64(0xffffffc000000000)

Functions

func GenerateWork

func GenerateWork(b Block) types.Work

func GenerateWorkForHash

func GenerateWorkForHash(b types.BlockHash) types.Work

func HashBytes

func HashBytes(inputs ...[]byte) (result []byte)

func HashChange

func HashChange(previous types.BlockHash, representative types.Account) (result []byte)

func HashOpen

func HashOpen(source types.BlockHash, representative types.Account, account types.Account) (result []byte)

func HashReceive

func HashReceive(previous types.BlockHash, source types.BlockHash) (result []byte)

func HashSend

func HashSend(previous types.BlockHash, destination types.Account, balance uint128.Uint128) (result []byte)

func SignMessage

func SignMessage(private_key string, message []byte) (signature []byte)

func ValidateBlockWork

func ValidateBlockWork(b Block) bool

func ValidateWork

func ValidateWork(block_hash []byte, work []byte) bool

ValidateWork takes the "work" value (little endian from hex) and block hash and verifies that the work passes the difficulty. To verify this, we create a new 8 byte hash of the work and the block hash and convert this to a uint64 which must be higher (or equal) than the difficulty (0xffffffc000000000) to be valid.

Types

type Block

type Block interface {
	Type() BlockType
	GetSignature() types.Signature
	GetWork() types.Work
	RootHash() types.BlockHash
	Hash() types.BlockHash
	PreviousBlockHash() types.BlockHash
}

func FromJson

func FromJson(b []byte) (block Block)

type BlockType

type BlockType string

type ChangeBlock

type ChangeBlock struct {
	PreviousHash   types.BlockHash
	Representative types.Account
	CommonBlock
}

func (*ChangeBlock) Hash

func (b *ChangeBlock) Hash() types.BlockHash

func (*ChangeBlock) PreviousBlockHash

func (b *ChangeBlock) PreviousBlockHash() types.BlockHash

func (*ChangeBlock) RootHash

func (b *ChangeBlock) RootHash() types.BlockHash

func (*ChangeBlock) Type

func (*ChangeBlock) Type() BlockType

type CommonBlock

type CommonBlock struct {
	Work      types.Work
	Signature types.Signature
	Confirmed bool
}

func (*CommonBlock) GetSignature

func (b *CommonBlock) GetSignature() types.Signature

func (*CommonBlock) GetWork

func (b *CommonBlock) GetWork() types.Work

type OpenBlock

type OpenBlock struct {
	SourceHash     types.BlockHash
	Representative types.Account
	Account        types.Account
	CommonBlock
}

func (*OpenBlock) Hash

func (b *OpenBlock) Hash() types.BlockHash

func (*OpenBlock) PreviousBlockHash

func (b *OpenBlock) PreviousBlockHash() types.BlockHash

func (*OpenBlock) RootHash

func (b *OpenBlock) RootHash() types.BlockHash

func (*OpenBlock) Type

func (*OpenBlock) Type() BlockType

func (*OpenBlock) VerifySignature

func (b *OpenBlock) VerifySignature() (bool, error)

type RawBlock

type RawBlock struct {
	Type           BlockType
	Source         types.BlockHash
	Representative types.Account
	Account        types.Account
	Work           types.Work
	Signature      types.Signature
	Previous       types.BlockHash
	Balance        uint128.Uint128
	Destination    types.Account
}

func (RawBlock) Hash

func (b RawBlock) Hash() (result []byte)

func (RawBlock) HashToString

func (b RawBlock) HashToString() (result types.BlockHash)

type ReceiveBlock

type ReceiveBlock struct {
	PreviousHash types.BlockHash
	SourceHash   types.BlockHash
	CommonBlock
}

func (*ReceiveBlock) Hash

func (b *ReceiveBlock) Hash() types.BlockHash

func (*ReceiveBlock) PreviousBlockHash

func (b *ReceiveBlock) PreviousBlockHash() types.BlockHash

func (*ReceiveBlock) RootHash

func (b *ReceiveBlock) RootHash() types.BlockHash

func (*ReceiveBlock) Type

func (*ReceiveBlock) Type() BlockType

type SendBlock

type SendBlock struct {
	PreviousHash types.BlockHash
	Destination  types.Account
	Balance      uint128.Uint128
	CommonBlock
}

func (*SendBlock) Hash

func (b *SendBlock) Hash() types.BlockHash

func (*SendBlock) PreviousBlockHash

func (b *SendBlock) PreviousBlockHash() types.BlockHash

func (*SendBlock) RootHash

func (b *SendBlock) RootHash() types.BlockHash

func (*SendBlock) Type

func (*SendBlock) Type() BlockType

Jump to

Keyboard shortcuts

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