router

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package router provides base router for using in chaincode Invoke function

Index

Constants

View Source
const InitFunc = `init`

Variables

View Source
var (
	// ErrMethodNotFound occurs when trying to invoke non existent chaincode method
	ErrMethodNotFound = errors.New(`chaincode method not found`)

	// ErrArgsNumMismatch occurs when the number of declared and the number of arguments passed does not match
	ErrArgsNumMismatch = errors.New(`chaincode method args count mismatch`)

	// ErrHandlerError error in handler
	ErrHandlerError = errors.New(`router handler error`)
)

Functions

This section is empty.

Types

type Chaincode

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

Chaincode default chaincode implementation with router

func NewChaincode

func NewChaincode(r *Group) *Chaincode

NewChaincode new default chaincode implementation

func (*Chaincode) Init

======== Base methods ====================================

Init initializes chain code - sets chaincode "owner"

func (*Chaincode) Invoke

Invoke - entry point for chain code invocations

type Context

type Context interface {
	Stub() shim.ChaincodeStubInterface
	Client() (cid.ClientIdentity, error)
	Response() Response
	Logger() *shim.ChaincodeLogger
	Path() string
	State() State
	Time() (time.Time, error)
	Args() InterfaceMap
	Arg(string) interface{}
	ArgString(string) string
	ArgBytes(string) []byte
	ArgInt(string) int
	SetArg(string, interface{})
	Get(string) interface{}
	Set(string, interface{})
	SetEvent(string, interface{}) error
}

Context of chaincode invoke

type ContextHandlerFunc

type ContextHandlerFunc func(Context) peer.Response

ContextHandlerFunc use stub context as input parameter

type ContextMiddlewareFunc

type ContextMiddlewareFunc func(ContextHandlerFunc, ...int) ContextHandlerFunc

ContextMiddlewareFunc middleware for ContextHandlerFun

type ContextResponse

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

ContextResponse implementation

func (ContextResponse) Create

func (c ContextResponse) Create(data interface{}, err interface{}) peer.Response

Create returns error response if err != nil

func (ContextResponse) Error

func (c ContextResponse) Error(err interface{}) peer.Response

Error response

func (ContextResponse) Success

func (c ContextResponse) Success(data interface{}) peer.Response

Success response

type ContextState

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

func (ContextState) Delete

func (s ContextState) Delete(key interface{}) (err error)

func (ContextState) Exists

func (s ContextState) Exists(key interface{}) (exists bool, err error)

func (ContextState) Get

func (s ContextState) Get(key interface{}, target ...interface{}) (result interface{}, err error)

func (ContextState) GetHistory

func (s ContextState) GetHistory(key interface{}, target interface{}) (result state.HistoryEntryList, err error)

func (ContextState) GetInt

func (s ContextState) GetInt(key interface{}, defaultValue int) (result int, err error)

func (ContextState) Insert

func (s ContextState) Insert(key interface{}, value ...interface{}) (err error)

func (ContextState) List

func (s ContextState) List(objectType interface{}, target interface{}) (result []interface{}, err error)

func (ContextState) Put

func (s ContextState) Put(key interface{}, value ...interface{}) (err error)

type Group

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

Group of chain code functions

func New

func New(name string) *Group

New group of chain code functions

func (*Group) Context

func (g *Group) Context(path string, stub shim.ChaincodeStubInterface) Context

Context returns chain code invoke context for provided path and stub

func (*Group) ContextHandler

func (g *Group) ContextHandler(path string, fn ContextHandlerFunc) *Group

ContextHandler adds new context handler using presented path

func (*Group) Group

func (g *Group) Group(path string) *Group

Group gets new group using presented path New group can be used as independent

func (*Group) Handle

func (g *Group) Handle(stub shim.ChaincodeStubInterface) peer.Response

Handle used for using in CC Invoke function Must be called after adding new routes using Add function

func (*Group) HandleFunc

func (g *Group) HandleFunc(fnString string, stub shim.ChaincodeStubInterface) peer.Response

func (*Group) HandleInit

func (g *Group) HandleInit(stub shim.ChaincodeStubInterface) peer.Response

HandleInit handle chaincode init method

func (*Group) Init

func (g *Group) Init(handler HandlerFunc, middleware ...MiddlewareFunc) *Group

func (*Group) Invoke

func (g *Group) Invoke(path string, handler HandlerFunc, middleware ...MiddlewareFunc) *Group

Invoke configure handler and middleware functions for chain code function name

func (*Group) Pre

func (g *Group) Pre(middleware ...MiddlewareFunc) *Group

func (*Group) Query

func (g *Group) Query(path string, handler HandlerFunc, middleware ...MiddlewareFunc) *Group

Query alias for invoke

func (*Group) StubHandler

func (g *Group) StubHandler(path string, fn StubHandlerFunc) *Group

StubHandler adds new stub handler using presented path

func (*Group) Use

func (g *Group) Use(middleware ...MiddlewareFunc) *Group

Use middleware function in chain code functions group

type HandlerFunc

type HandlerFunc func(Context) (interface{}, error)

HandlerFunc returns result as interface and error, this is converted to peer.Response via response.Create

type InterfaceMap

type InterfaceMap map[string]interface{}

InterfaceMap map of interfaces

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc, ...int) HandlerFunc

MiddlewareFunc middleware for HandlerFunc

type Response

type Response interface {
	Error(err interface{}) peer.Response
	Success(data interface{}) peer.Response
	Create(data interface{}, err interface{}) peer.Response
}

Response chaincode interface

type State

type State interface {
	Get(key interface{}, target ...interface{}) (result interface{}, err error)
	GetInt(key interface{}, defaultValue int) (result int, err error)
	GetHistory(key interface{}, target interface{}) (result state.HistoryEntryList, err error)
	Exists(key interface{}) (exists bool, err error)
	Put(key interface{}, value ...interface{}) (err error)
	Insert(key interface{}, value ...interface{}) (err error)
	List(objectType interface{}, target interface{}) (result []interface{}, err error)
	Delete(key interface{}) (err error)
}

State interface for chain code CRUD operations

type StubHandlerFunc

type StubHandlerFunc func(shim.ChaincodeStubInterface) peer.Response

StubHandlerFunc acts as raw chaincode invoke method, accepts stub and returns peer.Response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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