Reputation: 13
In Hyperledger Composer, v 19.12, I am trying to use the @returns decorator to return an asset. When I call the function through the REST API though I get a succesful transaction (200 return code) but do not get the Account object in the Response Body. Here is the transaction as defined in the data model file, the associated transaction function, and the Response Body from the REST API call. The Account object is defined in the same model file.
I expect to get an Account JSON object back. What am I doing wrong?
Transaction model
/*
Read only transaction to load account
*/
@commit(false)
@returns(Account)
transaction LoadAccountTx {
o String accountId
}
Transaction function
/**
* 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;
}
Response Body:
{
"$class": "org.scsvault.history.LoadAccountTx",
"accountId": "ACCOUNT_1",
"transactionId": "09c9eb722fe3adda41fe0a4d1060ab4efff4c2ca9ad817a763dae81374123b4c"
}
EDIT:
To test further, I changed the code above to be a simple string return value and do not receive the test string back throught the 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";
}
Upvotes: 1
Views: 255
Reputation: 6740
just adding to what @nicolapaoli wrote: this is fixed in Hyperledger Composer release v0.19.13 FYI - you do get the return
value.
Upvotes: 1
Reputation: 55
I had very similar issue. I've just opened an issue with general example on GitHub here with ref to this question and to the message on Rocketchat as well. Hope this will be fixed soon.
Upvotes: 1