diff --git a/off_chain_data/.gitignore b/off_chain_data/.gitignore new file mode 100644 index 00000000..cc6066a0 --- /dev/null +++ b/off_chain_data/.gitignore @@ -0,0 +1,5 @@ +addAssets.json +mychannel__lifecycle.log +mychannel_basic.log +nextblock.txt +wallet/ \ No newline at end of file diff --git a/off_chain_data/README.md b/off_chain_data/README.md index fbe4ecb4..79cde6da 100644 --- a/off_chain_data/README.md +++ b/off_chain_data/README.md @@ -38,7 +38,7 @@ The configuration for the listener is stored in the `config.json` file: "channelid": "mychannel", "use_couchdb":true, "create_history_log":true, - "couchdb_address": "http://localhost:5990" + "couchdb_address": "http://admin:password@localhost:5990" } ``` @@ -48,7 +48,7 @@ The configuration for the listener is stored in the `config.json` file: CouchDB. If set to false, only a local log of events will be stored. `create_history_log:` If true, a local log file will be created with all of the block changes. -`couchdb_address:` is the local address for an off chain CouchDB database. +`couchdb_address:` is the local address for an off chain CouchDB database with username and password. ### Create an instance of CouchDB @@ -56,7 +56,7 @@ If you set the "use_couchdb" option to true in `config.json`, you can run the following command start a local instance of CouchDB using docker: ``` -docker run --publish 5990:5984 --detach --name offchaindb couchdb:2.3.1 +docker run -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password --publish 5990:5984 --detach --name offchaindb couchdb:3.1.1 docker start offchaindb ``` diff --git a/off_chain_data/blockProcessing.js b/off_chain_data/blockProcessing.js index eed61b24..a2acb286 100644 --- a/off_chain_data/blockProcessing.js +++ b/off_chain_data/blockProcessing.js @@ -86,7 +86,7 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan for (var record in rwSet) { // ignore lscc events - if (rwSet[record].namespace != 'lscc') { + if (rwSet[record].namespace != '_lifecycle') { // create object to store properties const writeObject = new Object(); writeObject.blocknumber = blockNumber; @@ -108,7 +108,7 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan try { await writeValuesToCouchDBP(nano, channelname, writeObject); } catch (error) { - + } } } @@ -136,14 +136,14 @@ async function writeValuesToCouchDBP(nano, channelname, writeObject) { const historydbname = channelname + '_' + writeObject.chaincodeid + '_history'; // set values to the array of values received const values = writeObject.values; - + try { for (var sequence in values) { let keyvalue = values[ sequence ]; - + if ( keyvalue.is_delete == true @@ -159,6 +159,7 @@ async function writeValuesToCouchDBP(nano, channelname, writeObject) { keyvalue.value ) ) { + // insert or update value by key - this emulates world state behavior await couchdbutil.writeToCouchDB( nano, diff --git a/off_chain_data/config.json b/off_chain_data/config.json index 4df92335..5852531f 100644 --- a/off_chain_data/config.json +++ b/off_chain_data/config.json @@ -3,5 +3,5 @@ "channelid": "mychannel", "use_couchdb":true, "create_history_log":true, - "couchdb_address": "http://localhost:5990" + "couchdb_address": "http://admin:password@localhost:5990" } diff --git a/off_chain_data/couchdbutil.js b/off_chain_data/couchdbutil.js index 5e6a5329..c82c8b01 100644 --- a/off_chain_data/couchdbutil.js +++ b/off_chain_data/couchdbutil.js @@ -37,7 +37,7 @@ exports.writeToCouchDB = async function (nano, dbname, key, value) { try { await this.createDatabaseIfNotExists(nano, dbname); } catch (error) { - + console.log("Error creating the database-"+error) } const db = nano.use(dbname); @@ -82,7 +82,7 @@ exports.deleteRecord = async function (nano, dbname, key) { try { await this.createDatabaseIfNotExists(nano, dbname); } catch (error) { - + console.log("Error creating the database-"+error) } const db = nano.use(dbname); diff --git a/off_chain_data/startFabric.sh b/off_chain_data/startFabric.sh index e340bed5..b22eefc8 100755 --- a/off_chain_data/startFabric.sh +++ b/off_chain_data/startFabric.sh @@ -11,7 +11,19 @@ starttime=$(date +%s) # launch network; create channel and join peer to channel pushd ../test-network -./network.sh down + +# Fixes the issue of when running busybox in network down command on windows git bash +case "$(uname -s)" in + CYGWIN*|MINGW32*|MSYS*|MINGW*) + echo 'Running on MS Windows' + export MSYS_NO_PATHCONV=1 + ./network.sh down + unset MSYS_NO_PATHCONV + ;; + *) + ./network.sh down + ;; +esac ./network.sh up createChannel -ca -s couchdb ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go/ -ccl go