Skip to content

Commit

Permalink
changes to support couchdb 3.1.1
Browse files Browse the repository at this point in the history
Signed-off-by: Indranil Majumder <indranil.majumder@navis.com>
  • Loading branch information
majumin authored and denyeart committed Sep 29, 2021
1 parent 5860027 commit 7a727eb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
5 changes: 5 additions & 0 deletions off_chain_data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
addAssets.json
mychannel__lifecycle.log
mychannel_basic.log
nextblock.txt
wallet/
6 changes: 3 additions & 3 deletions off_chain_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand All @@ -48,15 +48,15 @@ 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

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
```

Expand Down
9 changes: 5 additions & 4 deletions off_chain_data/blockProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -108,7 +108,7 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
try {
await writeValuesToCouchDBP(nano, channelname, writeObject);
} catch (error) {

}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion off_chain_data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 2 additions & 2 deletions off_chain_data/couchdbutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion off_chain_data/startFabric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sh: cd: line 1: can't cd to /data: No such file or directory> 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

Expand Down

0 comments on commit 7a727eb

Please sign in to comment.