Skip to content

Instantly share code, notes, and snippets.

@sneljo1
Created February 20, 2018 18:46
Show Gist options
  • Save sneljo1/b52764acd7cadc919ae942bf869ac3fe to your computer and use it in GitHub Desktop.
Save sneljo1/b52764acd7cadc919ae942bf869ac3fe to your computer and use it in GitHub Desktop.
const shim = require('fabric-shim');
const util = require('util');
var Chaincode = class {
Init(stub) {
return stub.putState('dummyKey', Buffer.from('dummyValue'))
.then(() => {
console.info('Chaincode instantiation is successful');
return shim.success();
}, () => {
return shim.error();
});
}
Invoke(stub) {
console.info('Transaction ID: ' + stub.getTxID());
console.info(util.format('Args: %j', stub.getArgs()));
let ret = stub.getFunctionAndParameters();
console.info('Calling function: ' + ret.fcn);
return stub.getState('dummyKey')
.then((value) => {
if (value.toString() === 'dummyValue') {
console.info(util.format('successfully retrieved value "%j" for the key "dummyKey"', value ));
return shim.success();
} else {
console.error('Failed to retrieve dummyKey or the retrieved value is not expected: ' + value);
return shim.error();
}
});
}
};
shim.start(new Chaincode());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment