javascript - 如何将多个参数传递给 hyperledger-composer 查询?
问题描述
我仍然是区块链开发的初学者,我无法弄清楚我的代码有什么问题。
很简单,我想在这里使用两个参数查询资产。
我什至尝试对这些值进行硬编码,并且它在一个参数查询中运行良好。
使用休息服务器也可以正常工作。
**
* Vote transaction
* @param {org.evotedapp.biznet.GenerateElectionResult} result
* @transaction
*/
async function electionResult(result) {
var factory = getFactory();
var namespace = "org.evotedapp.biznet";
var currentElection;
const votes = await query("getBallotsByElection", {election:
"resource:org.evotedapp.biznet.Election#el892076"}) // this query works fine
return getAssetRegistry("org.evotedapp.biznet.Election")
.then(registry => {
var electionRegistry = registry.get(result.electionId);
return electionRegistry
})
.then(election => {
currentElection = election;
var candidates = election.candidates
const results = [];
for(let i = 0; i<candidates.length;i++) {
var candidateVotes = query("getBallotsByElectionAndCandidate", {election: `resource:org.evotedapp.biznet.Election#${result.electionId} `,candidate:`${candidates[i]}`})
var resultCount = factory.newResource(namespace, "ResultCount", result.electionId+i);
resultCount.candidate = candidates[i];
if(candidateVotes == []){
resultCount.votes = 0
}else{
resultCount.votes = candidateVotes.length;
}
results.push(resultCount)
}
var voteCountCandidate;
return getAssetRegistry("org.evotedapp.biznet.VoteCountCandidate")
.then(registry => {
voteCountCandidate = factory.newResource(namespace, "VoteCountCandidate", "vcc_"+result.electionId);
voteCountCandidate.election = currentElection
voteCountCandidate.results = results;
return registry.add(voteCountCandidate)
})
.then(() => {
var voteCountCandidateEvent = factory.newEvent(namespace, "GenerateElectionResultNotification");
voteCountCandidateEvent.voteCountCandidate = voteCountCandidate;
emit(voteCountCandidateEvent);
});
})
}
这是查询:
query getBallotsByElectionAndCandidate {
description: "Select all ballots by election"
statement:
SELECT org.evotedapp.biznet.Ballot
WHERE (election == _$election AND votedCandidate == _$candidate)
}
我希望此查询将匹配值返回给候选投票。它使事务失败并给出此错误:
Error: Error trying invoke business network with transaction id 5f256b4ed096962a60e2753f611cad7d051abd4703dde36cb03da08b14036788.
Error: No valid responses from any peers. Response from attempted peer comms was an error:
Error: transaction returned with failure:
ValidationException: Instance org.evotedapp.biznet.ResultCount#el9888210 missing required field votes`enter code here`
解决方案
推荐阅读
- sql - 函数 PL/SQL ORACLE
- android - 如何从 Kotlin 的 recyclerview 获取 Checkbox isChecked 数据
- java - JAVA 正则表达式识别值并对路径参数进行分类
- angular - Angular 11(或 9+)I18n 在启动时设置语言环境
- java - 具有非 void 返回值的方法的 Java Spring 异步异常处理
- activemq - 如何通过命令行获取 Apache ActiveMQ 的统计信息
- node.js - Connect-mongodb-session: TypeError: Cannot read property 'Store' of undefined (mongodb, nodejs, connect-mongodb-session)
- powershell - 不同计算机语言的日期转换出错
- c# - 反序列化列表
使用运行时的类型 - c# - 我可以在 Dapper 中使用查询方法来插入和更新行吗?