gpt4 book ai didi

javascript - super 账本 Composer : How to push array of assets into another asset's field?

转载 作者:行者123 更新时间:2023-11-28 17:47:05 27 4
gpt4 key购买 nike

我正在尝试在 Composer 中重新创建用 GoLang 编写的链码之一。模型.cto

asset Carton identified by cartonId {
o String cartonId
o String manufacturerId
o String dateOfDeparture optional
o String recipient optional
o String currentOwner
o String status
--> Unit[] units optional
o Trackrecord[] trackrecord optional
}
transaction MakeCarton {
--> Unit[] unit
o String Id
}
asset Unit identified by unitId {
o String unitId
o String cartonId
o String manufacturerId
o String dateOfDeparture
o String recipient
o Trackrecord[] trackrecord
o String currentOwner
o String status
}

所以我需要创建一个交易,该交易创建一个纸箱并接受一组单元和 cartonId。

  function makeCarton(make) {
var carton = getFactory().newResource('org.acme.mynetwork','Carton',make.Id);
//carton.cartonId = make.Id ;
var unitobjs = new Array() ;
for(var i=0; i < make.unit.length ; i++) {
var unitobj = getFactory().newResource('org.acme.mynetwork','Unit',make.unit[i].unitId) ;
unitobj = getFactory().newRelationship('org.acme.mynetwork','Unit',make.unit[i].unitId) ;
unitobjs.push(unitobj) ;
}
for(var i = 0 ; i< make.unit.length ; i++) {
carton.units.push(make.unit[i]) ;
}
// getFactory().newRelationship('org.acme.mynetwork','Unit',make.unit[i].unitId)
carton.manufacturerId= make.unit.manufacturerId ;
carton.currentOwner = make.unit.currentOwner ;
carton.status = 'At '+ make.unit.currentOwner ;
return getAssetRegistry('org.acme.mynetwork.Carton').then(function (assetRegistry) {
return assetRegistry.add(carton);
});
}

提交此交易会生成错误:carton.units undefined

最佳答案

您没有初始化carton.units。您可以使用以下方法复制数组:

carton.units = make.unit;

也就是说,我不太理解你的模型——一个纸箱有一个单元数组,每个单元都有一个所有者,但纸箱也有一个所有者。

关于javascript - super 账本 Composer : How to push array of assets into another asset's field?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46444377/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com