common

package
v3.0.0-alpha.0...-e5a6d49 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 20 Imported by: 19

Documentation

Overview

Package base provides the fundamental structures for currency model.

Index

Constants

This section is empty.

Variables

View Source
var (
	NilBig       = NewBig(-1)
	NilBigString = big.NewInt(-1).String()
	ZeroBig      = NewBig(0)
)
View Source
var BaseStateHint = hint.MustNewHint("currency-base-state-v0.0.1")
View Source
var NodeHint = hint.MustNewHint("currency-node-v0.0.1")

Functions

func DecodeStateValue

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

func IsValidOperationFact

func IsValidOperationFact(fact base.Fact, networkID []byte) error

func NewHashFromBytes

func NewHashFromBytes(b []byte) util.Hash

Types

type BaseFactBSONUnmarshaler

type BaseFactBSONUnmarshaler struct {
	Hash  string `bson:"hash"`
	Token []byte `bson:"token"`
}

type BaseNode

type BaseNode struct {
	util.IsValider

	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseNode

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

func (BaseNode) Address

func (n BaseNode) Address() base.Address

func (*BaseNode) DecodeBSON

func (n *BaseNode) DecodeBSON(b []byte, enc *bsonenc.Encoder) error

func (*BaseNode) DecodeJSON

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

func (BaseNode) HashBytes

func (n BaseNode) HashBytes() []byte

func (BaseNode) IsValid

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

func (BaseNode) MarshalBSON

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

func (BaseNode) MarshalJSON

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

func (BaseNode) Publickey

func (n BaseNode) Publickey() base.Publickey

type BaseNodeBSONUnMarshaler

type BaseNodeBSONUnMarshaler struct {
	Hint      string `bson:"_hint"`
	Address   string `bson:"address"`
	Publickey string `bson:"publickey"`
}

type BaseNodeJSONMarshaler

type BaseNodeJSONMarshaler struct {
	Address   base.Address   `json:"address"`
	Publickey base.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 base.Fact) BaseNodeOperation

func (*BaseNodeOperation) AddNodeSigns

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

func (*BaseNodeOperation) DecodeBSON

func (op *BaseNodeOperation) DecodeBSON(b []byte, enc *bsonenc.Encoder) error

func (*BaseNodeOperation) DecodeJSON

func (op *BaseNodeOperation) DecodeJSON(b []byte, enc encoder.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 base.Privatekey, networkID base.NetworkID, node base.Address) error

func (BaseNodeOperation) NodeSigns

func (op BaseNodeOperation) NodeSigns() []base.NodeSign

func (*BaseNodeOperation) SetNodeSigns

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

type BaseOperation

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

func NewBaseOperation

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

func (*BaseOperation) DecodeBSON

func (op *BaseOperation) DecodeBSON(b []byte, enc *bsonenc.Encoder) error

func (*BaseOperation) DecodeJSON

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

func (BaseOperation) Fact

func (op BaseOperation) Fact() base.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) MarshalBSON

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

func (BaseOperation) MarshalJSON

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

func (*BaseOperation) SetFact

func (op *BaseOperation) SetFact(fact base.Fact)

func (*BaseOperation) SetHash

func (op *BaseOperation) SetHash(h util.Hash)

func (*BaseOperation) Sign

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

func (BaseOperation) Signs

func (op BaseOperation) Signs() []base.Sign

type BaseOperationBSONUnmarshaler

type BaseOperationBSONUnmarshaler struct {
	Hint  string     `bson:"_hint"`
	Hash  string     `bson:"hash"`
	Fact  bson.Raw   `bson:"fact"`
	Signs []bson.Raw `bson:"signs"`
}

type BaseOperationJSONMarshaler

type BaseOperationJSONMarshaler struct {
	Hash  util.Hash   `json:"hash"`
	Fact  base.Fact   `json:"fact"`
	Signs []base.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 BaseSignBSONUnmarshaler

type BaseSignBSONUnmarshaler struct {
	Signer    string         `bson:"signer"`
	Signature base.Signature `bson:"signature"`
	SignedAt  time.Time      `bson:"signed_at"`
}

type BaseState

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

func NewBaseState

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

func (BaseState) BSONM

func (s BaseState) BSONM() bson.M

func (*BaseState) DecodeBSON

func (s *BaseState) DecodeBSON(b []byte, enc *bsonenc.Encoder) error

func (*BaseState) DecodeJSON

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

func (BaseState) Hash

func (s BaseState) Hash() util.Hash

func (BaseState) Height

func (s BaseState) Height() base.Height

func (BaseState) IsValid

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

func (BaseState) Key

func (s BaseState) Key() string

func (BaseState) MarshalBSON

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

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() base.StateValue

type BaseStateBSONUnmarshaler

type BaseStateBSONUnmarshaler struct {
	Hint       string            `bson:"_hint"`
	Hash       valuehash.Bytes   `bson:"hash"`
	Previous   valuehash.Bytes   `bson:"previous"`
	Key        string            `bson:"key"`
	Value      bson.Raw          `bson:"value"`
	Operations []valuehash.Bytes `bson:"operations"`
	Height     base.Height       `bson:"height"`
}

type BaseStateMergeValue

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

func NewBaseStateMergeValue

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

func (BaseStateMergeValue) Key

func (v BaseStateMergeValue) Key() string

func (BaseStateMergeValue) Merger

func (BaseStateMergeValue) Value

type BaseStateValueMerger

type BaseStateValueMerger struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBaseStateValueMerger

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

func (*BaseStateValueMerger) AddOperation

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

func (*BaseStateValueMerger) Close

func (s *BaseStateValueMerger) Close() error

func (*BaseStateValueMerger) CloseValue

func (s *BaseStateValueMerger) CloseValue() (base.State, error)

func (*BaseStateValueMerger) Height

func (s *BaseStateValueMerger) Height() base.Height

func (*BaseStateValueMerger) Key

func (s *BaseStateValueMerger) Key() string

func (*BaseStateValueMerger) Merge

func (s *BaseStateValueMerger) Merge(value base.StateValue, op util.Hash) error

func (*BaseStateValueMerger) Reset

func (s *BaseStateValueMerger) Reset(height base.Height, key string, st base.State)

func (*BaseStateValueMerger) SetValue

func (s *BaseStateValueMerger) SetValue(v base.StateValue)

func (*BaseStateValueMerger) State

func (s *BaseStateValueMerger) State() base.State

type Big

type Big struct {
	*big.Int
}

func MustBigFromString

func MustBigFromString(s string) Big

func NewBig

func NewBig(i int64) Big

func NewBigFromBigInt

func NewBigFromBigInt(b *big.Int) Big

func NewBigFromInterface

func NewBigFromInterface(a interface{}) (Big, error)

func NewBigFromString

func NewBigFromString(s string) (Big, error)

func (Big) Add

func (a Big) Add(b Big) Big

func (Big) Compare

func (a Big) Compare(b Big) int

func (Big) Div

func (a Big) Div(b Big) Big

func (Big) Equal

func (a Big) Equal(b Big) bool

func (Big) IsValid

func (Big) IsValid([]byte) error

func (Big) IsZero

func (a Big) IsZero() bool

func (Big) MarshalBSONValue

func (a Big) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Big) MarshalJSON

func (a Big) MarshalJSON() ([]byte, error)

func (Big) Mul

func (a Big) Mul(b Big) Big

func (Big) MulFloat64

func (a Big) MulFloat64(b float64) Big

func (Big) MulInt64

func (a Big) MulInt64(b int64) Big

func (Big) Neg

func (a Big) Neg() Big

func (Big) OverNil

func (a Big) OverNil() bool

func (Big) OverZero

func (a Big) OverZero() bool

func (Big) String

func (a Big) String() string

func (Big) Sub

func (a Big) Sub(b Big) Big

func (*Big) UnmarshalBSONValue

func (a *Big) UnmarshalBSONValue(t bsontype.Type, b []byte) error

func (*Big) UnmarshalJSON

func (a *Big) UnmarshalJSON(b []byte) error

type Bytes

type Bytes []byte

func NewBytes

func NewBytes(b []byte) Bytes

func NewBytesFromString

func NewBytesFromString(s string) Bytes

func (Bytes) Bytes

func (h Bytes) Bytes() []byte

func (Bytes) Equal

func (h Bytes) Equal(b util.Hash) bool

func (Bytes) IsValid

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

func (Bytes) MarshalText

func (h Bytes) MarshalText() ([]byte, error)

func (Bytes) String

func (h Bytes) String() string

func (*Bytes) UnmarshalText

func (h *Bytes) UnmarshalText(b []byte) error

type HashDecoder

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

func (HashDecoder) Hash

func (d HashDecoder) Hash() util.Hash

func (*HashDecoder) UnmarshalText

func (d *HashDecoder) UnmarshalText(b []byte) error

type HashGenerator

type HashGenerator interface {
	GenerateHash() util.Hash
}

Jump to

Keyboard shortcuts

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