stub

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: 23 Imported by: 2

Documentation

Overview

Package golang includes The runtime, which is just a stub that connects the cocoon code to the connector's RPC server. The runtime provides access to APIs for various operations.

Index

Constants

This section is empty.

Variables

View Source
var (

	// System link
	System = NewLink(types.SystemCocoonID)

	// Native link refers to a link that points
	// to the resources of a natively linked cocoon. If the current cocoon
	// has not native link to another cocoon, then the link points to its own resource
	Native = newNativeLink(GetID())

	// Me link refers to a link that points the resources of the current cocoon respective
	// of whether the cocoon is natively linked to another cocoon.
	Me = NewLink(GetCocoonID())

	// SourceDir is the root directory of the running cocoon code
	SourceDir = os.Getenv("SOURCE_DIR")

	// ViewDir is the directory where view files are stored
	ViewDir = path.Join(SourceDir, "/static/views")
)
View Source
var ErrLockNotAcquired = fmt.Errorf("lock not acquired")

ErrLockNotAcquired defines an error about a lock not acquired

View Source
var (
	// ErrNoTransaction represents a lack of transaction
	ErrNoTransaction = fmt.Errorf("no transaction")
)
View Source
var ErrObjectLocked = fmt.Errorf("failed to acquire lock. object has been locked by another process")

ErrObjectLocked reprents an error about an object or transaction locked by another process

View Source
var (
	// ErrViewNotFound indicates an unknown view file
	ErrViewNotFound = fmt.Errorf("view file not found")
)

Functions

func GetCocoonID

func GetCocoonID() string

GetCocoonID returns the unique cocoon id

func GetID

func GetID() string

GetID returns the cocoon id. However, it will return the natively linked cocoon id if this cocoon is linked to another cocoon.

func GetLogger

func GetLogger() *logging.Logger

GetLogger returns the stubs logger.

func GetSystemCocoonID

func GetSystemCocoonID() string

GetSystemCocoonID returns the system cocoon id

func GetSystemPublicLedgerName

func GetSystemPublicLedgerName() string

GetSystemPublicLedgerName returns the name of the system ledger.

func HasView

func HasView(name string) bool

HasView checks whether a view exists

func Render

func Render(name string, dataSource interface{}) ([]byte, error)

Render creates a View from am eml view file and a data source. Data source can be a map or a struct type. The created View is json encoded.

func RenderString

func RenderString(eml string, dataSource interface{}) (content []byte, err error)

RenderString creates a view from an eml component and a data source. Data source can be a map or a struct type.The created View is json encoded.

func Run

func Run(cc CocoonCode)

Run starts the stub server, takes a cocoon code and attempts to initialize it..

func SetDebugLevel

func SetDebugLevel(level logging.Level)

SetDebugLevel sets the default logger debug level

func Stop

func Stop(exitCode int)

Stop stub and cocoon code

Types

type CocoonCode

type CocoonCode interface {
	OnInit() error
	OnInvoke(header Metadata, function string, params []string) ([]byte, error)
	OnStop()
}

CocoonCode defines the interface of a cocoon code.

type Link struct {
	InMetadata Metadata // incoming metadata
	// contains filtered or unexported fields
}

Link provides access to all platform services available to the cocoon code.

func NewLink(cocoonID string) *Link

NewLink creates a new link to a cocoon

func (*Link) Get

func (link *Link) Get(ledgerName, key string) (*types.Transaction, error)

Get gets a transaction from a ledger

func (*Link) GetBlock

func (link *Link) GetBlock(ledgerName, id string) (*types.Block, error)

GetBlock gets a block from a ledger by a block id

func (*Link) GetCocoonID

func (link *Link) GetCocoonID() string

GetCocoonID returns the cocoon id attached to this link

func (*Link) GetIncomingMeta

func (link *Link) GetIncomingMeta() Metadata

GetIncomingMeta returns the metadata included in the link.

func (*Link) GetInvokeID

func (link *Link) GetInvokeID() string

GetInvokeID returns the transaction id of the invoke request. Returns an empty string if link was not created as a result of an invoke request

func (*Link) GetLedger

func (link *Link) GetLedger(ledgerName string) (*types.Ledger, error)

GetLedger fetches a ledger

func (*Link) IsNative

func (link *Link) IsNative() bool

IsNative checks whether the link is a native link

func (*Link) Lock

func (link *Link) Lock(key string, ttl time.Duration) (*Lock, error)

Lock acquires a lock on the specified key within the scope of the linked cocoon code. An error is returned if it failed to acquire the lock.

func (*Link) NewLedger

func (link *Link) NewLedger(name string, chained, public bool) (*types.Ledger, error)

NewLedger creates a new ledger by sending an invoke transaction (TxNewLedger) to the connector. If chained is set to true, a blockchain is created and subsequent PUT operations to the ledger will be included in the types. Otherwise, PUT operations will only be included in the types.

func (*Link) NewRangeGetter

func (link *Link) NewRangeGetter(ledgerName, start, end string, inclusive bool) *RangeGetter

NewRangeGetter creates an instance of a RangeGetter for a specified ledger.

func (*Link) Put

func (link *Link) Put(ledgerName, key string, value []byte) (*types.Transaction, error)

Put puts a transaction in a ledger

func (*Link) PutSafe

func (link *Link) PutSafe(revisionID, ledgerName, key string, value []byte) (*types.Transaction, error)

PutSafe puts a transaction and also ensures that no previous transaction references the revision id provided. If a previous transaction references the revision id, an ErrStateObject is returned. This is useful for situations where CAS (check-an-set) procedure is a requirement. Use the ID of previous transactions to ensure updates are not made based on records that may have been updated by another process.

type Lock

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

Lock defines a structure for a platform-wide lock mechanism

func (*Lock) Acquire

func (l *Lock) Acquire() error

Acquire will attempt to acquire a lock on the key within the cocoon scope defined in the lock instance. If successful, Lock object is returned. An acquired lock will also be enforced in other linked cocoon codes.

func (*Lock) IsAcquirer

func (l *Lock) IsAcquirer() error

IsAcquirer checks whether lock session is still active. If the lock is still active, nil is returned.

func (*Lock) Release

func (l *Lock) Release() error

Release release the lock. Returns nil if successful or if no lock was held.

type Metadata

type Metadata map[string]string

Metadata defines a structure for storing link related header information

func (Metadata) Get

func (m Metadata) Get(key string) string

Get returns the value of a key

func (Metadata) Has

func (m Metadata) Has(key string) bool

Has checks whether a key exists in the object

func (Metadata) Set

func (m Metadata) Set(key, val string)

Set sets a key and its value

type RangeGetter

type RangeGetter struct {
	Error error
	// contains filtered or unexported fields
}

RangeGetter defines a means to fetch keys of a specific range with support for

func NewRangeGetter

func NewRangeGetter(ledgerName, to, start, end string, inclusive bool) *RangeGetter

NewRangeGetter creates a new range getter to traverse a specific ledger. Set start and end key will get transactions between those keys. However, the end key is not included by default. Set inclusive to true to include the end key. Set only start to get all keys matching that key as a prefix or set only end key to get match keys as a surfix.

func (*RangeGetter) HasNext

func (rg *RangeGetter) HasNext() bool

HasNext determines whether more rows exists.

func (*RangeGetter) Next

func (rg *RangeGetter) Next() *types.Transaction

Next returns a transaction if available or nil

func (*RangeGetter) Reset

func (rg *RangeGetter) Reset()

Reset the state for reuse

type View

type View struct {
	Markup string `json:"markup"`
}

View represents a structure of a view

func (*View) ToJSON

func (v *View) ToJSON() []byte

ToJSON encodes the view to json

Directories

Path Synopsis
Package proto_runtime is a generated protocol buffer package.
Package proto_runtime is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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