From 2f3c476928b0090e4cc9a3ae84f7cf3dbf04feea Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Tue, 13 Aug 2024 14:40:10 +1000 Subject: [PATCH] fix --- clientcontroller/cosmwasm/consumer.go | 31 +++++++++------------------ 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/clientcontroller/cosmwasm/consumer.go b/clientcontroller/cosmwasm/consumer.go index c440d8af..f64c60f1 100644 --- a/clientcontroller/cosmwasm/consumer.go +++ b/clientcontroller/cosmwasm/consumer.go @@ -298,33 +298,22 @@ func (wc *CosmwasmConsumerController) QueryLastPublicRandCommit(fpPk *btcec.Publ return nil, fmt.Errorf("failed to query smart contract state: %w", err) } - // Define a response struct - var commits []PubRandCommitResponse - err = json.Unmarshal(dataFromContract.Data, &commits) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal response: %w", err) - } - - if len(commits) == 0 { + if len(dataFromContract.Data) == 0 { // expected when there is no PR commit at all - // `get_pub_rand_commit`'s return type is Vec and it can be - // empty vector if no results found return nil, nil } - if len(commits) > 1 { - return nil, fmt.Errorf("expected length to be 1, but got :%d", len(commits)) + // Define a response struct + var commitResp PubRandCommitResponse + err = json.Unmarshal(dataFromContract.Data, &commitResp) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal response: %w", err) } - // Convert the response to the expected map format - var commit *fptypes.PubRandCommit = nil - for _, commitRes := range commits { - commitCopy := commitRes // create a copy to avoid referencing the loop variable - commit = &fptypes.PubRandCommit{ - StartHeight: commitCopy.StartHeight, - NumPubRand: commitCopy.NumPubRand, - Commitment: commitCopy.Commitment, - } + commit := &fptypes.PubRandCommit{ + StartHeight: commitResp.StartHeight, + NumPubRand: commitResp.NumPubRand, + Commitment: commitResp.Commitment, } if err := commit.Validate(); err != nil {