FPCError

Official documentation:

Check the official docs here .

We followed the steps as given in the official documentation as captured in the following video:

The flow is as follows:

_images/FPCError.png

The commands are as follow:

1

sudo apt update && sudo apt upgrade -y

2

sudo apt install docker.io git curl wget cmake software-properties-common -y

3

sudo usermod -aG docker vagrant

4

sudo nano /etc/docker/daemon.json
sudo service docker restart

5

sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

6

wget-c https://golang.org/dl/go1.16.2.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

7

sudo apt install nodejs npm python -y

8

git clone --recursive https://github.com/hyperledger-labs/fabric-private-chaincode.git $GOPATH/src/github.com/hyperledger-labs/fabric-private-chaincode

9

cd utils/docker; make run

10

cd $GOPATH/src/github.com/hyperledger-labs/fabric-private-chaincode/examples
mkdir helloworld
cd helloworld
touch helloworld_cc.cpp

Add this in helloworld_cc.cpp

#include "shim.h"
#include "logging.h"
#include <string>

#define OK "OK"
#define NOT_FOUND "Asset not found"

#define MAX_VALUE_SIZE 1024

//  Add asset_name, value to ledger
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;
}

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;
}

// implements chaincode logic for invoke
int invoke(
    uint8_t* response,
    uint32_t max_response_len,
    uint32_t* actual_response_len,
    shim_ctx_ptr_t ctx)
{
    LOG_DEBUG("HelloworldCC: +++ Executing helloworld chaincode invocation +++");

    std::string function_name;
    std::vector<std::string> params;
    get_func_and_params(function_name, params, ctx);
    std::string asset_name = params[0];
    std::string result;

    if (function_name == "storeAsset")
    {
        int value = std::stoi (params[1]);
        result = storeAsset(asset_name, value, ctx);
    }
    else if (function_name == "retrieveAsset")
    {
        result = retrieveAsset(asset_name, ctx);
    }
    else
    {
        // unknown function
        LOG_DEBUG("HelloworldCC: RECEIVED UNKNOWN transaction '%s'", function_name);
        return -1;
    }

    // check that result fits into response
    int neededSize = result.size();
    if (max_response_len < neededSize)
    {
        // error:  buffer too small for the response to be sent
        LOG_DEBUG("HelloworldCC: Response buffer too small");
        *actual_response_len = 0;
        return -1;
    }

    // copy result to response
    memcpy(response, result.c_str(), neededSize);
    *actual_response_len = neededSize;
    LOG_DEBUG("HelloworldCC: Response: %s", result.c_str());
    LOG_DEBUG("HelloworldCC: +++ Executing done +++");
    return 0;
}

Create CMakeLists.txt with the following content.

cmake_minimum_required(VERSION 3.5.1)

set(SOURCE_FILES
    helloworld_cc.cpp
    )

include(../../ecc_enclave/enclave/CMakeLists-common-app-enclave.txt)

Create Makefile with the following content.

TOP = ../..
include $(TOP)/build.mk

BUILD_DIR := _build

$(BUILD_DIR):
    @if [ ! -d $(BUILD_DIR) ]; then \
        mkdir -p $(BUILD_DIR) && \
        cd $(BUILD_DIR) && \
        cmake ./..; \
    fi

build: $(BUILD_DIR)
    $(MAKE) --directory=$<

clean:
    rm -rf $(BUILD_DIR)
make

We’re getting the following error while running the chaincode:

CMake Error at /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/common/logging/CMakeVariables.txt:5 (include_guard):
  Unknown CMake command "include_guard".
Call Stack (most recent call first):
  /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/common/crypto/CMakeVariables.txt:13 (INCLUDE)
  /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/ecc_enclave/enclave/CMakeVariables.txt:8 (include)
  /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/ecc_enclave/enclave/CMakeLists-common-app-enclave.txt:14 (include)
  CMakeLists.txt:13 (include)

Here is the verbose error:

root@ubuntu-xenial:~/go/src/github.com/hyperledger-labs/fabric-private-chaincode/examples# make
make -C auction build || exit;  make -C echo build || exit;
make[1]: Entering directory '/root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/examples/auction'
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- SGX_COMMON_CFLAGS: -m64 -DSGX_SIM_MODE -O2
-- SGX_SDK: /opt/intel/sgxsdk
-- SGX_MODE: SIM
-- SGX_BUILD: PRERELEASE
-- SGX_LIBRARY_PATH: /opt/intel/sgxsdk/lib64
-- SGX_ENCLAVE_SIGNER: /opt/intel/sgxsdk/bin/x64/sgx_sign
-- SGX_EDGER8R: /opt/intel/sgxsdk/bin/x64/sgx_edger8r
-- SGX_SSL: /opt/intel/sgxssl
-- SGX_SSL_LIBRARY_PATH: /opt/intel/sgxssl/lib64
CMake Error at /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/common/logging/CMakeVariables.txt:5 (include_guard):
  Unknown CMake command "include_guard".
Call Stack (most recent call first):
  /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/common/crypto/CMakeVariables.txt:13 (INCLUDE)
  /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/ecc_enclave/enclave/CMakeVariables.txt:8 (include)
  /root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/ecc_enclave/enclave/CMakeLists-common-app-enclave.txt:14 (include)
  CMakeLists.txt:13 (include)


-- Configuring incomplete, errors occurred!
See also "/root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/examples/auction/_build/CMakeFiles/CMakeOutput.log".
Makefile:12: recipe for target '_build' failed
make[1]: *** [_build] Error 1
make[1]: Leaving directory '/root/go/src/github.com/hyperledger-labs/fabric-private-chaincode/examples/auction'
Makefile:12: recipe for target 'build' failed
make: *** [build] Error 2