e2e: integrate light clients (#6196)

This commit is contained in:
Callum Waters
2021-03-05 14:24:45 +01:00
committed by GitHub
parent 4540bef665
commit 418e2c140f
14 changed files with 226 additions and 54 deletions
+22
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"regexp"
"time"
"github.com/gogo/protobuf/proto"
@@ -59,6 +60,27 @@ func KeyPathFn(fn KeyPathFunc) Option {
}
}
// DefaultMerkleKeyPathFn creates a function used to generate merkle key paths
// from a path string and a key. This is the default used by the cosmos SDK.
// This merkle key paths are required when verifying /abci_query calls
func DefaultMerkleKeyPathFn() KeyPathFunc {
// regexp for extracting store name from /abci_query path
storeNameRegexp := regexp.MustCompile(`\/store\/(.+)\/key`)
return func(path string, key []byte) (merkle.KeyPath, error) {
matches := storeNameRegexp.FindStringSubmatch(path)
if len(matches) != 2 {
return nil, fmt.Errorf("can't find store name in %s using %s", path, storeNameRegexp)
}
storeName := matches[1]
kp := merkle.KeyPath{}
kp = kp.AppendKey([]byte(storeName), merkle.KeyEncodingURL)
kp = kp.AppendKey(key, merkle.KeyEncodingURL)
return kp, nil
}
}
// NewClient returns a new client.
func NewClient(next rpcclient.Client, lc LightClient, opts ...Option) *Client {
c := &Client{