[英]How to Updating Existing Assets? - Hyperledger Composer
I am trying to update and Asset in hyperledger, in this case I am trying to add a new provider to a provider array list in the Asset but hthe composer dont let me. 我正在尝试在Hyperledger中更新和Asset,在这种情况下,我正在尝试将新的提供程序添加到Asset中的提供程序数组列表中,但是作曲家不允许我这样做。
I dont know what is wrong. 我不知道怎么了。 Belor are the model, the javascript and the error. Belor是模型,javascript和错误。
Model: 模型:
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace org.acme.Bicycle
asset Bicycle identified by serial {
o String serial
--> Rider owner optional
--> Rider [] ownerold optional
--> Provider [] distribuold optional
--> Store [] Storeold optional
--> Manufacturing manufacturing
}
abstract participant User identified by email {
o String email
o String firstName
o String lastName
}
participant Rider extends User {
}
participant Manufacturing extends User {
}
participant Provider extends User {
}
participant Store extends User {
}
participant Police extends User {
}
transaction check {
o String date
o String Description
--> Rider owner
--> Police police
--> Bicycle bike
}
transaction fabrictodistri {
o String Description
--> Manufacturing manufacturing
--> Bicycle bike
--> Provider providerstore
}
transaction providertostore {
o String Description
--> Bicycle bike
--> Provider providerstore
--> Store Storeold
}
transaction storetobiker {
o String Description
--> Bicycle bike
--> Store Storeold
--> Rider owner
}
Script file: here is all my functions 脚本文件:这是我的全部功能
/**
* @param {org.acme.Bicycle.check} check
* @transaction
*/
async function check(check) {
let owner = check.bike.owner.email;
let ciclista = check.owner.email;
if(owner != ciclista){
check.description= "This is not the owner";
throw new Error('This is not the owner');
}else{
check.description= "This is the owner";
throw new Error('This is not the owner');
}
}
/**
* @param {org.acme.Bicycle.fabrictodistri} ftod
* @transaction
*/
async function fabrictodistri(ftod) {
let bike = ftod.bike;
bike.distribuold.push(ftod.providerstore);
}
/**
* @param {org.acme.Bicycle.providertostore} ptosto
* @transaction
*/
async function providertostore(ptosto) {
let bike = ptosto.bike;
bike.distribuold.push(ptosto.providerstore);
bike.Storeold.push(ptosto.Storeold);
}
/**
* @param {org.acme.Bicycle.storetobiker} stostobik
* @transaction
*/
async function storetobiker(stostobik) {
let bike = stostobik.bike;
bike.ownerold.push(stostobik.owner);
bike.owner = stostobik.owner;
}
Error: "TypeError: Cannot read property 'push' of undefined" 错误:“ TypeError:无法读取未定义的属性'push'”
In order to modify your existing assets you need to use functions such as getAssetRegistry
and then use the update
method. 为了修改现有资产,您需要使用诸如getAssetRegistry
功能,然后使用update
方法。
The Trade-Network sample in Composer Playground has a simple transaction to update an asset which is an easy reference. Composer Playground中的Trade-Network示例具有一个更新资产的简单事务,这很容易参考。
The same network is used in the Developer Tutorial . 开发人员指南中使用了相同的网络。
I faced the same issue. 我遇到了同样的问题。 Turns out you probably can't push to a array which is empty/undefined. 原来,您可能无法推送到空/未定义的数组。
I used the following fix for that (Modify it according to your program) : 我为此使用了以下修复程序(根据您的程序进行修改):
if (typeof roj.contributors == 'undefined') { // Check if the array is empty roj.contributors = new Array(); roj.contributors[0] = createROData.creator; } else { roj.contributors.push(createROData.creator); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.