Hyperledger fabric Hyperledger结构节点JS链码-检索调用方标识符
我正在尝试开发一个链码,它必须创建和存储一个汽车对象,并允许转让汽车的所有权Hyperledger fabric Hyperledger结构节点JS链码-检索调用方标识符,hyperledger-fabric,hyperledger,Hyperledger Fabric,Hyperledger,我正在尝试开发一个链码,它必须创建和存储一个汽车对象,并允许转让汽车的所有权 //arg[0]=identifier - arg[1]=model async createCar(stub, args) { console.info('============= START : Create Car ==========='); if (args.length != 2) { throw new Error('Incorrect number of arguments. Expe
//arg[0]=identifier - arg[1]=model
async createCar(stub, args) {
console.info('============= START : Create Car ===========');
if (args.length != 2) {
throw new Error('Incorrect number of arguments. Expecting 2');
}
console.info("Creator",stub.getCreator());
var car = {
model: arg[1],
owner: //.... - Here store the id of who invoked the transaction
};
await stub.putState(args[0], Buffer.from(JSON.stringify(car)));
console.info('============= END : Create Car ===========');
return true;
}
当调用“createCar”时,我想将汽车的所有者设置为提交事务的人的标识符/证书
我也在开发一种方法,允许转让汽车的所有权。在这个方法中,我想插入一个条件,如果当前用户(调用事务的用户)不是汽车的当前所有者,则会引发异常
//arg[0]=identifier - arg[1]=model
async createCar(stub, args) {
console.info('============= START : Create Car ===========');
if (args.length != 2) {
throw new Error('Incorrect number of arguments. Expecting 2');
}
console.info("Creator",stub.getCreator());
var car = {
model: arg[1],
owner: //.... - Here store the id of who invoked the transaction
};
await stub.putState(args[0], Buffer.from(JSON.stringify(car)));
console.info('============= END : Create Car ===========');
return true;
}
有人知道我能做什么吗?您可以使用getCreator(),它将返回链码调用提交者的标识对象。谢谢。如何使用getCreator()比较存储后的所有者?如果(car.owner!=/*…-调用事务的新用户*/){throw new Error('Invalid owner');}[这可能会帮助您,类似于您的要求。在您的情况下,您只需检查提交者和当前所有者是否相同。