Hyperledger Fabric's chain code interface finishing

Source: Internet
Author: User
Tags definition key string list of attributes stub hyperledger fabric

The 1.Chaincode interface must be implemented by all the code on the chain, and the fabric runs the transaction by invoking these specified functions

Call the INIT function to allow code on the chain to initialize internal data after the container has established a connection and then deploys the transaction
Init (stub chaincodestubinterface, function string, args []string) ([]byte, error)
Each call to the transaction invokes the Invoke interface. The code on the chain may change the state variable
Invoke (stub chaincodestubinterface, function string, args []string) ([]byte, error)
Invokes the query interface when querying transactions. The code on the chain simply reads (rather than modifies) its state variable and returns the result
Query (stub chaincodestubinterface, function string, args []string) ([]byte, error)
}
2. Chaincodestubinterface is used to deploy chained code apps to access and modify their ledger

Type Chaincodestubinterface Interface {
Get The arguments to the stub call as a 2D byte array
Gets the parameter of the stub call to act as a 2-D byte array
Getargs () [][]byte
Get The arguments to the stub call as a string array
Gets the parameter of the stub call to be used as a character array
Getstringargs () []string
Get the ID of the transaction
Gettxid () string
Invokechaincode locally invokes the specified chain code, ' invoke ' uses the same trade, and says the chain code is called
The code on the chain does not create a new trade message
Invokechaincode (Chaincodename string, args [][]byte) ([]byte, error)
Invokechaincode calls the specified chain code locally, ' Query ' uses the same trade, and it says the chain code is called
The code on the chain does not create a new trade message
Querychaincode (Chaincodename string, args [][]byte) ([]byte, error)
GetState to return specific values of an array by key
GetState (Key String) ([]byte, error)
Putstate write specific keys and values to the ledger
Putstate (key string, value []byte) error
Delstate remove the specified key and value from the Ledger
Delstate (key String) error
The Rangequerystate function can be used to query for keys in the state range through Chaincode. Suppose Startkey and EndKey
In the dictionary, an iterator is returned that can be used to traverse all the keys between Startkey and EndKey.
The order of the iterator return keys is random.
Rangequerystate (Startkey, EndKey string) (Staterangequeryiteratorinterface, error)
CreateTable Create a new table, give the table name and the column definition
CreateTable (name string, columndefinitions []*columndefinition) error
GetTable If a table exists, returns the specified table if the table does not exist Errtablenotfound error
GetTable (TableName string) (*table, error)
Deletetable Delete all rows related to the table and entity
Deletetable (TableName String) error
InsertRow insert a new line into the specified table
Returns
Returns true if the row successfully inserted and no error
Returns false and no error if a given row already exists
Returns FALSE if the specified table name does not exist and Tablenotfounderror
Returns false and error if an unexpected error condition occurs
InsertRow (TableName string, row row) (bool, error)
Replacerow updates the row in the specified table.
Returns
Returns false and no error if the row is updated successfully
Returns false and no error if the given row does not have a corresponding key
Returns FALSE if the specified table name does not exist and Tablenotfounderror
Returns false and error if an unexpected error condition occurs
Replacerow (TableName string, row row) (bool, error)
Fetching rows from a specified table by key
GetRow (TableName string, key []column) (Row, error)
Returns multiple rows based on a specific key. For example, give a table | A | B | C | D |,a,c and D are keys, you can use [A,c] to call GetRows to return all with a,
C and any D-value rows as their keys. GetRows can also use a call to return all rows with a and C and D as their key values.
GetRows (TableName string, key []column) (<-chan Row, error)
DeleteRow deletes a specific row from the specified table by key
DeleteRow (TableName string, key []column) error
Readcertattribute used to read the specified attribute from the transaction certificate
*attributename* is the entry for this function.
For example:
  attrvalue,error:=stub. Readcertattribute ("position")
Readcertattribute (AttributeName string) ([]byte, error)
Verifyattribute is used to verify that the transaction certificate has a property named * Attribute name * and value * AttributeValue *.
AttributeName and AttributeValue are input parameters that are received by this function
For example:
    containsattr, Error: = Stub. Verifyattribute ("position", "software Engineer")
Verifyattribute (AttributeName string, AttributeValue []byte) (bool, error)
Verifyattributes is the same as Verifyattribute, but it examines the list of attributes and their corresponding values instead of a single property/value pair
For example:
    Containsattrs, error:= stub. Verifyattributes (&attr. attribute{"position",  "Software Engineer"}, &attr. Attribute{"Company", "Acompany"})
Verifyattributes (Attrs ... *attr. Attribute) (bool, error)
VerifySignature Verify the signature of the transaction, or return False if True is returned correctly
VerifySignature (certificate, signature, message []byte) (bool, error)
Getcallercertificate Return Caller Certificate
Getcallercertificate () ([]byte, error)
Getcallermetadata Returning caller metadata
Getcallermetadata () ([]byte, error)
Getbinding return Trade Bundle
Getbinding () ([]byte, error)
Getpayload returns the payload of the transaction, payload is a definition in Fabric/protos/chaincode.proto
Chaincodespecwhich in the
Getpayload () ([]byte,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.