如何将多个参数传递给hyperledger-composer查询?

时间:2019-07-20 11:31:00

标签: javascript hyperledger-composer

我仍然是区块链开发的初学者,在这里我无法弄清楚我的代码出了什么问题。

我想在这里简单地使用两个参数查询资产。

我什至尝试对值进行硬编码,并且可以通过一个参数查询很好地工作。

也可以使用rest-server正常工作

async getRooms(){
    var DailyRoom = Parse.Object.extend("DailyRoom");
    var roomQuery = new Parse.Query(DailyRoom);
    roomQuery.equalTo("active", true);
    roomQuery.limit(20);
    roomQuery.find()
      .then(results => {
        results.forEach(room => {
          this.rooms.push(room.toJSON());
        });
      });
  }

}

这是查询

query getBallotsByElectionAndCandidate {

**
* 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);
                });
        })

}

我希望此查询将匹配的值返回给候选人投票。它使交易失败并给出此错误

description: "Select all ballots by election"
statement:
    SELECT org.evotedapp.biznet.Ballot
        WHERE (election == _$election AND votedCandidate == _$candidate)

0 个答案:

没有答案
相关问题