【问题标题】:hyperledger composer @returns not working超级账本作曲家@returns 不起作用
【发布时间】:2018-12-19 22:24:29
【问题描述】:

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

我希望得到一个 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"
}

编辑:

为了进一步测试,我将上面的代码更改为简单的字符串返回值,并且不会通过 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";
}

【问题讨论】:

    标签: hyperledger hyperledger-composer


    【解决方案1】:

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

    【讨论】:

    • 感谢跟进,同意,我的问题已通过更新到 19.13 得到解决。感谢@nicolapaoli!
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-10
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      相关资源
      最近更新 更多