在Hyperledger Composer中将资产的特定属性导入另一个资产以进行交易

时间:2018-05-14 08:42:32

标签: hyperledger hyperledger-composer

我正在研究超级作曲家,我在理解关系及其工作原理方面遇到了麻烦。 我有两个名为CHECKBOOK和CHECK的模型。

我有创建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
}

1 个答案:

答案 0 :(得分:0)

如果您发布模型会有所帮助......

所以给出了这个模型

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);

}

相关问题