Testing Blockchain on Bluemix
Based on IBM Blockchain Marbles Tutorial
The params.chaincodeID.name property that is used in the examples below is likely out of date. Contact the author for the updated chaincodeID in order to access all of the functionality detailed below.
This section breaks chaincode operations into sections based on their type and their usage. To use these commands, edit the "ctorMsg" property of the JSON object that is sent to /chaincode. Arguments to functions are always passed in as a string array.
The "method" property in the JSON object that is sent to /chaincode for operations in this section should be set to "query".
Function name: "read"
Arguments: 1
- The name of the variable to be read from the chaincode state
Example: Read the variable "ece" from the chaincode state
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "read",
"args": [
"ece"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "query_functions"
Arguments: 0
Example:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "query_functions",
"args": []
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "invoke_functions"
Arguments: 0
Example:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "invoke_functions",
"args": []
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "open_trades"
Arguments: 0
Example:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "open_trades",
"args": []
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "view_my_assets" Arguments: 1
- Owner's name
Example: View energy assets owned by bob
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "view_my_assets",
"args": [
"bob"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
The "method" property in the JSON object that is sent to /chaincode for operations in this section should be set to "query".
Function name: "write"
Arguments: 2
- Name of the variable
- Value of the variable
Example: Write the value "485" to the variable "ece" to the chaincode state
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "write",
"args": [
"ece",
"485"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "delete"
Arguments: 1
- Name of the variable to delete
Example: Delete the variable "ece" from the chaincode state
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "delete",
"args": [
"ece"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "init_energy"
Arguments: 4
- Unique identifier
- Amount of energy in this asset
- Price of energy in this asset
- Owner of the energy
Example: Create a new energy asset called "asset1" that is owned by bob with energy amount 50 and price 25
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "init_energy",
"args": [
"asset1",
"50",
"25",
"bob"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "set_owner"
Arguments: 2
- Unique Indentifier of an energy asset
- New owner of that energy asset
Example: Set the owner of asset1 to alice
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "set_owner",
"args": [
"asset1",
"alice"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "open_trade"
Arguments: 2
- Creator of the energy asset
- Energy asset to be traded
Example: Bob creates an open trade order for his asset called "asset1"
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "open_trade",
"args": [
"bob",
"asset1"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "perform_trade"
Arguments: 2
- Energy asset that will be bought
- New owner of the energy asset (purchaser)
Example: alice purchases the asset "asset1" that bob listed previously
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "perform_trade",
"args": [
"asset1",
"alice"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
Function name: "remove_trade"
Arguments: 2
- Creator of the open trade agreement
- Unique Identifier of energy asset in open trade order
Example: Remove the bob's open trade order for asset1
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID": {
"name": "76c1e5a0f389b61ed57ffb68be07aae7fa1c63dc98361afc50efb2d6fab41e1536c0270ffa31fb9a6b83d9829c33924d5f47ec16e3517df5c7dba80c082f758a"
},
"ctorMsg": {
"function": "remove_trade",
"args": [
"bob",
"asset1"
]
},
"secureContext": "user_type1_1"
},
"id": 0
}
{
"id": "asset1" // Unique Identifier
"amount" "50" // Amount of energy
"price": "25" // Selling price
"owner": "bob" // Person who owns the energy
}
{
"owner": "bob" // Owner of the energy that initiates the trade
"timestamp": <timestamp> // UTC Timestamp of when the offer was created
"id": "asset1" // Id of the asset used to create the trade
"amount": "50" // Amount of energy for trade
"price": "25" // Minimum price willing to accept
}