request

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: BSD-3-Clause Imports: 20 Imported by: 1

README

Fabric Request activity

This Flogo activity contribution can be configured to send invoke or query request from a client app to a specified chaincode deployed on a Fabric network. Most of the request operations are demonstrated in the contract example.

Configuration and Inputs

This operation can be configured to support all types of client requests for Fabric chaincode, e.g.,

    "activity": {
        "ref": "#request",
        "settings": {
            "connectionName": "=$property[\"NETWORK\"]",
            "channelID": "=$property[\"CHANNEL\"]",
            "chaincodeID": "=$property[\"CHAINCODE\"]",
            "transactionName": "queryMarblesByOwner",
            "parameters": "owner",
            "requestType": "query",
            "userOrgOnly": false
        },
        "input": {
            "parameters": "=$flow.parameters",
            "transient": {},
            "userName": "=$flow.user",
            "timeoutMillis": 0,
            "endpoints": []
        }
    }

Notes on the configuration and input parameters:

  • connectionName identifies a Fabric network, e.g., test-network. The network configuration and local entity matchers patterns are not configured by the activity. Instead, they are provided when the application is built by using the command flogo configfabric. This late binding approach provides more flexibility for building an app model for multiple chaincode deployments.
  • parameters under settings contain a comma-delimited names of parameters of the specified transaction. It defines the sequence of the parameters in the input.
  • requestType is invoke or query. You may use query for read-only operations, and so it will not go through the endorsment process.
  • userOrgOnly specifies an end-point filter. When it is turned on, the request will be sent to only the peers of the user's organization.
  • transient specifies transient data that should not be sent to distributed ledger, nor orderer processes.
  • userName specifies user@org that is used to invoke chaincode transactions. The user must be a valid blockchain user with CA crypto data accessible by the HTTP server. The org is optional, which specifies the user's organization as specified in the Fabric network config file. If org is not specified, the user is assumed to be part of the client organization specified by the Fabric network configuration.
  • timeoutMillis specifies the wait time for responses from the Fabric network.
  • endpoints is a list of peers to send the request to. It is typically left blank, and so the SDK will randomly choose an available peer to send the Fabric request. This list, if specified, overrides the settings for userOrgOnly.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EntityMatcher []byte

EntityMatcher is the content of fabric local entity matcher file

View Source
var NetworkConfig []byte

NetworkConfig is the content of fabric network config file

Functions

func InitializeNetwork

func InitializeNetwork(config, matcher []byte)

InitializeNetwork can be called to initialize Fabric network config

func New

New creates a new Activity

func ReadFile

func ReadFile(filePath string) ([]byte, error)

ReadFile returns content of a specified file

func Subst

func Subst(path string) string

Subst replaces instances of '${VARNAME}' (eg ${GOPATH}) with the variable. Variables names that are not set by the SDK are replaced with the environment variable.

Types

type Activity

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

Activity fabric request activity struct

func (*Activity) Eval

func (a *Activity) Eval(ctx activity.Context) (done bool, err error)

Eval implements activity.Activity.Eval

func (*Activity) Metadata

func (a *Activity) Metadata() *activity.Metadata

Metadata implements activity.Activity.Metadata

type Attribute

type Attribute struct {
	Name string `md:"name"`
	Type string `md:"type"`
}

Attribute describes a name and data type

func (*Attribute) String

func (p *Attribute) String() string

type ConnectorSpec

type ConnectorSpec struct {
	Name           string
	NetworkConfig  []byte
	EntityMatchers []byte
	OrgName        string
	UserName       string
	ChannelID      string
	TimeoutMillis  int
	Endpoints      []string
	UserOrgOnly    bool
}

ConnectorSpec contains configuration parameters of a Fabric connector

type FabricClient

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

FabricClient holds fabric client pointers for chaincode invocations.

func NewFabricClient

func NewFabricClient(config ConnectorSpec) (*FabricClient, error)

NewFabricClient returns a new or cached fabric client

func (*FabricClient) Close

func (c *FabricClient) Close()

Close closes Fabric client connection

func (*FabricClient) ExecuteChaincode

func (c *FabricClient) ExecuteChaincode(ccID, fcn string, args [][]byte, transient map[string][]byte) ([]byte, int, error)

ExecuteChaincode sends invocation request to Fabric network

func (*FabricClient) QueryChaincode

func (c *FabricClient) QueryChaincode(ccID, fcn string, args [][]byte, transient map[string][]byte) ([]byte, int, error)

QueryChaincode sends query request to Fabric network

type Input

type Input struct {
	OrgName       string                 `md:"orgName"`
	UserName      string                 `md:"userName,required"`
	Parameters    map[string]interface{} `md:"parameters"`
	Transient     map[string]interface{} `md:"transient"`
	TimeoutMillis int                    `md:"timeoutMillis"`
	Endpoints     []string               `md:"endpoints"`
}

Input of the activity

func (*Input) FromMap

func (i *Input) FromMap(values map[string]interface{}) error

FromMap sets activity input values from a map

func (*Input) ToMap

func (i *Input) ToMap() map[string]interface{}

ToMap converts activity input to a map

type OrgFilter added in v0.0.4

type OrgFilter struct {
	MSPID string
}

OrgFilter implements TargetFilter interface for target peers

func (*OrgFilter) Accept added in v0.0.4

func (f *OrgFilter) Accept(peer fab.Peer) bool

Accept implements fab.TargetFilter interface

type Output

type Output struct {
	Code    int         `md:"code"`
	Message string      `md:"message"`
	Result  interface{} `md:"result"`
}

Output of the activity

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

FromMap sets activity output values from a map

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

ToMap converts activity output to a map

type Settings

type Settings struct {
	ConnectionName  string       `md:"connectionName,required"`
	ChannelID       string       `md:"channelID,required"`
	ChaincodeID     string       `md:"chaincodeID,required"`
	TransactionName string       `md:"transactionName,required"`
	Arguments       []*Attribute `md:"arguments"`
	RequestType     string       `md:"requestType,required"`
	UserOrgOnly     bool         `md:"userOrgOnly"`
}

Settings of the activity

func (*Settings) FromMap

func (h *Settings) FromMap(values map[string]interface{}) error

FromMap sets activity settings from a map

Jump to

Keyboard shortcuts

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