错误:名称空间中的标识符无效或缺失

时间:2018-02-07 19:27:47

标签: javascript hyperledger-fabric hyperledger-composer

当我尝试在从抽象基类资产继承的资产上调用事务时,调用失败并显示Error: Invalid or missing identifier for Type <type> in namespace <name.spa.ce>

user.cto

namespace com.aczire.alm.base.user

import com.aczire.alm.base.*

abstract participant User {
  o String uid
  o String title optional
  o String firstName  optional
  o String lastName  optional
  o UserTransactionLogEntry[] logEntries
}

concept UserTransactionLogEntry {
  //--> User modified_by
  o String comment optional
  o DateTime timestamp
}

abstract transaction UserTransaction  {
  o String comment
}

abstract event UserTransactionEvent {
  o String comment
}

admin.cto

namespace com.aczire.alm.base.user.admin

import com.aczire.alm.base.*
import com.aczire.alm.base.user.*

participant Admin identified by uname extends User {
  o String uname
}

abstract transaction AdminUserTransaction extends UserTransaction {
  o Admin user
  --> Admin modified_by
}

abstract event AdminUserTransactionEvent extends UserTransactionEvent {
  --> Admin user
  --> Admin modified_by  
}

transaction CreateUser extends AdminUserTransaction {
}

admin.js

/**
 * Create a User
 * @param {com.aczire.alm.base.user.admin.CreateUser} createUser - the CreateUser transaction
 * @transaction
 */
function createUser(newuser) {
    console.log('createUser');

    var factory = getFactory();
    var NS_AU = 'com.aczire.alm.base.user.admin';

    var user = factory.newResource(NS_AU, 'Admin', newuser.uname);
    user.uid = newuser.uid;

    // save the order
    return getAssetRegistry(NS_AU)
        .then(function (registry) {
            return registry.add(user);
        })
        .then(function(){
            var userCreatedEvent = factory.newEvent(NS_AU, 'UserCreatedEvent');
            userCreatedEvent.user = user;
            userCreatedEvent.comment = 'Created new admin user - ' + newuser.uname + '!';
            emit(userCreatedEvent);
        });
}

我尝试将参数作为用户,管理员制作给TP;将事务参数移动到基类为用户类型;将事务移动到基类等。但似乎没有任何工作。

这里的继承是否有所不同?

在composer playground中显示错误。 enter image description here

1 个答案:

答案 0 :(得分:1)

您的admin.js存在一些问题。该错误是因为Admin是参与者,因此您必须getParticipantRegistry()而不是Assetregistry,然后添加用户。同样在您的模型文件admin.cto中,没有名为UserCreatedEvent的事件。因此,您首先需要将其添加到模型中,然后发出事件。要添加用户,请尝试更改为此。

    /**
 * Create a User
 * @param {com.aczire.alm.base.user.admin.CreateUser} createUser - the CreateUser transaction
 * @transaction
 */
function createUser(newuser) {
    console.log('createUser');
    var NS_AU = 'com.aczire.alm.base.user.admin';
    var factory = getFactory();

    var testuser = factory.newResource(NS_AU, 'Admin', newuser.user.uname);
    testuser.uid=newuser.user.uid
    testuser.logEntries=newuser.user.logEntries
    // save the order
            return getParticipantRegistry('com.aczire.alm.base.user.admin.Admin')
        .then(function (registry) {
            return registry.add(testuser);
        });
}