我正在研究超级账本作曲家,但我在理解关系及其工作原理方面遇到了麻烦。我有两个模型,名为 CHECKBOOK 和 CHEQUE。
我有一个创建 CHECK 的事务,它有它的属性。但我想从已经创建的资产 CHECKBOOK 中导入 CHEQUEBOOKNUMBER。
我怎样才能实现这样的功能。是否可以使用 CHEQUEBOOKNUMBER 检查资产是否存在
编辑很抱歉。这是我通过遵循官方教程能够组合在一起的。因为我还在学习,所以可能会有很多错误。
第一个模型文件
namespace org.example.bank.chequeBooks
asset chequeBook identified by chequeBookNumber{
o Integer chequeBookNumber
}
第二个模型文件
namespace org.example.bank.cheque
import org.example.bank.chequeBooks.chequeBook
asset cheque identified by chequeNumber{
o Integer chequeNumber
--> chequeBook cb
}
transaction chequeInProcess{
o Integer chequeNumber
o Integer chequeBookNumber
}
event chequeCashed{
o Integer chequeNumber
o Integer chequeBookNumber
}
如果你发布你的模型会有所帮助......
所以给定这个模型
asset Chequebook identified by cid {
o String cid
o Integer chequenumber
}
transaction Cheque {
--> Chequebook cb
o Integer number
}
您将在您的交易中按如下方式更新它(包括检查它是否存在):
async function updatechqno(cheque) { // eslint-disable-line no-unused-vars
// set the new owner of the commodity
cheque.cb.chequenumber = cheque.number ;
const assetRegistry = await getAssetRegistry('org.example.trading.Chequebook');
// check if it exists in the registry
const validno = await assetRegistry.exists(cheque.cb.cid);
console.log("Invoked Chequebook ID submitted is " + cheque.cb.cid ) ; // ie from the transaction
// does it exist (true / false)
if (validno) {
console.log('it exists, carry on');
} else {
console.log('doesnt exist, cant carry on');
throw new Error('this transaction failed, no such ID');
}
// persist the state of the commodity
await assetRegistry.update(cheque.cb);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句