我的使用Hyperledger作曲家REST API创建钱包的代码:
async function walletCreation(tx) {
var userId = {
userId: tx.userId,
};
var walletPassword = {
walletPassword: tx.walletPassword,
};
const encryptWalletId = await request.post({ uri:
'http://payment.api.in/encrypt', json: userId });
const encryptWalletPassword = await request.post({ uri:
'http://payment.api.in/encryptPass', json: walletPassword });
return getAssetRegistry('com.payment.UserWallet')
.then(function (userAssetRegistry) {
// Get the factory for creating new asset instances.
var factory = getFactory();
// Create the wallet.
tx.walletId = encryptWalletId.walletId;
var walletAsset = factory.newResource('com.payment', 'UserWallet',
tx.walletId);
walletAsset.userId = tx.userId;
walletAsset.walletPassword = encryptWalletPassword.walletPassword;
walletAsset.currency = tx.currency;
walletAsset.walletBalance = 0;
walletAsset.createdDate = new Date();
userAssetRegistry.add(walletAsset);
})
.catch(function (error) {
throw new Error("wallet creation failed");
});
}
下面是用于创建钱包的请求正文(Swagger输入) :
{
"$class": "com.payment.WalletCreation",
"userId": "Hari",
"walletPassword": "hari@123",
"currency": "INR",
"walletBalance": 0
}
以下是上述输入的预期响应:
{
"$class": "com.payment.WalletCreation",
"userId": "Hari",
"status":"Wallet creation successfully",
"WalletId":"1234567asder",
"walletId": 0,
"walletPassword": "hari@123",
"currency": "INR",
"walletBalance": 0,
"transactionId":
"deee486e2e74647635e53e316f2a8e1b71ab500e9dd3bf15945665a4025fc208"
}
但这就是得到的回应
{
"$class": "com.payment.WalletCreation",
"userId": "Hari",
"walletPassword": "hari@123",
"currency": "INR",
"walletBalance": 0,
"transactionId":
"deee486e2e74647635e53e316f2a8e1b71ab500e9dd3bf15945665a4025fc208"
}
请帮助我修复此问题,卡了2天无法修复该错误
答案 0 :(得分:0)
https://hyperledger.github.io/composer/latest/integrating/call-out(第3个代码块)中有一个示例说明了您要尝试执行的操作,例如(用下面替换)
仅供参考,您无法重新分配tx.walletId
(它是交易输入的一部分!)。另外,新的Date()不确定。
响应完全是您对TRANSACTION帖子的期望-您需要使用/ GET在注册表'com.payment.UserWallet'中使用/ GET检查您正在创建的ASSET实例(资产)正在添加。此外,您期望的响应与您的功能不匹配。
答案 1 :(得分:0)
从事务处理器功能返回复杂类型
模型文件:
namespace org.sample
concept MyConcept {
o String value
}
@returns(MyConcept)
transaction MyTransaction {
}
事务处理器功能:
/**
* Handle a transaction that returns a concept.
* @param {org.sample.MyTransaction} transaction The transaction.
* @returns {org.sample.MyConcept} The concept.
* @transaction
*/
async function myTransaction(transaction) {
const factory = getFactory();
const concept = factory.newConcept('org.sample', 'MyConcept');
concept.value = 'hello world!';
return concept;
}
Profile ZB @zeimbeekor
再见!