This section gives examples of a universal deposit contract and a simple approval contract to facilitate the development of smart contracts.
General Deposit Contract
The general deposit contract provides a general operation interface for the blockchain ledger KV, and supports data reading, writing, and historical query. You can access the chaincode source code and see Package chaincode. You can also download the packaged chaincode.
Initialize Parameters
No initialization parameters
API operation
get
Queries the current content of a key in the blockchain deposit certificate information.
The list of parameters.
key: the key of the certificate to be read.
Valid values:
On success, the current content stored by the key in the contract is deposited.
If the error fails, the cause of the error is returned.
put
Write the <key, value> key to the blockchain. If the key already exists, a failure is returned.
The list of parameters.
key: the key of the certificate to be read.
value: the information to be saved.
Valid values:
If successful, the key of the certificate is returned.
If the error fails, the cause of the error is returned.
set
Write the certificate information <key, value> to the blockchain. If the certificate key already exists, the old certificate content is overwritten.
The list of parameters.
key: the key of the certificate to be read.
value: the information to be saved.
Valid values:
If successful, the key of the certificate is returned.
If the error fails, the cause of the error is returned.
history
You can call this operation to query the modification history of a key in the blockchain deposit certificate information.
The list of parameters.
key: the key of the certificate to be read.
Valid values:
If successful, the modification history (JSON-encoded) of the key is returned.
If the error fails, the cause of the error is returned.
Simple Approval Contract
The simple approval contract provides a simple task approval interface based on blockchain, which allows you to create, query, and approve tasks. When the status of a task changes, a corresponding blockchain event is generated. You can access the chaincode source code and see Package chaincode. You can also download the packaged chaincode.
Initialize Parameters
No initialization parameters
The data structure.
task
type Task struct {
// The name of the task.
Name string `json:"name"`
// The creator of the task.
Creator string `json:"creator"`
// The process can be terminated only after the user approves the task. (User representation: ${MSP_ID}.${USER_NAME}.)
Requires []string `json:"requires"`
// The current user who has agreed to the task (user representation: ${MSP_ID}.${USER_NAME})
Approved []string `json:"approved"`
// The description of the task.
Description string `json:"description"`
}API operation
create
Creates a new task flow.
The list of parameters.
name: the name of the task.
task: the JSON-encoded task content. It must contain the
requiresanddescriptionfields.
Valid values:
If successful, returns the name of the successfully created task.
If the error fails, the cause of the error is returned.
Events:
The event
event-create-taskis triggered. The event content is JSON-encoded.
get
Obtain a task flow
The list of parameters.
name: the name of the task.
Valid values:
If successful, the JSON-encoded task content is returned.
If the error fails, the cause of the error is returned.
approve
Agree to a task
The list of parameters.
name: the name of the task.
Valid values:
If successful, the JSON-encoded task content is returned.
If the error fails, the cause of the error is returned.
Events:
After you agree to the task and the task meets the end conditions, an event
event-task-finishedis triggered. The event content is JSON-encoded.After you agree to the task, if the task does not meet the end conditions, the event
event-approve-taskis triggered. The event content is JSON-encoded.