get

package module
v0.1.1-0...-4a489c3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

README

Fabric Get activity

This Flogo activity contribution can be configured to perform read operations on Hyperledger Fabric distributed ledger and private data collections. Most of the read operations are demonstrated in the contract example.

Retrieve one or more ledger states by state keys

The operation does not need to change any default configurations, you can simply map one or an array of state keys to the input, e.g.,

    "activity": {
        "ref": "#get",
        "input": {
            "data": "=$flow.parameters.name"
        }
    }

Retrieve multiple ledger states by partial composite keys

This operation requires a composite-key configuration, and input data for the attributes of the composite key, e.g.,

    "activity": {
        "ref": "#get",
        "settings": {
            "compositeKeys": {
                "mapping": {
                    "color~name": ["docType", "color", "name"]
                }
            }
        },
        "input": {
            "data": {
                "mapping": {
                    "docType": "marble",
                    "color": "=$flow.parameters.color"
                }
            },
            "pageSize": 0,
            "bookmark": ""
        }
    }

This example retrieves all ledger states that matches the first 2 fields of the composite key color~name, in other words, it retrieves all marbles of a specified color from the Fabric ledger.

pageSize and bookmark are optional, and can be specified when result pagination is required.

Retrieve multiple ledger states by CouchDB query

This operation requires a configuration of the CouchDB query statement, and input data for the query parameters, e.g.,

    "activity": {
        "ref": "#get",
        "settings": {
            "query": {
                "mapping": {
                    "selector": {
                        "docType": "marble",
                        "owner": "$owner"
                    }
                }
            }
        },
        "input": {
            "data": {
                "mapping": {
                    "owner": "=$flow.parameters.owner"
                }
            },
            "pageSize": 0,
            "bookmark": ""
        }
    }

This example executes a CouchDB query that takes $owner as a parameter that is provided by the input data. In other words, this query retrieves all marbles in the Fabric ledger by a specified owner.

pageSize and bookmark are optional, and can be specified when result pagination is required.

Retrieve the history of one or more state keys

The operation requires turning on the history flag, and input of one or an array of state keys, e.g.,

    "activity": {
        "ref": "#get",
        "settings": {
            "history": true
        },
        "input": {
            "data": "=$flow.parameters.name"
        }
    }

Retrieve composite-keys by partial composite key

This operation is normally not used, but it is supported, and requires turning on the keysOnly flag besides a composite-key configuration, and input data for the attributes of the composite key, e.g.,

    "activity": {
        "ref": "#get",
        "settings": {
            "keysOnly": true,
            "compositeKeys": {
                "mapping": {
                    "color~name": ["docType", "color", "name"]
                }
            }
        },
        "input": {
            "data": {
                "mapping": {
                    "docType": "marble",
                    "color": "=$flow.parameters.color"
                }
            }
        }
    }

This example will return only the matching composite-keys, but not the corresponding ledger states.

Retrieve ledger states by key range

This operation requires input data that specifies the start and end of the range of state keys, e.g.,

    "activity": {
        "ref": "#get",
        "input": {
            "data": {
                "mapping": {
                    "start": "=$flow.parameters.startKey",
                    "end": "=$flow.parameters.endKey"
                }
            },
            "pageSize": 0,
            "bookmark": ""
        }
    }

This example will return all ledger states between a start state key (inclusive) and an end state key (exclusive).

pageSize and bookmark are optional, and can be specified when the result pagination is required.

Retrieve data from private data collection

When a private data collection is specified in the input, data will be fetched from the specified private data collection, e.g.,

    "activity": {
        "ref": "#get",
        "input": {
            "data": "=$flow.parameters.name",
            "privateCollection": "_implicit"
        }
    }

This example will retrieve data from the client's implicit private collection, i.e., _implicit_org_<mspid>.

Most of the above read operations can be executed on private data collections, except for the history query, which is not supported by private collections. Besides, pagination is mostly ignored for read operations on private data collections.

Retrieve private data hash

To retrieve the public hash of a private data record, you can turn on the privateHash flag, and specify the state key and name of the private data collection, e.g.,

    "activity": {
        "ref": "#get",
        "settings": {
            "privateHash": true
        },
        "input": {
            "data": "=$flow.parameters.name",
            "privateCollection": "_implicit"
        }
    }

This example will return the public hash of the specified private data on the implicit private data collection. The input data can specify one or an array of multiple state keys.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New creates a new Activity

Types

type Activity

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

Activity is a stub for executing Hyperledger Fabric get operations

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

func (*Activity) String

func (a *Activity) String() string

type Input

type Input struct {
	Data              interface{} `md:"data,required"`
	PrivateCollection string      `md:"privateCollection"`
	PageSize          int32       `md:"pageSize"`
	Bookmark          string      `md:"bookmark"`
}

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 Output

type Output struct {
	Code     int           `md:"code"`
	Message  string        `md:"message"`
	Bookmark string        `md:"bookmark"`
	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 {
	KeyName     string   `md:"keyName"`
	Attributes  []string `md:"attributes"`
	QueryStmt   string   `md:"queryStmt"`
	KeysOnly    bool     `md:"keysOnly"`
	History     bool     `md:"history"`
	PrivateHash bool     `md:"privateHash"`
}

Settings of the activity

func (*Settings) FromMap

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

FromMap sets settings from a map construct composite key definition of format {"index": ["field1, "field2"]}

type StateData

type StateData struct {
	Key   string
	Value []byte
}

StateData contains a state key and its associated data

Jump to

Keyboard shortcuts

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