goosecoin

package module
v0.0.0-...-e977d95 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mod

func Mod(data []byte, mod int64) int64

func RandaoID

func RandaoID(height uint64) string

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

Types

type Attestation

type Attestation struct {
	Validator Validator
	BlockHash Hash
	Signature []byte
}

type Attestations

type Attestations struct {
	Attestations map[[32]byte]Attestation
	// contains filtered or unexported fields
}

func NewAttestations

func NewAttestations() Attestations

func (*Attestations) Add

func (a *Attestations) Add(attestation Attestation)

func (*Attestations) Size

func (a *Attestations) Size() int

type Block

type Block struct {
	Hash        Hash
	HexHash     string
	Height      uint64
	PrevHash    Hash
	HexPrevHash string
	TimeStamp   time.Time
	Data        []Message

	Proposer  Validator
	Signature []byte

	Attestations Attestations `json:"-"`
	// contains filtered or unexported fields
}

func Genesis

func Genesis(t time.Time) *Block

func NewBlock

func NewBlock(prev *Block, data []Message) *Block

func (*Block) ComputeHash

func (block *Block) ComputeHash() Hash

type Hash

type Hash []byte

type HashRequest

type HashRequest struct {
	ID        string
	Validator ed25519.PublicKey
	Hash      []byte
	Signature []byte
}

type Message

type Message interface {
	Data() []byte
	Verify() bool
}

type Network

type Network struct {
	// TotalStake uint64
	Validators []Validator
}

func (*Network) NewServer

func (n *Network) NewServer(config ServerConfig) *Server

type Node

type Node struct {
	PublicKey  ed25519.PublicKey
	PrivateKey ed25519.PrivateKey

	Head     *Block
	Blocks   []*Block
	Messages []Message
	// contains filtered or unexported fields
}

func NewNode

func NewNode(n *Network) *Node

func NewNodeWithKey

func NewNodeWithKey(publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey, n *Network) *Node

func (*Node) AddBlock

func (n *Node) AddBlock(block *Block)

func (*Node) AddMessage

func (n *Node) AddMessage(m Message)

func (*Node) Mine

func (n *Node) Mine() *Block

func (*Node) Validator

func (n *Node) Validator() Validator

func (*Node) VerifyBlock

func (n *Node) VerifyBlock(block *Block) bool

type Randao

type Randao struct {
	ID       string
	OnFinish func(result []byte)

	Status     RandaoStatus
	Validators [][32]byte

	Hashs map[[32]byte][]byte

	Seeds map[[32]byte][]byte

	Result []byte
	// contains filtered or unexported fields
}

func (*Randao) AddHash

func (r *Randao) AddHash(req HashRequest) error

func (*Randao) AddSeed

func (r *Randao) AddSeed(req SeedRequest) error

func (*Randao) SendHash

func (r *Randao) SendHash()

func (*Randao) SendSeed

func (r *Randao) SendSeed()

type RandaoStatus

type RandaoStatus int64
const (
	RandaoStatusHash RandaoStatus = iota
	RandaoStatusSeed
	RandaoStatusFinished
)

type RawMessage

type RawMessage []byte

func (RawMessage) Data

func (m RawMessage) Data() []byte

func (RawMessage) Verify

func (m RawMessage) Verify() bool

type SeedRequest

type SeedRequest struct {
	ID        string
	Validator ed25519.PublicKey
	Seed      []byte
	Signature []byte
}

type Server

type Server struct {
	Config ServerConfig
	*Node
	Randaos      map[string]*Randao
	NextProposer Validator
	// contains filtered or unexported fields
}

func (*Server) Mine

func (s *Server) Mine()

func (*Server) NewRandao

func (s *Server) NewRandao(id string, onFinish func(result []byte)) *Randao

func (*Server) OnRandaoFinish

func (s *Server) OnRandaoFinish(result []byte)

func (*Server) Run

func (s *Server) Run()

type ServerConfig

type ServerConfig struct {
	Addr       string
	Peers      []string
	PublicKey  ed25519.PublicKey
	PrivateKey ed25519.PrivateKey
}

type Validator

type Validator struct {
	PublicKey ed25519.PublicKey
}

func (Validator) Key

func (v Validator) Key() [32]byte

func (Validator) Verify

func (v Validator) Verify(data []byte, signature []byte) bool

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

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