base

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: GPL-3.0 Imports: 28 Imported by: 77

Documentation

Overview

Package base provides the fundamental structures.

Index

Constants

View Source
const (
	StageUnknown = Stage("UNKNOWN")
	StageINIT    = Stage("INIT")
	StageACCEPT  = Stage("ACCEPT")
)
View Source
const (
	VoteResultNotYet   = VoteResult("NOT YET")
	VoteResultDraw     = VoteResult("DRAW")
	VoteResultMajority = VoteResult("MAJORITY")
)
View Source
const AddressTypeSize = 3
View Source
const MaxNetworkIDLength = 300
View Source
const MaxTokenSize = math.MaxUint16
View Source
const PKKeyTypeSize = 3
View Source
const PrivatekeyMinSeedSize = 36

Variables

View Source
var (
	MaxAddressSize = 100
	MinAddressSize = AddressTypeSize + 3

	REStringAddressString = `[a-zA-Z0-9][\w\-\.\!\$\*\@]*[a-zA-Z0-9]`
)
View Source
var (
	OperationFixedtreeHint              = hint.MustNewHint("operation-fixedtree-v0.0.1")
	BaseOperationProcessReasonErrorHint = hint.MustNewHint("operation-fixedtree-node-process-reason-v0.0.1")
)
View Source
var (
	MPrivatekeyHint = hint.MustNewHint("mpr-v0.0.1")
	MPublickeyHint  = hint.MustNewHint("mpu-v0.0.1")
)
View Source
var (
	NilHeight      = Height(-1)
	GenesisHeight  = Height(0)
	GenesisPoint   = Point{/* contains filtered or unexported fields */}
	ZeroPoint      = Point{/* contains filtered or unexported fields */}
	ZeroStagePoint = StagePoint{Point: ZeroPoint, /* contains filtered or unexported fields */}
)
View Source
var BaseStateHint = hint.MustNewHint("base-state-v0.0.1")
View Source
var EmptyOperationProcessorProcessFunc = func(context.Context, Operation, GetStateFunc) (
	OperationProcessReasonError, error,
) {
	return nil, nil
}
View Source
var ErrNotChangedOperationProcessReason = NewBaseOperationProcessReasonError(
	"states not changed")
View Source
var ErrSignatureVerification = util.NewError("signature verification failed")
View Source
var StateFixedtreeHint = hint.MustNewHint("state-fixedtree-v0.0.1")
View Source
var StringAddressHint = hint.MustNewHint("sas-v2")

Functions

func BatchValidateMaps

func BatchValidateMaps(
	ctx context.Context,
	prev BlockMap,
	to Height,
	batchlimit uint64,
	blockMapf func(context.Context, Height) (BlockMap, error),
	callback func(BlockMap) error,
) error

func CheckFactSignsBySuffrage

func CheckFactSignsBySuffrage(suf Suffrage, threshold Threshold, signs []NodeSign) error

func CountBallotSignFacts

func CountBallotSignFacts(sfs []BallotSignFact) (set []string, m map[string]BallotFact)

func FindMajority

func FindMajority(quorum, threshold uint, set ...uint) int

FindMajority finds the majority(over threshold) set between the given sets. The returned value means, 0-N: index number of set -1: not yet majority -2: draw

func IsEqualNode

func IsEqualNode(a, b Node) bool

func IsEqualNodes

func IsEqualNodes(a, b []Node) bool

func IsEqualState

func IsEqualState(a, b State) bool

func IsEqualStateValue

func IsEqualStateValue(a, b StateValue) bool

func IsNetworkPolicyState

func IsNetworkPolicyState(st State) bool

func IsSuffrageNodesState

func IsSuffrageNodesState(st State) bool

func IsValidACCEPTBallot

func IsValidACCEPTBallot(bl ACCEPTBallot, _ []byte) error

func IsValidACCEPTBallotFact

func IsValidACCEPTBallotFact(fact ACCEPTBallotFact) error

func IsValidACCEPTBallotSignFact

func IsValidACCEPTBallotSignFact(sf BallotSignFact, networkID []byte) error

func IsValidACCEPTVoteproof

func IsValidACCEPTVoteproof(vp ACCEPTVoteproof, _ NetworkID) error

func IsValidBallot

func IsValidBallot(bl Ballot, networkID []byte) error

func IsValidBallotFact

func IsValidBallotFact(fact BallotFact) error

func IsValidBallotSignFact

func IsValidBallotSignFact(sf BallotSignFact, networkID []byte) error

func IsValidFact

func IsValidFact(fact Fact, b []byte) error

func IsValidINITBallot

func IsValidINITBallot(bl INITBallot, _ []byte) error

func IsValidINITBallotFact

func IsValidINITBallotFact(fact INITBallotFact) error

func IsValidINITBallotSignFact

func IsValidINITBallotSignFact(sf BallotSignFact, networkID []byte) error

func IsValidINITVoteproof

func IsValidINITVoteproof(vp INITVoteproof, _ NetworkID) error

func IsValidProposalFact

func IsValidProposalFact(fact ProposalFact) error

func IsValidProposalSignFact

func IsValidProposalSignFact(sf ProposalSignFact, networkID []byte) error

func IsValidSignFact

func IsValidSignFact(sf SignFact, networkID []byte) error

func IsValidVoteproof

func IsValidVoteproof(vp Voteproof, networkID NetworkID) error

func IsValidVoteproofWithSuffrage

func IsValidVoteproofWithSuffrage(vp Voteproof, suf Suffrage, th Threshold) error

func ManifestLog

func ManifestLog(m Manifest) *zerolog.Event

func NumberOfFaultyNodes

func NumberOfFaultyNodes(n uint, threshold Threshold) int

func ParseTreeNodeOperationKey

func ParseTreeNodeOperationKey(s string) (util.Hash, bool)

func ValidateGenesisOperation

func ValidateGenesisOperation(op Operation, networkID NetworkID, signer Publickey) error

func ValidateManifests

func ValidateManifests(m Manifest, previous util.Hash) error

func ValidateMaps

func ValidateMaps(m BlockMap, maps []BlockMap, previous BlockMap) error

func ValidateOperationsTreeWithManifest

func ValidateOperationsTreeWithManifest(tr fixedtree.Tree, ops []Operation, manifest Manifest) error

func ValidateProposalWithManifest

func ValidateProposalWithManifest(proposal ProposalSignFact, manifest Manifest) error

func ValidateStatesTreeWithManifest

func ValidateStatesTreeWithManifest(tr fixedtree.Tree, sts []State, manifest Manifest) error

func ValidateVoteproofsWithManifest

func ValidateVoteproofsWithManifest(vps []Voteproof, manifest Manifest) error

func VoteproofLog

func VoteproofLog(vp Voteproof) *zerolog.Event

Types

type ACCEPTBallot

type ACCEPTBallot interface {
	Ballot
	BallotSignFact() ACCEPTBallotSignFact
}

type ACCEPTBallotFact

type ACCEPTBallotFact interface {
	BallotFact
	Proposal() util.Hash // NOTE proposal fact hash
	NewBlock() util.Hash
}

type ACCEPTBallotSignFact

type ACCEPTBallotSignFact interface {
	BallotSignFact
	BallotFact() ACCEPTBallotFact
}

type ACCEPTVoteproof

type ACCEPTVoteproof interface {
	Voteproof
	BallotMajority() ACCEPTBallotFact
	BallotSignFacts() []ACCEPTBallotSignFact
}

func EnsureACCEPTVoteproof

func EnsureACCEPTVoteproof(vp Voteproof) (ACCEPTVoteproof, error)

type Address

type Address interface {
	fmt.Stringer // NOTE String() should be typed string
	util.Byter
	util.IsValider
	Equal(Address) bool
}

Address represents the address of account.

func DecodeAddress

func DecodeAddress(s string, enc encoder.Encoder) (Address, error)

DecodeAddress decodes Address from string.

type Addresses

type Addresses []Address

func (Addresses) Len

func (as Addresses) Len() int

func (Addresses) Less

func (as Addresses) Less(i, j int) bool

func (Addresses) Swap

func (as Addresses) Swap(i, j int)

type Ballot

type Ballot interface {
	util.IsValider
	util.HashByter
	Point() StagePoint
	SignFact() BallotSignFact
	Voteproof() Voteproof
}

type BallotFact

type BallotFact interface {
	Fact
	Point() StagePoint
}

type BallotSignFact

type BallotSignFact interface {
	NodeSignFact
	Node() Address
	Signer() Publickey
}

type BaseFact

type BaseFact struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseFact

func NewBaseFact(ht hint.Hint, t Token) BaseFact

func (BaseFact) Hash

func (fact BaseFact) Hash() util.Hash

func (BaseFact) IsValid

func (fact BaseFact) IsValid([]byte) error

func (BaseFact) JSONMarshaler

func (fact BaseFact) JSONMarshaler() BaseFactJSONMarshaler

func (*BaseFact) SetHash

func (fact *BaseFact) SetHash(h util.Hash)

func (*BaseFact) SetJSONUnmarshaler

func (fact *BaseFact) SetJSONUnmarshaler(u BaseFactJSONUnmarshaler)

func (*BaseFact) SetToken

func (fact *BaseFact) SetToken(t Token) error

func (BaseFact) Token

func (fact BaseFact) Token() Token

type BaseFactJSONMarshaler

type BaseFactJSONMarshaler struct {
	Hash  util.Hash `json:"hash"`
	Token Token     `json:"token"`
	hint.BaseHinter
}

type BaseFactJSONUnmarshaler

type BaseFactJSONUnmarshaler struct {
	Hash  valuehash.HashDecoder `json:"hash"`
	Token Token                 `json:"token"`
}

type BaseNode

type BaseNode struct {
	util.IsValider

	util.DefaultJSONMarshaled
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseNode

func NewBaseNode(ht hint.Hint, pub Publickey, addr Address) BaseNode

func (BaseNode) Address

func (n BaseNode) Address() Address

func (*BaseNode) DecodeJSON

func (n *BaseNode) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (BaseNode) HashBytes

func (n BaseNode) HashBytes() []byte

func (BaseNode) IsValid

func (n BaseNode) IsValid([]byte) error

func (BaseNode) MarshalJSON

func (n BaseNode) MarshalJSON() ([]byte, error)

func (BaseNode) Publickey

func (n BaseNode) Publickey() Publickey

type BaseNodeJSONMarshaler

type BaseNodeJSONMarshaler struct {
	Address   Address   `json:"address"`
	Publickey Publickey `json:"publickey"`
}

type BaseNodeJSONUnmarshaler

type BaseNodeJSONUnmarshaler struct {
	Address   string `json:"address"`
	Publickey string `json:"publickey"`
}

type BaseNodeOperation

type BaseNodeOperation struct {
	BaseOperation
}

func NewBaseNodeOperation

func NewBaseNodeOperation(ht hint.Hint, fact Fact) BaseNodeOperation

func (*BaseNodeOperation) AddNodeSigns

func (op *BaseNodeOperation) AddNodeSigns(signs []NodeSign) (added bool, _ error)

func (*BaseNodeOperation) DecodeJSON

func (op *BaseNodeOperation) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (BaseNodeOperation) IsValid

func (op BaseNodeOperation) IsValid(networkID []byte) error

func (BaseNodeOperation) MarshalJSON

func (op BaseNodeOperation) MarshalJSON() ([]byte, error)

func (*BaseNodeOperation) NodeSign

func (op *BaseNodeOperation) NodeSign(priv Privatekey, networkID NetworkID, node Address) error

func (BaseNodeOperation) NodeSigns

func (op BaseNodeOperation) NodeSigns() []NodeSign

func (*BaseNodeOperation) SetNodeSigns

func (op *BaseNodeOperation) SetNodeSigns(signs []NodeSign) error

type BaseNodeSign

type BaseNodeSign struct {
	BaseSign
	// contains filtered or unexported fields
}

func NewBaseNodeSign

func NewBaseNodeSign(node Address, signer Publickey, signature Signature, signedAt time.Time) BaseNodeSign

func NewBaseNodeSignFromBytes

func NewBaseNodeSignFromBytes(node Address, priv Privatekey, networkID NetworkID, b []byte) (BaseNodeSign, error)

func NewBaseNodeSignFromFact

func NewBaseNodeSignFromFact(node Address, priv Privatekey, networkID NetworkID, fact Fact) (BaseNodeSign, error)

func (BaseNodeSign) Bytes

func (si BaseNodeSign) Bytes() []byte

func (*BaseNodeSign) DecodeJSON

func (si *BaseNodeSign) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (BaseNodeSign) IsValid

func (si BaseNodeSign) IsValid([]byte) error

func (BaseNodeSign) JSONMarshaler

func (si BaseNodeSign) JSONMarshaler() BaseNodeSignJSONMarshaler

func (BaseNodeSign) MarshalJSON

func (si BaseNodeSign) MarshalJSON() ([]byte, error)

func (BaseNodeSign) Node

func (si BaseNodeSign) Node() Address

func (BaseNodeSign) Verify

func (si BaseNodeSign) Verify(networkID NetworkID, b []byte) error

type BaseNodeSignJSONMarshaler

type BaseNodeSignJSONMarshaler struct {
	Node Address `json:"node"`
	BaseSignJSONMarshaler
}

type BaseOperation

type BaseOperation struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

BaseOperation is basic form to make new Operation.

func NewBaseOperation

func NewBaseOperation(ht hint.Hint, fact Fact) BaseOperation

func (*BaseOperation) DecodeJSON

func (op *BaseOperation) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (BaseOperation) Fact

func (op BaseOperation) Fact() Fact

func (BaseOperation) Hash

func (op BaseOperation) Hash() util.Hash

func (BaseOperation) HashBytes

func (op BaseOperation) HashBytes() []byte

func (BaseOperation) IsValid

func (op BaseOperation) IsValid(networkID []byte) error

func (BaseOperation) JSONMarshaler

func (op BaseOperation) JSONMarshaler() BaseOperationJSONMarshaler

func (BaseOperation) MarshalJSON

func (op BaseOperation) MarshalJSON() ([]byte, error)

func (BaseOperation) PreProcess

func (*BaseOperation) SetFact

func (op *BaseOperation) SetFact(fact Fact)

func (*BaseOperation) Sign

func (op *BaseOperation) Sign(priv Privatekey, networkID NetworkID) error

func (BaseOperation) Signs

func (op BaseOperation) Signs() []Sign

type BaseOperationJSONMarshaler

type BaseOperationJSONMarshaler struct {
	Hash  util.Hash `json:"hash"`
	Fact  Fact      `json:"fact"`
	Signs []Sign    `json:"signs"`
	hint.BaseHinter
}

type BaseOperationJSONUnmarshaler

type BaseOperationJSONUnmarshaler struct {
	Hash  valuehash.HashDecoder `json:"hash"`
	Fact  json.RawMessage       `json:"fact"`
	Signs []json.RawMessage     `json:"signs"`
}

type BaseOperationProcessReasonError

type BaseOperationProcessReasonError struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseOperationProcessReasonError

func NewBaseOperationProcessReasonError(s string, a ...interface{}) BaseOperationProcessReasonError

func (BaseOperationProcessReasonError) Error

func (BaseOperationProcessReasonError) Hint

func (BaseOperationProcessReasonError) Is

func (BaseOperationProcessReasonError) MarshalJSON

func (e BaseOperationProcessReasonError) MarshalJSON() ([]byte, error)

func (BaseOperationProcessReasonError) Msg

func (*BaseOperationProcessReasonError) UnmarshalJSON

func (e *BaseOperationProcessReasonError) UnmarshalJSON(b []byte) error

type BaseOperationProcessReasonErrorJSONMarshaler

type BaseOperationProcessReasonErrorJSONMarshaler struct {
	Message string `json:"message"`
	hint.BaseHinter
}

type BaseOperationProcessReasonErrorJSONUnmarshaler

type BaseOperationProcessReasonErrorJSONUnmarshaler struct {
	Message string `json:"message"`
}

type BaseOperationProcessor

type BaseOperationProcessor struct {
	PreProcessConstraintFunc OperationProcessorProcessFunc
	ProcessConstraintFunc    OperationProcessorProcessFunc
	// contains filtered or unexported fields
}

func NewBaseOperationProcessor

func NewBaseOperationProcessor(
	height Height,
	getStateFunc GetStateFunc,
	newPreProcessConstraintFunc NewOperationProcessorProcessFunc,
	newProcessConstraintFunc NewOperationProcessorProcessFunc,
) (*BaseOperationProcessor, error)

func (*BaseOperationProcessor) Close

func (p *BaseOperationProcessor) Close() error

func (*BaseOperationProcessor) Height

func (p *BaseOperationProcessor) Height() Height

type BaseSign

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

func NewBaseSign

func NewBaseSign(signer Publickey, signature Signature, signedAt time.Time) BaseSign

func NewBaseSignFromBytes

func NewBaseSignFromBytes(priv Privatekey, networkID NetworkID, b []byte) (BaseSign, error)

func NewBaseSignFromFact

func NewBaseSignFromFact(priv Privatekey, networkID NetworkID, fact Fact) (BaseSign, error)

func (BaseSign) Bytes

func (si BaseSign) Bytes() []byte

func (*BaseSign) DecodeJSON

func (si *BaseSign) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (BaseSign) IsValid

func (si BaseSign) IsValid([]byte) error

func (BaseSign) JSONMarshaler

func (si BaseSign) JSONMarshaler() BaseSignJSONMarshaler

func (BaseSign) MarshalJSON

func (si BaseSign) MarshalJSON() ([]byte, error)

func (BaseSign) Signature

func (si BaseSign) Signature() Signature

func (BaseSign) SignedAt

func (si BaseSign) SignedAt() time.Time

func (BaseSign) Signer

func (si BaseSign) Signer() Publickey

func (BaseSign) Verify

func (si BaseSign) Verify(networkID NetworkID, b []byte) error

type BaseSignJSONMarshaler

type BaseSignJSONMarshaler struct {
	SignedAt  localtime.Time `json:"signed_at"`
	Signer    Publickey      `json:"signer"`
	Signature Signature      `json:"signature"`
}

type BaseState

type BaseState struct {
	util.DefaultJSONMarshaled
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseState

func NewBaseState(
	height Height,
	k string,
	v StateValue,
	previous util.Hash,
	ops []util.Hash,
) BaseState

func (*BaseState) DecodeJSON

func (s *BaseState) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (BaseState) Hash

func (s BaseState) Hash() util.Hash

func (BaseState) Height

func (s BaseState) Height() Height

func (BaseState) IsValid

func (s BaseState) IsValid([]byte) error

func (BaseState) Key

func (s BaseState) Key() string

func (BaseState) MarshalJSON

func (s BaseState) MarshalJSON() ([]byte, error)

func (BaseState) Operations

func (s BaseState) Operations() []util.Hash

func (BaseState) Previous

func (s BaseState) Previous() util.Hash

func (BaseState) Value

func (s BaseState) Value() StateValue

type BaseStateMergeValue

type BaseStateMergeValue struct {
	StateValue
	// contains filtered or unexported fields
}

func NewBaseStateMergeValue

func NewBaseStateMergeValue(
	key string,
	value StateValue,
	merger func(Height, State) StateValueMerger,
) BaseStateMergeValue

func (BaseStateMergeValue) Key

func (v BaseStateMergeValue) Key() string

func (BaseStateMergeValue) Merger

func (v BaseStateMergeValue) Merger(height Height, st State) StateValueMerger

func (BaseStateMergeValue) Value

func (v BaseStateMergeValue) Value() StateValue

type BaseStateValueMerger

type BaseStateValueMerger struct {
	State

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBaseStateValueMerger

func NewBaseStateValueMerger(height Height, key string, st State) *BaseStateValueMerger

func (*BaseStateValueMerger) AddOperations

func (s *BaseStateValueMerger) AddOperations(ops []util.Hash)

func (*BaseStateValueMerger) Close

func (s *BaseStateValueMerger) Close() error

func (*BaseStateValueMerger) Hash

func (s *BaseStateValueMerger) Hash() util.Hash

func (*BaseStateValueMerger) Height

func (s *BaseStateValueMerger) Height() Height

func (*BaseStateValueMerger) Key

func (s *BaseStateValueMerger) Key() string

func (*BaseStateValueMerger) MarshalJSON

func (s *BaseStateValueMerger) MarshalJSON() ([]byte, error)

func (*BaseStateValueMerger) Merge

func (s *BaseStateValueMerger) Merge(value StateValue, ops []util.Hash) error

func (*BaseStateValueMerger) Operations

func (s *BaseStateValueMerger) Operations() []util.Hash

func (*BaseStateValueMerger) Previous

func (s *BaseStateValueMerger) Previous() util.Hash

func (*BaseStateValueMerger) SetValue

func (s *BaseStateValueMerger) SetValue(v StateValue)

func (*BaseStateValueMerger) Value

func (s *BaseStateValueMerger) Value() StateValue

type BaseStringAddress

type BaseStringAddress struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseStringAddressWithHint

func NewBaseStringAddressWithHint(ht hint.Hint, s string) BaseStringAddress

func (BaseStringAddress) Bytes

func (ad BaseStringAddress) Bytes() []byte

func (BaseStringAddress) Equal

func (ad BaseStringAddress) Equal(b Address) bool

func (BaseStringAddress) IsValid

func (ad BaseStringAddress) IsValid([]byte) error

func (BaseStringAddress) MarshalText

func (ad BaseStringAddress) MarshalText() ([]byte, error)

func (BaseStringAddress) String

func (ad BaseStringAddress) String() string

type BlockMap

type BlockMap interface {
	NodeSign
	Manifest() Manifest
	Item(BlockMapItemType) (BlockMapItem, bool)
	Items(func(BlockMapItem) bool)
	Writer() hint.Hint
	Encoder() hint.Hint
}

type BlockMapItem

type BlockMapItem interface {
	util.IsValider
	Type() BlockMapItemType
	URL() *url.URL
	Checksum() string
	Num() uint64
}

type BlockMapItemType

type BlockMapItemType string
var (
	BlockMapItemTypeProposal       BlockMapItemType = "blockmapitem_proposal"
	BlockMapItemTypeOperations     BlockMapItemType = "blockmapitem_operations"
	BlockMapItemTypeOperationsTree BlockMapItemType = "blockmapitem_operations_tree"
	BlockMapItemTypeStates         BlockMapItemType = "blockmapitem_states"
	BlockMapItemTypeStatesTree     BlockMapItemType = "blockmapitem_states_tree"
	BlockMapItemTypeVoteproofs     BlockMapItemType = "blockmapitem_voteproofs"
)

func (BlockMapItemType) IsValid

func (t BlockMapItemType) IsValid([]byte) error

func (BlockMapItemType) String

func (t BlockMapItemType) String() string

type Fact

type Fact interface {
	util.IsValider
	util.Hasher
	Token() Token
}

type Facter

type Facter interface {
	Fact() Fact
}

type GetStateFunc

type GetStateFunc func(key string) (State, bool, error)

type HasWithdraws

type HasWithdraws interface {
	Withdraws() []SuffrageWithdrawOperation
}

type Height

type Height int64

Height stands for height of Block

func ParseHeightBytes

func ParseHeightBytes(b []byte) (Height, error)

func ParseHeightString

func ParseHeightString(s string) (Height, error)

func (Height) Bytes

func (h Height) Bytes() []byte

func (Height) FixedString

func (h Height) FixedString() string

func (Height) Int64

func (h Height) Int64() int64

Int64 returns int64 of height.

func (Height) IsValid

func (h Height) IsValid([]byte) error

func (Height) IsZero

func (h Height) IsZero() bool

func (Height) Prev

func (h Height) Prev() Height

func (Height) SafePrev

func (h Height) SafePrev() Height

func (Height) String

func (h Height) String() string

type HeightDecoder

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

func (HeightDecoder) Height

func (d HeightDecoder) Height() Height

func (*HeightDecoder) UnmarshalJSON

func (d *HeightDecoder) UnmarshalJSON(b []byte) error

type INITBallot

type INITBallot interface {
	Ballot
	BallotSignFact() INITBallotSignFact
}

type INITBallotFact

type INITBallotFact interface {
	BallotFact
	PreviousBlock() util.Hash
	Proposal() util.Hash
}

type INITBallotSignFact

type INITBallotSignFact interface {
	BallotSignFact
	BallotFact() INITBallotFact
}

type INITVoteproof

type INITVoteproof interface {
	Voteproof
	BallotMajority() INITBallotFact
	BallotSignFacts() []INITBallotSignFact
}

func EnsureINITVoteproof

func EnsureINITVoteproof(vp Voteproof) (INITVoteproof, error)

type LocalNode

type LocalNode interface {
	Node
	Privatekey() Privatekey
}

type LocalParams

type LocalParams interface {
	util.IsValider
	NetworkID() NetworkID
	Threshold() Threshold
}

type MPrivatekey

type MPrivatekey struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

MPrivatekey is the default privatekey of mitum, it is based on BTC Privatekey.

func LoadMPrivatekey

func LoadMPrivatekey(s string) (MPrivatekey, error)

func NewMPrivatekey

func NewMPrivatekey() MPrivatekey

func NewMPrivatekeyFromSeed

func NewMPrivatekeyFromSeed(s string) (MPrivatekey, error)

func ParseMPrivatekey

func ParseMPrivatekey(s string) (MPrivatekey, error)

func (MPrivatekey) Bytes

func (k MPrivatekey) Bytes() []byte

func (MPrivatekey) Equal

func (k MPrivatekey) Equal(b PKKey) bool

func (MPrivatekey) IsValid

func (k MPrivatekey) IsValid([]byte) error

func (MPrivatekey) MarshalText

func (k MPrivatekey) MarshalText() ([]byte, error)

func (MPrivatekey) Publickey

func (k MPrivatekey) Publickey() Publickey

func (MPrivatekey) Sign

func (k MPrivatekey) Sign(b []byte) (Signature, error)

func (MPrivatekey) String

func (k MPrivatekey) String() string

func (*MPrivatekey) UnmarshalText

func (k *MPrivatekey) UnmarshalText(b []byte) error

type MPublickey

type MPublickey struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

MPublickey is the default publickey of mitum, it is based on BTC Privatekey.

func LoadMPublickey

func LoadMPublickey(s string) (MPublickey, error)

func NewMPublickey

func NewMPublickey(k *btcec.PublicKey) MPublickey

func ParseMPublickey

func ParseMPublickey(s string) (MPublickey, error)

func (MPublickey) Bytes

func (k MPublickey) Bytes() []byte

func (MPublickey) Equal

func (k MPublickey) Equal(b PKKey) bool

func (MPublickey) IsValid

func (k MPublickey) IsValid([]byte) error

func (MPublickey) MarshalText

func (k MPublickey) MarshalText() ([]byte, error)

func (MPublickey) String

func (k MPublickey) String() string

func (*MPublickey) UnmarshalText

func (k *MPublickey) UnmarshalText(b []byte) error

func (MPublickey) Verify

func (k MPublickey) Verify(input []byte, sig Signature) error

type Manifest

type Manifest interface {
	util.Hasher
	util.IsValider
	Height() Height
	Previous() util.Hash
	Proposal() util.Hash       // NOTE proposal fact hash
	OperationsTree() util.Hash // NOTE operations tree root hash
	StatesTree() util.Hash     // NOTE states tree root hash
	Suffrage() util.Hash       // NOTE state hash of newly updated SuffrageNodesStateValue
	ProposedAt() time.Time     // NOTE Proposal proposed time
}

type NetworkID

type NetworkID []byte

NetworkID will be used to separate mitum network with the other mitum network. Generally it is used for hashing and making signature.

func (NetworkID) Bytes

func (ni NetworkID) Bytes() []byte

func (NetworkID) Equal

func (ni NetworkID) Equal(a NetworkID) bool

func (NetworkID) IsValid

func (ni NetworkID) IsValid([]byte) error

func (NetworkID) MarshalText

func (ni NetworkID) MarshalText() ([]byte, error)

func (*NetworkID) UnmarshalText

func (ni *NetworkID) UnmarshalText(b []byte) error

type NetworkPolicy

type NetworkPolicy interface {
	util.IsValider
	util.HashByter
	MaxOperationsInProposal() uint64
	SuffrageCandidateLifespan() Height
	SuffrageCandidateLimiterRule() SuffrageCandidateLimiterRule
	MaxSuffrageSize() uint64
	SuffrageWithdrawLifespan() Height
}

type NetworkPolicyStateValue

type NetworkPolicyStateValue interface {
	StateValue
	Policy() NetworkPolicy
}

type NewOperationProcessorProcessFunc

type NewOperationProcessorProcessFunc func(Height, GetStateFunc) (OperationProcessorProcessFunc, error)

type Node

type Node interface {
	util.HashByter
	util.IsValider
	Address() Address
	Publickey() Publickey
}

type NodeSign

type NodeSign interface {
	Sign
	Node() Address
}

type NodeSignFact

type NodeSignFact interface {
	SignFact
	NodeSigns() []NodeSign
}

type NodeSigner

type NodeSigner interface {
	NodeSign(Privatekey, NetworkID, Address) error
	AddNodeSigns([]NodeSign) (added bool, _ error)
	SetNodeSigns([]NodeSign) error
}

type OperationFixedtreeNode

type OperationFixedtreeNode struct {
	fixedtree.BaseNode
	// contains filtered or unexported fields
}

func NewInStateOperationFixedtreeNode

func NewInStateOperationFixedtreeNode(facthash util.Hash, reason string) OperationFixedtreeNode

func NewNotInStateOperationFixedtreeNode

func NewNotInStateOperationFixedtreeNode(facthash util.Hash, reason string) OperationFixedtreeNode

func (*OperationFixedtreeNode) DecodeJSON

func (no *OperationFixedtreeNode) DecodeJSON(b []byte, enc *jsonenc.Encoder) error

func (OperationFixedtreeNode) InState

func (no OperationFixedtreeNode) InState() bool

func (OperationFixedtreeNode) MarshalJSON

func (no OperationFixedtreeNode) MarshalJSON() ([]byte, error)

func (OperationFixedtreeNode) Operation

func (no OperationFixedtreeNode) Operation() util.Hash

func (OperationFixedtreeNode) Reason

func (OperationFixedtreeNode) SetHash

type OperationProcessReasonError

type OperationProcessReasonError interface {
	error
	Msg() string
}

type PKKey

type PKKey interface {
	fmt.Stringer
	util.Byter
	util.IsValider
	Equal(PKKey) bool
}

type Point

type Point struct {
	util.DefaultJSONMarshaled
	// contains filtered or unexported fields
}

func NewPoint

func NewPoint(h Height, r Round) Point

func RawPoint

func RawPoint(h int64, r uint64) Point

func (Point) Bytes

func (p Point) Bytes() []byte

func (Point) Compare

func (p Point) Compare(b Point) int

func (Point) Equal

func (p Point) Equal(b Point) bool

func (Point) Height

func (p Point) Height() Height

func (Point) IsValid

func (p Point) IsValid([]byte) error

func (Point) IsZero

func (p Point) IsZero() bool

func (Point) MarshalJSON

func (p Point) MarshalJSON() ([]byte, error)

func (Point) MarshalZerologObject

func (p Point) MarshalZerologObject(e *zerolog.Event)

func (Point) NextHeight

func (p Point) NextHeight() Point

NextHeight returns next height with 0 round.

func (Point) NextRound

func (p Point) NextRound() Point

func (Point) PrevHeight

func (p Point) PrevHeight() Point

PrevHeight returns previous height with 0 round

func (Point) PrevRound

func (p Point) PrevRound() Point

PrevRound returns previous round; if 0 round, returns previous height and zero round

func (Point) Round

func (p Point) Round() Round

func (Point) String

func (p Point) String() string

func (*Point) UnmarshalJSON

func (p *Point) UnmarshalJSON(b []byte) error

type Privatekey

type Privatekey interface {
	PKKey
	Publickey() Publickey
	Sign([]byte) (Signature, error)
}

func DecodePrivatekeyFromString

func DecodePrivatekeyFromString(s string, enc encoder.Encoder) (Privatekey, error)

type ProposalFact

type ProposalFact interface {
	Fact
	Point() Point
	Proposer() Address
	Operations() []util.Hash // NOTE operation hash
	ProposedAt() time.Time
}

type ProposalSignFact

type ProposalSignFact interface {
	util.HashByter
	util.IsValider
	SignFact
	Point() Point
	ProposalFact() ProposalFact
}

type Publickey

type Publickey interface {
	PKKey
	Verify([]byte, Signature) error
}

func DecodePublickeyFromString

func DecodePublickeyFromString(s string, enc encoder.Encoder) (Publickey, error)

type Round

type Round uint64

func (Round) Bytes

func (r Round) Bytes() []byte

func (Round) Prev

func (r Round) Prev() Round

func (Round) Uint64

func (r Round) Uint64() uint64

type Sign

type Sign interface {
	util.Byter
	util.IsValider
	Signer() Publickey
	Signature() Signature
	SignedAt() time.Time
	Verify(NetworkID, []byte) error
}

type SignFact

type SignFact interface {
	util.HashByter
	util.IsValider
	Fact() Fact
	Signs() []Sign
}

type Signature

type Signature []byte

func (Signature) Bytes

func (sg Signature) Bytes() []byte

func (Signature) Equal

func (sg Signature) Equal(b Signature) bool

func (Signature) IsValid

func (sg Signature) IsValid([]byte) error

func (Signature) MarshalText

func (sg Signature) MarshalText() ([]byte, error)

func (Signature) String

func (sg Signature) String() string

func (*Signature) UnmarshalText

func (sg *Signature) UnmarshalText(b []byte) error

type Signer

type Signer interface {
	Sign(Privatekey, NetworkID) error
}

type Stage

type Stage string

func (Stage) Bytes

func (st Stage) Bytes() []byte

func (Stage) CanVote

func (st Stage) CanVote() bool

func (Stage) Compare

func (st Stage) Compare(b Stage) int

func (Stage) IsValid

func (st Stage) IsValid([]byte) error

func (Stage) MarshalText

func (st Stage) MarshalText() ([]byte, error)

func (Stage) String

func (st Stage) String() string

func (*Stage) UnmarshalText

func (st *Stage) UnmarshalText(b []byte) error

type StagePoint

type StagePoint struct {
	util.DefaultJSONMarshaled
	Point
	// contains filtered or unexported fields
}

func NewStagePoint

func NewStagePoint(point Point, stage Stage) StagePoint

func (StagePoint) Bytes

func (p StagePoint) Bytes() []byte

func (StagePoint) Compare

func (p StagePoint) Compare(b StagePoint) int

func (StagePoint) Decrease

func (p StagePoint) Decrease() StagePoint

func (StagePoint) Equal

func (p StagePoint) Equal(b StagePoint) bool

func (StagePoint) IsValid

func (p StagePoint) IsValid([]byte) error

func (StagePoint) IsZero

func (p StagePoint) IsZero() bool

func (StagePoint) MarshalJSON

func (p StagePoint) MarshalJSON() ([]byte, error)

func (StagePoint) MarshalZerologObject

func (p StagePoint) MarshalZerologObject(e *zerolog.Event)

func (StagePoint) SetStage

func (p StagePoint) SetStage(s Stage) StagePoint

func (StagePoint) Stage

func (p StagePoint) Stage() Stage

func (StagePoint) String

func (p StagePoint) String() string

func (*StagePoint) UnmarshalJSON

func (p *StagePoint) UnmarshalJSON(b []byte) error

type State

type State interface {
	util.Hasher // NOTE <key> + <value HashByte> + <height>
	util.IsValider
	Key() string
	Value() StateValue
	Height() Height          // NOTE manifest height
	Previous() util.Hash     // NOTE previous state hash
	Operations() []util.Hash // NOTE operation fact hash
}

func InterfaceIsSuffrageNodesState

func InterfaceIsSuffrageNodesState(i interface{}) (State, error)

type StateMergeValue

type StateMergeValue interface {
	StateValue
	Key() string
	Value() StateValue
	Merger(Height, State) StateValueMerger
}

type StateValue

type StateValue interface {
	util.HashByter
	util.IsValider
}

func DecodeStateValue

func DecodeStateValue(b []byte, enc encoder.Encoder) (StateValue, error)

type StateValueMerger

type StateValueMerger interface {
	State
	Merge(value StateValue, operations []util.Hash) error
	Close() error
}

type StringAddress

type StringAddress struct {
	BaseStringAddress
}

func NewStringAddress

func NewStringAddress(s string) StringAddress

func ParseStringAddress

func ParseStringAddress(s string) (StringAddress, error)

func (StringAddress) IsValid

func (ad StringAddress) IsValid([]byte) error

func (*StringAddress) UnmarshalText

func (ad *StringAddress) UnmarshalText(b []byte) error

type StuckVoteproof

type StuckVoteproof interface {
	HasWithdraws
	IsStuckVoteproof() bool // NOTE should be true
}

type Suffrage

type Suffrage interface {
	Exists(Address) bool
	ExistsPublickey(Address, Publickey) bool
	Nodes() []Node
	Len() int
}

type SuffrageCandidateLimiter

type SuffrageCandidateLimiter func() (uint64, error)

type SuffrageCandidateLimiterRule

type SuffrageCandidateLimiterRule interface {
	hint.Hinter
	util.IsValider
	util.HashByter
}

type SuffrageCandidateStateValue

type SuffrageCandidateStateValue interface {
	Node
	Start() Height
	Deadline() Height
}

func LoadNodesFromSuffrageCandidatesState

func LoadNodesFromSuffrageCandidatesState(st State) ([]SuffrageCandidateStateValue, error)

type SuffrageCandidatesStateValue

type SuffrageCandidatesStateValue interface {
	StateValue
	Nodes() []SuffrageCandidateStateValue
}

type SuffrageNodeStateValue

type SuffrageNodeStateValue interface {
	Node
	Start() Height
}

type SuffrageNodesStateValue

type SuffrageNodesStateValue interface {
	StateValue
	Height() Height // NOTE not manifest height
	Nodes() []SuffrageNodeStateValue
	Suffrage() (Suffrage, error)
}

func LoadSuffrageNodesStateValue

func LoadSuffrageNodesStateValue(st State) (SuffrageNodesStateValue, error)

type SuffrageProof

type SuffrageProof interface {
	util.IsValider
	Map() BlockMap
	State() State
	ACCEPTVoteproof() ACCEPTVoteproof
	Proof() fixedtree.Proof
	Suffrage() (Suffrage, error)
	SuffrageHeight() Height
	Prove(previousState State) error
}

type SuffrageWithdrawFact

type SuffrageWithdrawFact interface {
	Fact
	Node() Address
	WithdrawStart() Height // NOTE available from WithdrawStart()
	WithdrawEnd() Height   // NOTE not available at WithdrawEnd() + 1
	Reason() string
}

type SuffrageWithdrawOperation

type SuffrageWithdrawOperation interface {
	Operation
	NodeSignFact
	WithdrawFact() SuffrageWithdrawFact
}

type Threshold

type Threshold float64
var (
	DefaultThreshold Threshold = 67
	SafeThreshold    Threshold = 67
	MinThreshold     Threshold = 51
	MaxThreshold     Threshold = 100
)

func (Threshold) Bytes

func (t Threshold) Bytes() []byte

func (Threshold) Equal

func (t Threshold) Equal(b Threshold) bool

func (Threshold) Float64

func (t Threshold) Float64() float64

func (Threshold) IsValid

func (t Threshold) IsValid([]byte) error

func (Threshold) MarshalText

func (t Threshold) MarshalText() ([]byte, error)

func (Threshold) String

func (t Threshold) String() string

func (Threshold) Threshold

func (t Threshold) Threshold(quorum uint) uint

func (*Threshold) UnmarshalText

func (t *Threshold) UnmarshalText(b []byte) error

func (Threshold) VoteResult

func (t Threshold) VoteResult(quorum uint, set []string) (result VoteResult, key string)

type Token

type Token []byte

func (Token) IsValid

func (t Token) IsValid([]byte) error

type TokenSetter

type TokenSetter interface {
	SetToken(Token) error
}

type Tokener

type Tokener interface {
	Token() Token
}

type VoteResult

type VoteResult string

func FindVoteResult

func FindVoteResult(quorum, threshold uint, s []string) (result VoteResult, key string)

func (VoteResult) Bytes

func (v VoteResult) Bytes() []byte

func (VoteResult) IsValid

func (VoteResult) IsValid([]byte) error

func (VoteResult) MarshalText

func (v VoteResult) MarshalText() ([]byte, error)

func (VoteResult) String

func (v VoteResult) String() string

func (*VoteResult) UnmarshalText

func (v *VoteResult) UnmarshalText(b []byte) error

type Voteproof

type Voteproof interface {
	util.IsValider
	util.HashByter
	FinishedAt() time.Time // NOTE if zero, not yet finished
	Point() StagePoint
	Result() VoteResult
	Threshold() Threshold
	Majority() BallotFact
	SignFacts() []BallotSignFact
	ID() string // NOTE ID is only unique in local machine
}

type WithdrawVoteproof

type WithdrawVoteproof interface {
	HasWithdraws
	IsWithdrawVoteproof() bool // NOTE should be true
}

Jump to

Keyboard shortcuts

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