hyperledger composer @returns 不工作

hyperledger composer @returns not working

在 Hyperledger Composer,v 19.12 中,我正在尝试使用 @returns 装饰器来 return 资产。当我通过 REST API 调用该函数时,尽管我获得了成功的交易(200 return 代码)但没有在响应主体中获得帐户对象。这是数据模型文件中定义的事务、关联的事务函数和来自 REST API 调用的响应主体。 Account 对象在同一模型文件中定义。

我希望得到一个帐户 JSON 对象。我做错了什么?

交易模式

/*
Read only transaction to load account
*/
@commit(false)
@returns(Account)
transaction LoadAccountTx {
  o String accountId
}

交易功能

/**
* function to load account
* @param {org.scsvault.history.LoadAccountTx} loadAccountTx
* @returns {org.scsvault.history.Account} The resulting array of accounts
* @transaction
*/
async function loadAccount(loadAccount)
{
    var i = 2;
    var factory = getFactory();
    var NS = 'org.scsvault.history';
    var account = factory.newResource(NS, 'Account', 'ACCOUNT_1');
    account.accountType = 'CREDITCARD';
    account.balance = 100;
    account.openingbalance = 1000;
    account.opendate = new Date(2017, i, i);
    if (i % 2) {
        account.approvalStatus = 'REQUEST_PENDING';
    }
    else {
        account.approvalStatus = 'CREATE';
    }
    account.status = 'PENDING_APPROVAL';
    account.creditlimit = i * 1000;
    account.term_months = i;
    account.encryptedDescription = account.accountType + ' from Chase';
    account.apr = i;
    return account;
}

响应正文:

{
  "$class": "org.scsvault.history.LoadAccountTx",
  "accountId": "ACCOUNT_1",
  "transactionId": "09c9eb722fe3adda41fe0a4d1060ab4efff4c2ca9ad817a763dae81374123b4c"
}

编辑:

为了进一步测试,我将上面的代码更改为一个简单的字符串 return 值,并且不通过 REST API.

接收回测试字符串
@returns(String)
transaction LoadAccountTx {
  o String accountId
}

/**
* function to load account
* @param {org.scsvault.history.LoadAccountTx} loadAccountTx
* @returns {string} (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string)
* @transaction
*/
async function loadAccount(loadAccount)
{
    return "This is a test string";
}

我遇到了非常相似的问题。我刚刚在 GitHub here 上打开了一个带有一般示例的问题,并参考了这个问题以及 Rocketchat 上的消息。希望这会很快得到解决。

只是添加到@nicolapaoli 所写的内容:这已在 Hyperledger Composer 版本 v0.19.13 中修复,仅供参考 - 您确实获得了 return 值。