保存后更新 Hyperledger Composer 合约
Updating Hyperledger Composer Contract after it is saved
我是 Hyperledger Composer 的初学者,我想问一下在与资产链接后是否可以更新合约中的属性?
我能够更新资产中的属性,但是当我尝试时,例如:
document.contract.totalSigners = 3;
return getAssetRegistry(NS + '.Document')
.then(function (documentRegistry) {
return documentRegistry.update(document);
});
结果:Contract 中的属性没有更新。
我知道 Contract 链接到 Asset 所以我想知道是否允许更新 contract 或者是否有其他方式来执行更新过程?
此外,由于我将 Owner 资产链接到 Contract,如果他将来删除文档,我该如何删除所有者?下面是我的架构:
participant Owner extends Business {
}
asset Contract identified by contractId {
o String contractId
--> Owner owner
}
asset Document identified by documentId {
o String documentId
o DocumentStatus status
--> Contract contract
}
是的,可以更新资产。贸易网络样本正是这样做的——改变现有资产的所有者。
/**
* Track the trade of a commodity from one trader to another
* @param {org.acme.trading.Trade} trade - the trade to be processed
* @transaction
*/
async function tradeCommodity(trade) { // eslint-disable-line no-unused-vars
// set the new owner of the commodity
trade.commodity.owner = trade.newOwner;
const assetRegistry = await getAssetRegistry('org.acme.trading.Commodity');
// persist the state of the commodity
await assetRegistry.update(trade.commodity);
}
(贸易网络示例可以在 Playground 或通过 github 找到)
请注意,此示例使用 async / await 而不是 promises,这适用于更高版本的 Composer。希望您使用的是 Composer v0.19 和 Fabric 1.1 - 如果没有,请尽可能升级。
Owner 可以在交易中删除,您将访问 participantRegistry.remove 而不是 assetRegistry - 您可能想在删除之前检查所有者是否拥有其他合约,并且您可以使用查询那个。
我是 Hyperledger Composer 的初学者,我想问一下在与资产链接后是否可以更新合约中的属性?
我能够更新资产中的属性,但是当我尝试时,例如:
document.contract.totalSigners = 3;
return getAssetRegistry(NS + '.Document')
.then(function (documentRegistry) {
return documentRegistry.update(document);
});
结果:Contract 中的属性没有更新。
我知道 Contract 链接到 Asset 所以我想知道是否允许更新 contract 或者是否有其他方式来执行更新过程?
此外,由于我将 Owner 资产链接到 Contract,如果他将来删除文档,我该如何删除所有者?下面是我的架构:
participant Owner extends Business {
}
asset Contract identified by contractId {
o String contractId
--> Owner owner
}
asset Document identified by documentId {
o String documentId
o DocumentStatus status
--> Contract contract
}
是的,可以更新资产。贸易网络样本正是这样做的——改变现有资产的所有者。
/**
* Track the trade of a commodity from one trader to another
* @param {org.acme.trading.Trade} trade - the trade to be processed
* @transaction
*/
async function tradeCommodity(trade) { // eslint-disable-line no-unused-vars
// set the new owner of the commodity
trade.commodity.owner = trade.newOwner;
const assetRegistry = await getAssetRegistry('org.acme.trading.Commodity');
// persist the state of the commodity
await assetRegistry.update(trade.commodity);
}
(贸易网络示例可以在 Playground 或通过 github 找到) 请注意,此示例使用 async / await 而不是 promises,这适用于更高版本的 Composer。希望您使用的是 Composer v0.19 和 Fabric 1.1 - 如果没有,请尽可能升级。
Owner 可以在交易中删除,您将访问 participantRegistry.remove 而不是 assetRegistry - 您可能想在删除之前检查所有者是否拥有其他合约,并且您可以使用查询那个。