types

package
v0.0.0-...-7b2e207 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: AGPL-3.0 Imports: 11 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// TxNewLedger represents a message to create a ledger
	TxNewLedger = "CREATE_LEDGER"

	// TxPut represents a message to create a transaction
	TxPut = "PUT"

	// TxGetLedger represents a message to get a ledger
	TxGetLedger = "GET_LEDGER"

	// TxGet represents a message to get a transaction
	TxGet = "GET"

	// TxGetBlockByID represents a message to get ledger's block by id
	TxGetBlockByID = "GET_BLOCK_BY_ID"

	// TxRangeGet represents a message to get a range of transactions
	TxRangeGet = "RANGE_GET"

	// OpLockAcquire represents a message to acquire a lock
	OpLockAcquire = "LOCK_ACQUIRE"

	// OpLockRelease represents a message to release a lock
	OpLockRelease = "LOCK_RELEASE"

	// OpLockCheckAcquire represents a message to check whether a session is still the acquirer of a lock
	OpLockCheckAcquire = "LOCK_CHECK_ACQUIRE"
)

Variables

View Source
var (
	// ErrCocoonCodeNotRunning indicates a launched cocoon that isn't running a cocoon code
	ErrCocoonCodeNotRunning = fmt.Errorf("cocoon code is not running")

	// ErrIdentityNotFound indicates a non-existing identity
	ErrIdentityNotFound = fmt.Errorf("identity not found")

	// ErrIdentityAlreadyExists indicates existence of an identity
	ErrIdentityAlreadyExists = fmt.Errorf("an identity with matching email already exists")

	// ErrLedgerNotFound indicates a missing ledger
	ErrLedgerNotFound = fmt.Errorf("ledger not found")

	// ErrTxNotFound indicates a missing transaction
	ErrTxNotFound = fmt.Errorf("transaction not found")

	// ErrChainNotFound indicates a missing chain
	ErrChainNotFound = fmt.Errorf("chain not found")

	// ErrZeroTransactions indicates a transaction list has zeto transactions
	ErrZeroTransactions = fmt.Errorf("zero transactions not allowed")

	// ErrBlockNotFound indicates a missing block
	ErrBlockNotFound = fmt.Errorf("block not found")

	// ErrOperationTimeout represents a timeout error that occurs when response
	// is not received from orderer in time.
	ErrOperationTimeout = fmt.Errorf("operation timed out")

	// ErrCocoonNotFound represents a missing/unknown cocoon
	ErrCocoonNotFound = fmt.Errorf("cocoon not found")

	// ErrInvalidOrExpiredToken represents an invalid/expired access token
	ErrInvalidOrExpiredToken = fmt.Errorf("access token is invalid or expired")

	// ErrClientNoActiveSession represents a lack of active user session on the client
	ErrClientNoActiveSession = fmt.Errorf("No active session. Please login")

	// ErrUninitializedStream represents a stream with nil value
	ErrUninitializedStream = fmt.Errorf("stream appears to be uninitialized")

	// ErrTransportClosing represents a grpc connection closing
	ErrTransportClosing = fmt.Errorf("transport is closing")

	// ErrInvalidResourceName represents an invalid name error
	ErrInvalidResourceName = fmt.Errorf("invalid resource name")

	// ErrLockAlreadyAcquired represents an error about an already acquired lock
	ErrLockAlreadyAcquired = fmt.Errorf("lock already acquired by another process")

	// ErrLockNotAcquired represents a lock on a key that is not acquired
	ErrLockNotAcquired = fmt.Errorf("lock not acquired")

	// ErrPermissionNotGrant is the error to send when the user does not have permission to perform an operation
	ErrPermissionNotGrant = fmt.Errorf("Permission denied: You do not have permission to perform this operation")
)
View Source
var (

	// SystemCocoonID represents the name to use when creating or accessing system resources
	SystemCocoonID = "system"
)

Functions

func GetActualKeyFromTxKey

func GetActualKeyFromTxKey(key string) string

GetActualKeyFromTxKey returns the real key name from a transaction key

func GetFlags

func GetFlags(v string) []string

GetFlags returns the flags from an environment variable

func GetSystemPrivateLedgerName

func GetSystemPrivateLedgerName() string

GetSystemPrivateLedgerName returns the system's private ledger name

func GetSystemPublicLedgerName

func GetSystemPublicLedgerName() string

GetSystemPublicLedgerName returns the systems public ledger name

func GetVarName

func GetVarName(v string) string

GetVarName returns the name of the variable without the flags

func IsDuplicatePrevBlockHashError

func IsDuplicatePrevBlockHashError(err error) bool

IsDuplicatePrevBlockHashError checks whether an error is one created when an ttempts to create a block with a prev block hash value already used.

func MakeCocoonEnvKey

func MakeCocoonEnvKey(cocoonID string) string

MakeCocoonEnvKey returns a key for storing a cocoon environment variable

func MakeCocoonKey

func MakeCocoonKey(id string) string

MakeCocoonKey constructs a cocoon key

func MakeIdentityKey

func MakeIdentityKey(id string) string

MakeIdentityKey constructs an identity key

func MakeLedgerName

func MakeLedgerName(namespace, name string) string

MakeLedgerName creates a ledger name for use for creating or querying a ledger. Accepts a namespace value and the ledger name.

func MakePrivateIdentityKey

func MakePrivateIdentityKey(identityID string) string

MakePrivateIdentityKey returns a key for storing private identity fields

func MakePrivateReleaseKey

func MakePrivateReleaseKey(releaseID string) string

MakePrivateReleaseKey returns a key for storing private release fields

func MakeReleaseKey

func MakeReleaseKey(id string) string

MakeReleaseKey constructs an release key

func MakeTxKey

func MakeTxKey(namespace, name string) string

MakeTxKey creates a transaction key name for storing and querying a transaction. Accepts a namespace value and the key name.

func ReplaceFlag

func ReplaceFlag(v, targetFlag, replacement string) (string, bool)

ReplaceFlag replaces a flag with another flag in a variable. if flag is not found, false is returned

Types

type ACLMap

type ACLMap map[string]interface{}

ACLMap represents an ACL rule collection

func NewACLMap

func NewACLMap(defValue map[string]interface{}) ACLMap

NewACLMap creates an ACLMap from a default value

func NewACLMapFromByte

func NewACLMapFromByte(aclByte []byte) ACLMap

NewACLMapFromByte takes a byte slice representing a json encoded ACL data and returns an ACLMap. If aclByte could not be coerced from JSON, an empty ACLMap is returned. Caller should ensure aclBytes is valid JSON.

func (ACLMap) Add

func (m ACLMap) Add(target, privileges string) error

Add a new entry.

func (ACLMap) Eql

func (m ACLMap) Eql(o ACLMap) bool

Eql checks whether another ACLMap is equal

func (ACLMap) Remove

func (m ACLMap) Remove(target string)

Remove removes a target and its value

func (ACLMap) ToJSON

func (m ACLMap) ToJSON() []byte

ToJSON returns a json encoded representation of the ACLMap

type Block

type Block struct {
	PK            uint   `json:"-" gorm:"primary_key"`
	ID            string `json:"id,omitempty" structs:"id,omitempty" mapstructure:"id,omitempty" gorm:"type:varchar(64);unique_index:idx_name_id"`
	Number        uint   `json:"number,omitempty" structs:"number,omitempty" mapstructure:"number,omitempty" sql:"DEFAULT:0"`
	ChainName     string `json:"chainName,omitempty" structs:"chainName,omitempty" mapstructure:"chainName,omitempty" gorm:"index:idx_name_chain_name"`
	PrevBlockHash string `` /* 165-byte string literal not displayed */
	Hash          string `` /* 127-byte string literal not displayed */
	Transactions  []byte `json:"transactions,omitempty" structs:"transactions,omitempty" mapstructure:"transactions,omitempty"`
	CreatedAt     int64  `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty" gorm:"index:idx_name_created_at"`
}

Block represents a table of chains

func (*Block) GetTransactions

func (b *Block) GetTransactions() ([]*Transaction, error)

GetTransactions returns a slice of transactions in the block.

func (*Block) ToJSON

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

ToJSON returns the json equivalent of this object

type Blockchain

type Blockchain interface {
	Connect(dbAddr string) (interface{}, error)
	Init() error
	GetImplementationName() string
	MakeChainName(namespace, name string) string
	CreateChain(name string, public bool) (*Chain, error)
	GetChain(name string) (*Chain, error)
	CreateBlock(id, chainName string, transactions []*Transaction) (*Block, error)
	GetBlock(chainName, id string) (*Block, error)
	Close() error
}

Blockchain defines an interface for a blockchain

type Chain

type Chain struct {
	Number    uint   `json:"number,omitempty" structs:"number,omitempty" mapstructure:"number,omitempty" gorm:"primary_key"`
	Name      string `` /* 134-byte string literal not displayed */
	Public    bool   `json:"public,omitempty" structs:"public,omitempty" mapstructure:"public,omitempty"`
	CreatedAt int64  `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty"`
}

Chain represents a table of chains

func (*Chain) ToJSON

func (c *Chain) ToJSON() []byte

ToJSON returns the json equivalent of this object

type Cocoon

type Cocoon struct {
	IdentityID            string         `json:"identityId,omitempty" structs:"identityId,omitempty" mapstructure:"identityId,omitempty"`
	ID                    string         `json:"id,omitempty" structs:"id,omitempty" mapstructure:"id,omitempty"`
	Memory                int            `json:"memory,omitempty" structs:"memory,omitempty" mapstructure:"memory,omitempty"`
	CPUShare              int            `json:"CPUShare,omitempty" structs:"CPUShare,omitempty" mapstructure:"CPUShare,omitempty"`
	NumSignatories        int            `json:"numSignatories,omitempty" structs:"numSignatories,omitempty" mapstructure:"numSignatories,omitempty"`
	SigThreshold          int            `json:"sigThreshold,omitempty" structs:"sigThreshold,omitempty" mapstructure:"sigThreshold,omitempty"`
	Releases              []string       `json:"release,omitempty" structs:"releases,omitempty" mapstructure:"releases,omitempty"`
	Signatories           []string       `json:"signatories,omitempty" structs:"signatories,omitempty" mapstructure:"signatories,omitempty"`
	Status                string         `json:"status,omitempty" structs:"status,omitempty" mapstructure:"status,omitempty"`
	LastDeployedReleaseID string         `` /* 127-byte string literal not displayed */
	ResourceUsage         *ResourceUsage `json:"resourceUsage,omitempty" structs:"resourceUsage,omitempty" mapstructure:"resourceUsage,omitempty"`
	CreatedAt             string         `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty"`
}

Cocoon represents a smart contract application

func (*Cocoon) Clone

func (c *Cocoon) Clone() Cocoon

Clone creates a clone of this object.

func (*Cocoon) Difference

func (c *Cocoon) Difference(o Cocoon) [][]mapdiff.DiffValue

Difference returns the difference between the current cocoon and another cocoon

func (*Cocoon) Merge

func (c *Cocoon) Merge(o interface{}) error

Merge merges another cocoon or map with current object replacing every non-empty value with non-empty values of the passed object.

func (*Cocoon) ToJSON

func (c *Cocoon) ToJSON() []byte

ToJSON returns the json equivalent of this object

func (*Cocoon) ToMap

func (c *Cocoon) ToMap() map[string]interface{}

ToMap returns the map equivalent of the object

func (*Cocoon) ToMapPtr

func (c *Cocoon) ToMapPtr() *map[string]interface{}

ToMapPtr same as ToMap but returns a pointer

type CtxKey

type CtxKey string

CtxKey represents keys used as context value keys

const (

	// CtxAuthToken represents an auth token from a request
	CtxAuthToken CtxKey = "auth_token"

	// CtxSessionID represents the session id from the auth token
	CtxSessionID CtxKey = "session_id"

	// CtxIdentity represents a user identity id
	CtxIdentity CtxKey = "identity"
)

type Env

type Env map[string]string

Env represents a collection of environment variables

func NewEnv

func NewEnv(val interface{}) Env

NewEnv creates a new Env type from values in map[string]interface{}. and map[string]string Non-string values are omitted.

func (Env) Eql

func (e Env) Eql(o Env) bool

Eql checks whether the object is equal to another

func (Env) Get

func (e Env) Get(f string) (string, bool)

Get returns the value of a variable

func (Env) GetByFlag

func (e Env) GetByFlag(flag string) Env

GetByFlag returns the variables that have a flag

func (Env) GetFull

func (e Env) GetFull(variable string) (string, string, bool)

GetFull returns the full name of a variable (name and flag) and its value. Any flag contained the the variable is removed.

func (Env) Has

func (e Env) Has(v string) bool

Has checks whether a variable exists

func (Env) Process

func (e Env) Process(keepFlags bool) (Env, Env)

Process applies the flags and returns both public environment variables and private variables. If keepFlag is set to true, the flags will not be removed in the result returned.

func (Env) ProcessAsOne

func (e Env) ProcessAsOne(keepFlags bool) Env

ProcessAsOne is like Process but returns the public and private environments merged as one Env

func (Env) Set

func (e Env) Set(v, value string)

Set adds a variable or overwrites an existing variable

func (Env) ToJSON

func (e Env) ToJSON() []byte

ToJSON returns a json encoded representation of the ENV

func (Env) ToMap

func (e Env) ToMap() map[string]string

ToMap returns the object as a map type

type Firewall

type Firewall []FirewallRule

Firewall defines a collection of firewall rules

func (Firewall) DeDup

func (f Firewall) DeDup() Firewall

DeDup removes duplicate firewall rules

func (Firewall) Eql

func (f Firewall) Eql(o Firewall) bool

Eql checks whether another firewall object is equal.

func (Firewall) ToMap

func (f Firewall) ToMap() []map[string]string

ToMap returns a slice of map[string]string version

type FirewallRule

type FirewallRule struct {
	Destination     string `structs:"destination" mapstructure:"destination,omitempty"`
	DestinationPort string `structs:"destinationPort" mapstructure:"destinationPort,omitempty"`
	Protocol        string `structs:"protocol" mapstructure:"protocol,omitempty"`
}

FirewallRule represents information about a destination to allow connections to.

func (FirewallRule) Eql

func (r FirewallRule) Eql(o FirewallRule) bool

Eql returns true if another firewall rule is equal

type Identity

type Identity struct {
	Email          string   `json:"email,omitempty" structs:"email,omitempty" mapstructure:"email,omitempty"`
	Password       string   `json:"password,omitempty" structs:"password,omitempty" mapstructure:"password,omitempty"`
	Cocoons        []string `json:"cocoons,omitempty" structs:"cocoons,omitempty" mapstructure:"cocoons,omitempty"`
	ClientSessions []string `json:"clientSessions,omitempty" structs:"clientSessions,omitempty" mapstructure:"clientSessions,omitempty"`
	CreatedAt      string   `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty"`
}

Identity defines a user

func NewIdentity

func NewIdentity(email, password string) *Identity

NewIdentity creates a new Identity

func (*Identity) GetID

func (i *Identity) GetID() string

GetID returns the hashed version of the email

func (*Identity) ToJSON

func (i *Identity) ToJSON() []byte

ToJSON returns the json equivalent of this object

type Ledger

type Ledger struct {
	Number       uint   `json:"number,omitempty" structs:"number,omitempty" mapstructure:"number,omitempty" gorm:"primary_key"`
	Name         string `` /* 128-byte string literal not displayed */
	NameInternal string `json:"-" structs:"nameInternal,omitempty" mapstructure:"nameInternal,omitempty" gorm:"-" sql:"-"`
	CocoonID     string `json:"cocoonId,omitempty" structs:"cocoonId,omitempty" mapstructure:"cocoonId,omitempty" gorm:"index:idx_name_cocoon_id"`
	Public       bool   `json:"public,omitempty" structs:"public,omitempty" mapstructure:"public,omitempty" json:"public"`
	Chained      bool   `json:"chained,omitempty" structs:"chained,omitempty" mapstructure:"chained,omitempty"`
	CreatedAt    int64  `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty" gorm:"index:idx_name_created_at"`
}

Ledger represents a group of transactions

func (*Ledger) ToJSON

func (l *Ledger) ToJSON() []byte

ToJSON returns the json equivalent of this object

type Lock

type Lock interface {
	// Acquire acquires a lock on key
	Acquire() error
	// Release release the lock held
	Release() error
	// IsAcquirer checks if the lock is still held
	IsAcquirer() error
	// GetState returns the state associated with the lock instance
	GetState() map[string]interface{}
	// SetState loads a lock state into the lock object
	SetState(map[string]interface{})
}

Lock defines an interface for implementing a lock mechanism.

type LogMessage

type LogMessage struct {
	ID        string
	Text      string
	Timestamp time.Time
}

LogMessage represents a log message

type LogProvider

type LogProvider interface {
	Init(config map[string]interface{}) error
	Get(context context.Context, logName string, numEntries int, source string) ([]LogMessage, error)
}

LogProvider provides an interface to accessing logs from a log storage provider

type PutResult

type PutResult struct {
	TxReceipts []*TxReceipt `json:"txReceipts,omitempty"`
	Block      *Block       `json:"block,omitempty"`
}

PutResult defines a structure for put operation ressult

type Release

type Release struct {
	ID          string   `json:"id,omitempty" structs:"id,omitempty" mapstructure:"id,omitempty"`
	CocoonID    string   `json:"cocoonID,omitempty" structs:"cocoonID,omitempty" mapstructure:"cocoonID,omitempty"`
	URL         string   `json:"URL,omitempty" structs:"URL,omitempty" mapstructure:"URL,omitempty"`
	Version     string   `json:"version,omitempty" structs:"version,omitempty" mapstructure:"version,omitempty"`
	Language    string   `json:"language,omitempty" structs:"language,omitempty" mapstructure:"language,omitempty"`
	BuildParam  string   `json:"buildParam,omitempty" structs:"buildParam,omitempty" mapstructure:"buildParam,omitempty"`
	Link        string   `json:"link,omitempty" structs:"link,omitempty" mapstructure:"link,omitempty"`
	SigApproved int      `json:"sigApproved,omitempty" structs:"sigApproved,omitempty" mapstructure:"sigApproved,omitempty"`
	SigDenied   int      `json:"sigDenied,omitempty" structs:"sigDenied,omitempty" mapstructure:"sigDenied,omitempty"`
	VotersID    []string `json:"votersID,omitempty" structs:"votersID,omitempty" mapstructure:"votersID,omitempty"`
	Firewall    Firewall `json:"firewall,omitempty" structs:"firewall,omitempty" mapstructure:"firewall,omitempty"`
	ACL         ACLMap   `json:"acl,omitempty" structs:"acl,omitempty" mapstructure:"acl,omitempty"`
	Env         Env      `json:"env,omitempty" structs:"env,omitempty" mapstructure:"env,omitempty"`
	CreatedAt   string   `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty"`
}

Release represents a new update to a cocoon's configuration

func (*Release) Clone

func (r *Release) Clone() Release

Clone creates a clone of this object

func (*Release) Difference

func (r *Release) Difference(o Release) [][]mapdiff.DiffValue

Difference returns the difference between the current release and another release

func (*Release) Merge

func (r *Release) Merge(o interface{}) error

Merge merges another release or map with current object replacing every non-empty value with non-empty values of the passed object.

func (*Release) ToJSON

func (r *Release) ToJSON() []byte

ToJSON returns the json equivalent of this object

func (*Release) ToMap

func (r *Release) ToMap() map[string]interface{}

ToMap returns the map equivalent of the object

func (*Release) ToMapPtr

func (r *Release) ToMapPtr() *map[string]interface{}

ToMapPtr same as ToMap but returns a pointer

type ResourceUsage

type ResourceUsage struct {
	NetIn  uint64 `json:"netIn,omitempty" structs:"netIn,omitempty" mapstructure:"netIn,omitempty"`
	NetOut uint64 `json:"netOut,omitempty" structs:"netOut,omitempty" mapstructure:"netOut,omitempty"`
}

ResourceUsage represents resources used by a cocoon

type Spec

type Spec struct {
	ID          string
	Cocoon      *Cocoon
	URL         string
	Version     string
	Lang        string
	DiskLimit   int64
	BuildParams string
	Link        string
	Memory      int64
	CPUShare    int64
	ReleaseID   string
	Release     *Release
}

Spec represents all the required deployment information required by a connector to operate

type Store

type Store interface {
	Connect(dbAddr string) (interface{}, error)
	Init(systemPublicLedgerName, systemPrivateLedgerName string) error
	SetBlockchainImplementation(b Blockchain)
	GetImplementationName() string
	CreateLedger(cocoonID, name string, chained, public bool) (*Ledger, error)
	CreateLedgerThen(cocoonID, name string, chained, public bool, then func() error) (*Ledger, error)
	GetLedger(name string) (*Ledger, error)
	Put(ledger string, txs []*Transaction) ([]*TxReceipt, error)
	PutThen(ledger string, txs []*Transaction, then func(validTxs []*Transaction) error) ([]*TxReceipt, error)
	Get(ledger, key string) (*Transaction, error)
	GetRange(ledger, startKey, endKey string, inclusive bool, limit, lastNum int) ([]*Transaction, error)
	Close() error
}

Store defines an interface required for the implementation of a data structure for creating and reading ledgers and transactions.

type Transaction

type Transaction struct {
	Number         uint   `json:"number,omitempty" structs:"number,omitempty" mapstructure:"number,omitempty" gorm:"primary_key"`
	Ledger         string `` /* 134-byte string literal not displayed */
	ID             string `json:"id,omitempty" structs:"id,omitempty" mapstructure:"id,omitempty" gorm:"type:varchar(64);unique_index:idx_name_id"`
	Key            string `json:"key,omitempty" structs:"key,omitempty" mapstructure:"key,omitempty" gorm:"type:varchar(128);index:idx_name_key"`
	Value          string `json:"value,omitempty" structs:"value,omitempty" mapstructure:"value,omitempty" gorm:"type:text"`
	Hash           string `` /* 127-byte string literal not displayed */
	BlockID        string `json:"blockId,omitempty" structs:"blockId,omitempty" mapstructure:"blockId,omitempty"`
	RevisionTo     string `` /* 171-byte string literal not displayed */
	CreatedAt      int64  `json:"createdAt,omitempty" structs:"createdAt,omitempty" mapstructure:"createdAt,omitempty" gorm:"index:idx_name_created_at"`
	LedgerInternal string `json:"-" structs:"-" mapstructure:"-" gorm:"-" sql:"-"`
	KeyInternal    string `json:"-" structs:"-" mapstructure:"-" gorm:"-" sql:"-"`
	Block          *Block `json:"block" structs:"block" mapstructure:"block,omitempty" gorm:"-" sql:"-"`
}

Transaction reprents a group of transactions belonging to a ledger. All transaction entries must reference the hash of the immediate transaction sharing the same ledger name.

func (*Transaction) MakeHash

func (t *Transaction) MakeHash() string

MakeHash creates a hash of a transaction

func (*Transaction) ToJSON

func (t *Transaction) ToJSON() []byte

ToJSON returns the json equivalent of this object

type TxReceipt

type TxReceipt struct {
	ID  string `json:"id,omitempty"`
	Err string `json:"err,omitempty"`
}

TxReceipt defines a structure for representing transaction status from endpoint that manipulate transactions

type UserSession

type UserSession struct {
	Email string `json:"email,omitempty" structs:"email,omitempty" mapstructure:"email,omitempty"`
	Token string `json:"hash,omitempty" structs:"hash,omitempty" mapstructure:"hash,omitempty"`
}

UserSession represents a user session

func (*UserSession) ToJSON

func (u *UserSession) ToJSON() []byte

ToJSON returns json encoding of instance

Jump to

Keyboard shortcuts

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