Slide 28
Slide 28 text
© Hitachi, Ltd. 2021. All rights reserved.
Demo | ②How to Install Simple Private Chaincode
27
Simple chaincode installed in this demonstration
// storeAsset: Specify key and value and store them in the State DB
std::string storeAsset(std::string asset_name, int value, shim_ctx_ptr_t ctx)
{
LOG_DEBUG("HelloworldCC: +++ storeAsset +++");
put_state(asset_name.c_str(), (uint8_t*)&value, sizeof(int), ctx);
return OK;
}
// retrieveAsset: Specify a key, return the value paired with the key stored in the State DB
std::string retrieveAsset(std::string asset_name, shim_ctx_ptr_t ctx)
{
std::string result;
LOG_DEBUG("HelloworldCC: +++ retrieveAsset +++");
uint32_t asset_bytes_len = 0;
uint8_t asset_bytes[MAX_VALUE_SIZE];
get_state(asset_name.c_str(), asset_bytes, sizeof(asset_bytes), &asset_bytes_len, ctx);
// check if asset_name exists
if (asset_bytes_len > 0)
{
result = asset_name + ":" + std::to_string((int)(*asset_bytes));
} else {
// asset does not exist
result = NOT_FOUND;
}
return result;
}