将资产的特定属性导入另一个资产以在 Hyperledger Composer 中进行交易
Import a specific attribute of an asset into another for transaction in Hyperledger Composer
我正在研究 hyperledger composer,但我在理解关系及其工作原理方面遇到了困难。
我有两个模型,分别命名为 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);
}
我正在研究 hyperledger composer,但我在理解关系及其工作原理方面遇到了困难。 我有两个模型,分别命名为 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);
}