Created
February 20, 2018 18:46
-
-
Save sneljo1/b52764acd7cadc919ae942bf869ac3fe to your computer and use it in GitHub Desktop.
Gist for article https://medium.com/wearetheledger/the-new-and-exciting-features-in-hyperledger-fabric-1-1-preview-4261ece3590d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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