luckyblock

package module
v0.0.0-...-6cbf7e5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxScore = uint64(^uint32(0))
)

Variables

View Source
var BlockComparator spec.BlockComparator = func(blocks []spec.Block) spec.Block {

	if len(blocks) == 0 {
		return nil
	}
	if len(blocks) == 1 {
		return blocks[0]
	}

	result := make([]spec.Block, len(blocks))
	copy(result, blocks)

	round := 0
	for len(result) > 1 {
		i := 0
		j := i + 1
		for i < len(result)-1 {
			switch comparator(result[i], result[j], round) {
			case 0:
				result = append(result[:j], result[j+1:]...)

			case 1:
				result = append(result[:i], result[i+1:]...)
				j = i + 1
			case 2:
				j++
			}

			if j >= len(result)-1 {
				i++
				j = i + 1
			}
		}
		round++
	}

	return result[0]
}

Functions

This section is empty.

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(parent *Block, peerID string) *Block

func (*Block) BlockNumber

func (b *Block) BlockNumber() uint64

func (*Block) GetScore

func (b *Block) GetScore() uint32

func (*Block) Hash

func (b *Block) Hash() string

func (*Block) Marshal

func (b *Block) Marshal() ([]byte, spec.Links, error)

func (*Block) Name

func (b *Block) Name() string

func (*Block) Namespace

func (b *Block) Namespace() string

func (*Block) ParentHash

func (b *Block) ParentHash() string

func (*Block) PeerID

func (b *Block) PeerID() string

func (*Block) ResourceType

func (b *Block) ResourceType() string

func (*Block) Timestamp

func (b *Block) Timestamp() int64

func (*Block) Transactions

func (b *Block) Transactions() []spec.Transaction

func (*Block) Unmarshal

func (b *Block) Unmarshal(data []byte, links spec.Links) error

func (*Block) Valid

func (b *Block) Valid() bool

func (*Block) Version

func (b *Block) Version() string

type BlockGenerator

type BlockGenerator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewBlockGenerator

func NewBlockGenerator(txnHandlers ...spec.TransactionHandler) *BlockGenerator

func (*BlockGenerator) BlockPrototype

func (g *BlockGenerator) BlockPrototype() spec.Block

func (*BlockGenerator) CommitBlock

func (g *BlockGenerator) CommitBlock(block spec.Block)

func (*BlockGenerator) GenerateBlock

func (g *BlockGenerator) GenerateBlock(branch []spec.Block) (newBlock spec.Block)

func (*BlockGenerator) GenerateGenesisBlock

func (g *BlockGenerator) GenerateGenesisBlock() spec.Block

func (*BlockGenerator) ReceiveTransaction

func (g *BlockGenerator) ReceiveTransaction(netMsg *spec.NetworkMessage) (spec.Transaction, error)

func (*BlockGenerator) TryCommitBlock

func (g *BlockGenerator) TryCommitBlock(newBlock spec.Block, branch []spec.Block) bool

func (*BlockGenerator) Type

func (g *BlockGenerator) Type() string

type BlockMessage

type BlockMessage struct {
	Namespace   string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"`
	Name        string `protobuf:"bytes,10,opt,name=name,proto3" json:"name,omitempty"`
	Version     string `protobuf:"bytes,15,opt,name=version,proto3" json:"version,omitempty"`
	BlockNumber uint64 `protobuf:"varint,25,opt,name=blockNumber,proto3" json:"blockNumber,omitempty"`
	Timestamp   int64  `protobuf:"varint,30,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Score       uint32 `protobuf:"varint,35,opt,name=score,proto3" json:"score,omitempty"`
	PeerID      string `protobuf:"bytes,40,opt,name=peerID,proto3" json:"peerID,omitempty"`
	// Links:
	// "parent": parent block hash
	// "txn-1"..."txn-n": transactions belonging to this block
	Links                map[string]string `` /* 152-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func (*BlockMessage) Descriptor

func (*BlockMessage) Descriptor() ([]byte, []int)

func (*BlockMessage) GetBlockNumber

func (m *BlockMessage) GetBlockNumber() uint64
func (m *BlockMessage) GetLinks() map[string]string

func (*BlockMessage) GetName

func (m *BlockMessage) GetName() string

func (*BlockMessage) GetNamespace

func (m *BlockMessage) GetNamespace() string

func (*BlockMessage) GetPeerID

func (m *BlockMessage) GetPeerID() string

func (*BlockMessage) GetScore

func (m *BlockMessage) GetScore() uint32

func (*BlockMessage) GetTimestamp

func (m *BlockMessage) GetTimestamp() int64

func (*BlockMessage) GetVersion

func (m *BlockMessage) GetVersion() string

func (*BlockMessage) ProtoMessage

func (*BlockMessage) ProtoMessage()

func (*BlockMessage) Reset

func (m *BlockMessage) Reset()

func (*BlockMessage) String

func (m *BlockMessage) String() string

func (*BlockMessage) XXX_DiscardUnknown

func (m *BlockMessage) XXX_DiscardUnknown()

func (*BlockMessage) XXX_Marshal

func (m *BlockMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BlockMessage) XXX_Merge

func (dst *BlockMessage) XXX_Merge(src proto.Message)

func (*BlockMessage) XXX_Size

func (m *BlockMessage) XXX_Size() int

func (*BlockMessage) XXX_Unmarshal

func (m *BlockMessage) XXX_Unmarshal(b []byte) error

type TransactionHandler

type TransactionHandler struct {
	Protocol string
}

func (*TransactionHandler) Execute

func (h *TransactionHandler) Execute(txn *spec.Transaction) (ok bool)

func (*TransactionHandler) Type

func (h *TransactionHandler) Type() string

func (*TransactionHandler) Unmarshal

func (h *TransactionHandler) Unmarshal(message proto.Message) spec.Transaction

Jump to

Keyboard shortcuts

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