Documentation ¶
Index ¶
- Constants
- Variables
- func GetActualKeyFromTxKey(key string) string
- func GetFlags(v string) []string
- func GetSystemPrivateLedgerName() string
- func GetSystemPublicLedgerName() string
- func GetVarName(v string) string
- func IsDuplicatePrevBlockHashError(err error) bool
- func MakeCocoonEnvKey(cocoonID string) string
- func MakeCocoonKey(id string) string
- func MakeIdentityKey(id string) string
- func MakeLedgerName(namespace, name string) string
- func MakePrivateIdentityKey(identityID string) string
- func MakePrivateReleaseKey(releaseID string) string
- func MakeReleaseKey(id string) string
- func MakeTxKey(namespace, name string) string
- func ReplaceFlag(v, targetFlag, replacement string) (string, bool)
- type ACLMap
- type Block
- type Blockchain
- type Chain
- type Cocoon
- type CtxKey
- type Env
- func (e Env) Eql(o Env) bool
- func (e Env) Get(f string) (string, bool)
- func (e Env) GetByFlag(flag string) Env
- func (e Env) GetFull(variable string) (string, string, bool)
- func (e Env) Has(v string) bool
- func (e Env) Process(keepFlags bool) (Env, Env)
- func (e Env) ProcessAsOne(keepFlags bool) Env
- func (e Env) Set(v, value string)
- func (e Env) ToJSON() []byte
- func (e Env) ToMap() map[string]string
- type Firewall
- type FirewallRule
- type Identity
- type Ledger
- type Lock
- type LogMessage
- type LogProvider
- type PutResult
- type Release
- type ResourceUsage
- type Spec
- type Store
- type Transaction
- type TxReceipt
- type UserSession
Constants ¶
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 ¶
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") )
var (
// SystemCocoonID represents the name to use when creating or accessing system resources
SystemCocoonID = "system"
)
Functions ¶
func GetActualKeyFromTxKey ¶
GetActualKeyFromTxKey returns the real key name from a transaction key
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 ¶
GetVarName returns the name of the variable without the flags
func IsDuplicatePrevBlockHashError ¶
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 ¶
MakeCocoonEnvKey returns a key for storing a cocoon environment variable
func MakeIdentityKey ¶
MakeIdentityKey constructs an identity key
func MakeLedgerName ¶
MakeLedgerName creates a ledger name for use for creating or querying a ledger. Accepts a namespace value and the ledger name.
func MakePrivateIdentityKey ¶
MakePrivateIdentityKey returns a key for storing private identity fields
func MakePrivateReleaseKey ¶
MakePrivateReleaseKey returns a key for storing private release fields
func MakeReleaseKey ¶
MakeReleaseKey constructs an release key
func MakeTxKey ¶
MakeTxKey creates a transaction key name for storing and querying a transaction. Accepts a namespace value and the key name.
func ReplaceFlag ¶
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 NewACLMapFromByte ¶
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.
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.
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
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"` 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) Difference ¶
Difference returns the difference between the current cocoon and another cocoon
func (*Cocoon) Merge ¶
Merge merges another cocoon or map with current object replacing every non-empty value with non-empty values of the passed object.
type Env ¶
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) GetFull ¶
GetFull returns the full name of a variable (name and flag) and its value. Any flag contained the the variable is removed.
func (Env) Process ¶
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 ¶
ProcessAsOne is like Process but returns the public and private environments merged as one Env
type Firewall ¶
type Firewall []FirewallRule
Firewall defines a collection of firewall rules
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 ¶
NewIdentity creates a new Identity
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
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 ¶
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) Difference ¶
Difference returns the difference between the current release and another release
func (*Release) Merge ¶
Merge merges another release or map with current object replacing every non-empty value with non-empty values of the passed object.
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 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 ¶
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