types

package
v0.0.0-...-215cb89 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: GPL-3.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const AttributesLimit = 500

Variables

View Source
var (
	NoSuchAttribute = errors.New("no such attribute name")
	DurExtendLimit  = errors.New("authorization duration exceeds limit")
	ExistAttr       = errors.New("attribute added is existed")
)
View Source
var (
	UnKnownAddress = errors.New("unknown address in global state")
	MisMatchNonce  = errors.New("nonce mismatch between authorization/operation and account state")
	//NoPermission      = errors.New("authorization/operation without permission")
	NoPermissionForGm = errors.New("no permission of attribute with prefix of gm")
)

Functions

func GetSenderAddrFromAuth

func GetSenderAddrFromAuth(auth *Authorization) (*cryptoType.Address, error)

Types

type AccountState

type AccountState struct {
	Address    *cryptoType.Address
	Attributes map[string]*commonType.Attribute
	Nonce      uint64
	// contains filtered or unexported fields
}

func GenerateTestAccountState

func GenerateTestAccountState() *AccountState

func JsonToAccountState

func JsonToAccountState(asJson []byte) *AccountState

func NewAccountState

func NewAccountState(address *cryptoType.Address, attributes []*commonType.Attribute, nonce uint64) *AccountState

func (*AccountState) AddAttribute

func (as *AccountState) AddAttribute(attribute *commonType.Attribute) bool

func (*AccountState) AddAttributes

func (as *AccountState) AddAttributes(attributes []*commonType.Attribute) bool

func (*AccountState) AddNonce

func (as *AccountState) AddNonce() bool

func (*AccountState) CheckAttribute

func (as *AccountState) CheckAttribute(attribute *commonType.Attribute) (bool, error)

func (*AccountState) CheckAttributes

func (as *AccountState) CheckAttributes(attributes []*commonType.Attribute) (bool, error)

func (*AccountState) CheckAuthorization

func (as *AccountState) CheckAuthorization(auth *Authorization) (bool, error)

func (*AccountState) DeepCopy

func (as *AccountState) DeepCopy() *AccountState

func (*AccountState) ToJson

func (as *AccountState) ToJson() []byte

func (*AccountState) ToMap

func (as *AccountState) ToMap() map[string]interface{}

func (*AccountState) ToString

func (as *AccountState) ToString() string

type AuthList

type AuthList map[uint64]*Authorization

func NewAuthList

func NewAuthList() *AuthList

func (*AuthList) Add

func (al *AuthList) Add(auth *Authorization) bool

func (*AuthList) Remove

func (al *AuthList) Remove(nonce uint64) bool

func (*AuthList) ToJson

func (al *AuthList) ToJson() []byte

func (*AuthList) ToMap

func (al *AuthList) ToMap() map[string]interface{}

func (*AuthList) ToString

func (al *AuthList) ToString() string

type AuthPool

type AuthPool struct {
	Pending map[cryptoTypes.Address]*AuthList `json:"pending"`
	// contains filtered or unexported fields
}

func JsonToAuthPool

func JsonToAuthPool(b []byte) *AuthPool

func NewAuthPool

func NewAuthPool(pendingAuths []*Authorization) (*AuthPool, error)

func (*AuthPool) AddAuthorization

func (authPool *AuthPool) AddAuthorization(auth *Authorization) (bool, error)

add authorization into authPool, exactly into the authList in the pool

func (*AuthPool) ChooseAuthorizations

func (authPool *AuthPool) ChooseAuthorizations(limit uint64, state *GlobalState) []*Authorization

func (*AuthPool) DeleteAuth

func (authPool *AuthPool) DeleteAuth(auth *Authorization) error

func (*AuthPool) DeleteAuths

func (authPool *AuthPool) DeleteAuths(auths []*Authorization)

func (*AuthPool) ToJson

func (authPool *AuthPool) ToJson() []byte

func (*AuthPool) ToString

func (authPool *AuthPool) ToString() string

type Authorization

type Authorization struct {
	Recipient  *cryptoType.Address
	Attributes []*types.Attribute
	Nonce      uint64
	Signature  *cryptoType.Signature
}

func GenerateTestAuthorization

func GenerateTestAuthorization() *Authorization

generate fake authorization used for test

func NewAuthorization

func NewAuthorization(recipient *cryptoType.Address, attributes []*types.Attribute, nonce uint64) Authorization

func NewAuthorizationFromJson

func NewAuthorizationFromJson(authJson []byte) *Authorization

func (*Authorization) AddAttribute

func (auth *Authorization) AddAttribute(attr *types.Attribute) bool

func (*Authorization) Bytes

func (auth *Authorization) Bytes() []byte

func (*Authorization) CalcHash

func (auth *Authorization) CalcHash() *cryptoType.Hash

func (*Authorization) CheckSignature

func (auth *Authorization) CheckSignature() bool

func (*Authorization) DeepCopy

func (auth *Authorization) DeepCopy() *Authorization

func (*Authorization) Sign

func (auth *Authorization) Sign(signature *cryptoType.Signature)

func (*Authorization) ToJson

func (auth *Authorization) ToJson() []byte

func (*Authorization) ToMap

func (auth *Authorization) ToMap() map[string]interface{}

func (*Authorization) ToPrettyJson

func (auth *Authorization) ToPrettyJson() []byte

func (*Authorization) ToString

func (auth *Authorization) ToString() string

type Block

type Block struct {
	Header         *Header
	Authorizations []*Authorization
}

func GenerateTestBlock

func GenerateTestBlock() *Block

generate random block for testing

func JsonToBlock

func JsonToBlock(blockJson []byte) *Block

func NewBlock

func NewBlock(h *Header, auths []*Authorization) *Block

func (*Block) CalcAuthRoot

func (b *Block) CalcAuthRoot() *cryptoType.Hash

func (*Block) CalcHash

func (b *Block) CalcHash() *cryptoType.Hash

func (*Block) DeepCopy

func (b *Block) DeepCopy() *Block

func (*Block) SetRoot

func (b *Block) SetRoot()

func (*Block) ToIndexMap

func (b *Block) ToIndexMap() *map[string]interface{}

func (*Block) ToJson

func (b *Block) ToJson() []byte

func (*Block) ToMap

func (b *Block) ToMap() *map[string]interface{}

func (*Block) ToPrettyJson

func (b *Block) ToPrettyJson() []byte

func (*Block) ToString

func (b *Block) ToString() string

type Config

type Config struct {
	GmList   map[types.Address]string
	PreAuths []*Authorization
	// the paths of db storing data and blockchain
	DataDB  string
	ChainDB string
}

func GenerateConfig

func GenerateConfig() Config

type GlobalState

type GlobalState struct {
	GmList map[cryptoType.Address]string
	States map[cryptoType.Address]*AccountState
	// contains filtered or unexported fields
}

func NewGlobalState

func NewGlobalState(gmList map[cryptoType.Address]string, preStates []*AccountState) *GlobalState

func (*GlobalState) AcceptAuthorization

func (gState *GlobalState) AcceptAuthorization(auth *Authorization) (bool, error)

func (*GlobalState) AcceptAuthorizations

func (gState *GlobalState) AcceptAuthorizations(auths []*Authorization) bool

func (*GlobalState) AddState

func (gState *GlobalState) AddState(aState *AccountState) bool

func (*GlobalState) CalcHash

func (gState *GlobalState) CalcHash() *cryptoType.Hash

func (*GlobalState) CheckAuthorization

func (gState *GlobalState) CheckAuthorization(auth *Authorization) (bool, error)

check authorization from current global state, return answer and error

func (*GlobalState) CheckAuthorizations

func (gState *GlobalState) CheckAuthorizations(auths []*Authorization) bool

func (*GlobalState) DeepCopy

func (gState *GlobalState) DeepCopy() *GlobalState

func (*GlobalState) GetAccountNonce

func (gState *GlobalState) GetAccountNonce(addr *cryptoType.Address) uint64

func (*GlobalState) GetAccountState

func (gState *GlobalState) GetAccountState(address *cryptoType.Address) *AccountState

func (*GlobalState) GetAttrsFromAddr

func (gState *GlobalState) GetAttrsFromAddr(address *cryptoType.Address) (bool, []string)

func (*GlobalState) ToJson

func (gState *GlobalState) ToJson() []byte

func (*GlobalState) ToMap

func (gState *GlobalState) ToMap() map[string]interface{}

func (*GlobalState) ToString

func (gState *GlobalState) ToString() string
type Header struct {
	ParentHash *cryptoType.Hash
	AuthRoot   *cryptoType.Hash
	//StateRoot     *types.Hash
	Timestamp commonType.Timestamp
}

func GenerateTestHeader

func GenerateTestHeader() *Header

func NewHeader

func NewHeader(parentHash *cryptoType.Hash, authRoot *cryptoType.Hash, timestamp commonType.Timestamp) *Header

create new header

func (*Header) DeepCopy

func (h *Header) DeepCopy() *Header

func (*Header) PrettyPrint

func (h *Header) PrettyPrint()

func (*Header) SetAuthRoot

func (h *Header) SetAuthRoot(authRoot *cryptoType.Hash)

func (*Header) ToBytes

func (h *Header) ToBytes() []byte

func (*Header) ToJson

func (h *Header) ToJson() []byte

func (*Header) ToMap

func (h *Header) ToMap() *map[string]interface{}

func (*Header) ToPrettyJson

func (h *Header) ToPrettyJson() []byte

func (*Header) ToString

func (h *Header) ToString() string

Jump to

Keyboard shortcuts

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