ABCIQueryWithOptions returns an error if opts.Prove is false.
(ctx context.Context, path string, data tmbytes.HexBytes, opts rpcclient.ABCIQueryOptions)
| 131 | |
| 132 | // ABCIQueryWithOptions returns an error if opts.Prove is false. |
| 133 | func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes, |
| 134 | opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { |
| 135 | |
| 136 | // always request the proof |
| 137 | opts.Prove = true |
| 138 | |
| 139 | res, err := c.next.ABCIQueryWithOptions(ctx, path, data, opts) |
| 140 | if err != nil { |
| 141 | return nil, err |
| 142 | } |
| 143 | resp := res.Response |
| 144 | |
| 145 | // Validate the response. |
| 146 | if resp.IsErr() { |
| 147 | return nil, fmt.Errorf("err response code: %v", resp.Code) |
| 148 | } |
| 149 | if len(resp.Key) == 0 { |
| 150 | return nil, errors.New("empty key") |
| 151 | } |
| 152 | if resp.ProofOps == nil || len(resp.ProofOps.Ops) == 0 { |
| 153 | return nil, errors.New("no proof ops") |
| 154 | } |
| 155 | if resp.Height <= 0 { |
| 156 | return nil, errNegOrZeroHeight |
| 157 | } |
| 158 | |
| 159 | // Update the light client if we're behind. |
| 160 | // NOTE: AppHash for height H is in header H+1. |
| 161 | nextHeight := resp.Height + 1 |
| 162 | l, err := c.updateLightClientIfNeededTo(ctx, &nextHeight) |
| 163 | if err != nil { |
| 164 | return nil, err |
| 165 | } |
| 166 | |
| 167 | // Validate the value proof against the trusted header. |
| 168 | if resp.Value != nil { |
| 169 | // 1) build a Merkle key path from path and resp.Key |
| 170 | if c.keyPathFn == nil { |
| 171 | return nil, errors.New("please configure Client with KeyPathFn option") |
| 172 | } |
| 173 | |
| 174 | kp, err := c.keyPathFn(path, resp.Key) |
| 175 | if err != nil { |
| 176 | return nil, fmt.Errorf("can't build merkle key path: %w", err) |
| 177 | } |
| 178 | |
| 179 | // 2) verify value |
| 180 | err = c.prt.VerifyValue(resp.ProofOps, l.AppHash, kp.String(), resp.Value) |
| 181 | if err != nil { |
| 182 | return nil, fmt.Errorf("verify value proof: %w", err) |
| 183 | } |
| 184 | } else { // OR validate the absence proof against the trusted header. |
| 185 | err = c.prt.VerifyAbsence(resp.ProofOps, l.AppHash, string(resp.Key)) |
| 186 | if err != nil { |
| 187 | return nil, fmt.Errorf("verify absence proof: %w", err) |
| 188 | } |
| 189 | } |
| 190 |
no test coverage detected