t:实例org.acme.seller.Car#HW7722缺少必填字段oldOwner

时间:2018-02-06 06:37:02

标签: transactions blockchain hyperledger-composer

我是区块链的新手,我正在尝试使用虚拟盒在Ubuntu上安装的hyperledger-composer设置上的一些代码,但无法解决此错误。

我在提交交易时收到此错误:

t:实例org.acme.seller.Car#HW7722缺少必填字段oldOwner

以下是我正在尝试的代码:

**Sample.cto**
/**
 * Sample business network definition.
 */
namespace org.acme.seller

asset Car identified by carNumber{
  o String carNumber
  o String carName
  --> Owner oldOwner
}


participant Owner identified by ownerId{
  o String ownerId
  o String fname
  o String lname
}

transaction Transfer{
  --> Car car
  --> Owner newOwner
}
----------------------
**Sample.js**

/**
 * Sample transaction processor function.
 * @param {org.acme.seller.Transfer} tx The sample transaction instance.
 * @transaction
 */
function Transfer(tx) {

    // Save the old value of the asset.
    tx.car.oldOwner = tx.car.newOwner;

    // Update the asset with the new value.
     // tx.car1.value = tx.newValue;

    // Get the asset registry for the asset.
    return getAssetRegistry('org.acme.seller.Car')
        .then(function (assetRegistry) {

            // Update the asset in the asset registry.
            return assetRegistry.update(tx.car);
        });
}
------------------------------------------------
**Permissions.acl**

/**
 * Sample access control list.
 */
rule EverybodyCanReadEverything {
    description: "Allow all participants read access to all resources"
    participant: "ANY"
    operation: ALL
    resource: "org.acme.seller.*"
    action: ALLOW
}

rule EverybodyCanSubmitTransactions {
    description: "Allow all participants to submit transactions"
    participant: "ANY"
    operation: ALL
    resource: "org.acme.seller.*"
    action: ALLOW
}

rule OwnerHasFullAccessToTheirAssets {
    description: "Allow all participants full access to their assets"
    participant(p): "org.acme.seller.*"
    operation: ALL
    resource(r): "org.acme.seller.*"
    condition: (r.owner.getIdentifier() === p.getIdentifier())
    action: ALLOW
}

rule SystemACL {
  description:  "System ACL to permit all access"
  participant: "org.hyperledger.composer.system.Participant"
  operation: ALL
  resource: "org.hyperledger.composer.system.**"
  action: ALLOW
}

2 个答案:

答案 0 :(得分:1)

如果您已向资产添加新字段并且资产注册表中的现有数据没有该字段,则会看到此错误。

如果您向新字段添加可选项,例如--> Owner oldOwner optional该错误应该消失。

答案 1 :(得分:0)

有一个 Bootstrap功能总能帮助您加载一些资产和参与者来测试您的功能。在您的情况下,交易需要您之前应创建的所有者参与者。这有助于将汽车从一个所有者转移到另一个所有者。

考虑到这种情况,请执行以下操作,而不是像@ r-thatcher所提到的那样使其成为可选项。 创建两个所有者,然后通过在进行交易时提供所有者ID来尝试进行交易。这将有助于您清楚地理解它。