Add function to query ack proofs (#7732)

* Add function to query ack proofs

* Fix compilation issue

Co-authored-by: Aditya <adityasripal@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Jack Zampolin 2020-10-29 15:19:01 -07:00 committed by GitHub
parent e0e16f62f9
commit b2bc32f3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 0 deletions

View File

@ -231,3 +231,36 @@ func queryNextSequenceRecvABCI(clientCtx client.Context, portID, channelID strin
return types.NewQueryNextSequenceReceiveResponse(sequence, proofBz, proofHeight), nil
}
// QueryPacketAcknowledgement returns the data about a packet acknowledgement.
// If prove is true, it performs an ABCI store query in order to retrieve the merkle proof. Otherwise,
// it uses the gRPC query client
func QueryPacketAcknowledgement(clientCtx client.Context, portID, channelID string, sequence uint64, prove bool) (*types.QueryPacketAcknowledgementResponse, error) {
if prove {
return queryPacketAcknowledgementABCI(clientCtx, portID, channelID, sequence)
}
queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryPacketAcknowledgementRequest{
PortId: portID,
ChannelId: channelID,
Sequence: sequence,
}
return queryClient.PacketAcknowledgement(context.Background(), req)
}
func queryPacketAcknowledgementABCI(clientCtx client.Context, portID, channelID string, sequence uint64) (*types.QueryPacketAcknowledgementResponse, error) {
key := host.KeyPacketAcknowledgement(portID, channelID, sequence)
value, proofBz, proofHeight, err := ibcclient.QueryTendermintProof(clientCtx, key)
if err != nil {
return nil, err
}
if len(value) == 0 {
return nil, sdkerrors.Wrapf(types.ErrInvalidAcknowledgement, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence)
}
return types.NewQueryPacketAcknowledgementResponse(value, proofBz, proofHeight), nil
}