Documentation ¶
Index ¶
- Constants
- Variables
- func GetSenderAddrFromAuth(auth *Authorization) (*cryptoType.Address, error)
- type AccountState
- func (as *AccountState) AddAttribute(attribute *commonType.Attribute) bool
- func (as *AccountState) AddAttributes(attributes []*commonType.Attribute) bool
- func (as *AccountState) AddNonce() bool
- func (as *AccountState) CheckAttribute(attribute *commonType.Attribute) (bool, error)
- func (as *AccountState) CheckAttributes(attributes []*commonType.Attribute) (bool, error)
- func (as *AccountState) CheckAuthorization(auth *Authorization) (bool, error)
- func (as *AccountState) DeepCopy() *AccountState
- func (as *AccountState) ToJson() []byte
- func (as *AccountState) ToMap() map[string]interface{}
- func (as *AccountState) ToString() string
- type AuthList
- type AuthPool
- func (authPool *AuthPool) AddAuthorization(auth *Authorization) (bool, error)
- func (authPool *AuthPool) ChooseAuthorizations(limit uint64, state *GlobalState) []*Authorization
- func (authPool *AuthPool) DeleteAuth(auth *Authorization) error
- func (authPool *AuthPool) DeleteAuths(auths []*Authorization)
- func (authPool *AuthPool) ToJson() []byte
- func (authPool *AuthPool) ToString() string
- type Authorization
- func (auth *Authorization) AddAttribute(attr *types.Attribute) bool
- func (auth *Authorization) Bytes() []byte
- func (auth *Authorization) CalcHash() *cryptoType.Hash
- func (auth *Authorization) CheckSignature() bool
- func (auth *Authorization) DeepCopy() *Authorization
- func (auth *Authorization) Sign(signature *cryptoType.Signature)
- func (auth *Authorization) ToJson() []byte
- func (auth *Authorization) ToMap() map[string]interface{}
- func (auth *Authorization) ToPrettyJson() []byte
- func (auth *Authorization) ToString() string
- type Block
- func (b *Block) CalcAuthRoot() *cryptoType.Hash
- func (b *Block) CalcHash() *cryptoType.Hash
- func (b *Block) DeepCopy() *Block
- func (b *Block) SetRoot()
- func (b *Block) ToIndexMap() *map[string]interface{}
- func (b *Block) ToJson() []byte
- func (b *Block) ToMap() *map[string]interface{}
- func (b *Block) ToPrettyJson() []byte
- func (b *Block) ToString() string
- type Config
- type GlobalState
- func (gState *GlobalState) AcceptAuthorization(auth *Authorization) (bool, error)
- func (gState *GlobalState) AcceptAuthorizations(auths []*Authorization) bool
- func (gState *GlobalState) AddState(aState *AccountState) bool
- func (gState *GlobalState) CalcHash() *cryptoType.Hash
- func (gState *GlobalState) CheckAuthorization(auth *Authorization) (bool, error)
- func (gState *GlobalState) CheckAuthorizations(auths []*Authorization) bool
- func (gState *GlobalState) DeepCopy() *GlobalState
- func (gState *GlobalState) GetAccountNonce(addr *cryptoType.Address) uint64
- func (gState *GlobalState) GetAccountState(address *cryptoType.Address) *AccountState
- func (gState *GlobalState) GetAttrsFromAddr(address *cryptoType.Address) (bool, []string)
- func (gState *GlobalState) ToJson() []byte
- func (gState *GlobalState) ToMap() map[string]interface{}
- func (gState *GlobalState) ToString() string
- type Header
- func (h *Header) DeepCopy() *Header
- func (h *Header) PrettyPrint()
- func (h *Header) SetAuthRoot(authRoot *cryptoType.Hash)
- func (h *Header) ToBytes() []byte
- func (h *Header) ToJson() []byte
- func (h *Header) ToMap() *map[string]interface{}
- func (h *Header) ToPrettyJson() []byte
- func (h *Header) ToString() string
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
type AuthPool ¶
type AuthPool struct { Pending map[cryptoTypes.Address]*AuthList `json:"pending"` // contains filtered or unexported fields }
func JsonToAuthPool ¶
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)
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 JsonToBlock ¶
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) ToIndexMap ¶
func (*Block) ToPrettyJson ¶
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 ¶
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) PrettyPrint ¶
func (h *Header) PrettyPrint()
func (*Header) SetAuthRoot ¶
func (h *Header) SetAuthRoot(authRoot *cryptoType.Hash)
func (*Header) ToPrettyJson ¶
Click to show internal directories.
Click to hide internal directories.