19. 编写nodejs链码
- const shim = require('fabric-shim');
- const Chaincode = class{
- //链码初始化操作
- async Init(stub){
- var ret = stub.getFunctionAndParameters();
- var args = ret.params;
- var a = args[0];
- var aValue = args[1];
- var b = args[2];
- var bValue = args[3];
- await stub.putState(a,Buffer.from(aValue));
- await stub.putState(b,Buffer.from(bValue));
- return shim.success(Buffer.from('heima chaincodinit successs'));
- }
-
- async Invoke(stub){
- let ret = stub.getFunctionAndParameters();
- let fcn = this[ret.fcn];
- return fcn(stub,ret.params);
- }
- //查询操作
- async query(stub,args){
- let a = args[0];
- let balance = await stub.getState(a);
- return shim.success(balance);
- }
-
- };
- shim.start(new Chaincode());