Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit b80b701

Browse files
authored
Release v0.6.0
2 parents 03a64c8 + ae045c2 commit b80b701

32 files changed

+2753
-843
lines changed

.circleci/config.yml

+28-27
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,50 @@
22
# See: https://circleci.com/docs/2.0/configuration-reference
33
version: 2.1
44

5-
# Define a job to be invoked later in a workflow.
6-
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
5+
orbs:
6+
go: circleci/go@1.7.3
7+
78
jobs:
89
test:
9-
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
10-
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
1110
machine:
12-
image: ubuntu-2204:2022.07.1
13-
resource_class: large
14-
# Add steps to the job
15-
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
11+
image: ubuntu-2204:2022.10.1
1612
steps:
13+
- go/install:
14+
version: "1.20"
1715
- checkout
18-
- add_ssh_keys
1916
- run:
2017
name: Print Go environment
2118
command: "go env"
22-
- restore_cache: # restores saved cache if no changes are detected since last run
23-
keys:
24-
- go-mod-v6-{{ checksum "go.sum" }}
25-
- run:
26-
name: Install Dependencies
27-
command: sudo apt-get install libzmq3-dev
28-
- run:
29-
name: Retrieve dependencies
30-
command: go mod download
31-
- save_cache:
19+
- go/load-cache:
3220
key: go-mod-v6-{{ checksum "go.sum" }}
33-
paths:
34-
- "/home/circleci/.go_workspace/pkg/mod"
35-
- run:
36-
name: Lint
37-
command: |
38-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.1
39-
./bin/golangci-lint run
21+
- go/mod-download
22+
- go/save-cache:
23+
key: go-mod-v6-{{ checksum "go.sum" }}
24+
path: "/home/circleci/.go_workspace/pkg/mod"
4025
- run:
4126
name: Run tests
4227
command: |
4328
make test
29+
lint:
30+
machine:
31+
image: ubuntu-2204:2022.10.1
32+
steps:
33+
- go/install:
34+
version: "1.20"
35+
- checkout
36+
- run:
37+
name: Lint
38+
command: |
39+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.2
40+
./bin/golangci-lint run
4441
4542
# Invoke jobs via workflows
4643
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
4744
workflows:
48-
build-lint-test:
45+
version: 2
46+
test:
4947
jobs:
5048
- test
49+
lint:
50+
jobs:
51+
- lint

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ test:
99
mock-gen:
1010
mkdir -p $(MOCKS_DIR)
1111
$(MOCKGEN_CMD) -source=client/interface.go -package mocks -destination $(MOCKS_DIR)/client.go
12+
$(MOCKGEN_CMD) -source=query/interface.go -package mocks -destination $(MOCKS_DIR)/query.go

client/client.go

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package client
22

33
import (
4-
"fmt"
5-
"time"
4+
lensclient "github.com/strangelove-ventures/lens/client"
65

76
"github.com/babylonchain/rpc-client/config"
8-
lensclient "github.com/strangelove-ventures/lens/client"
7+
"github.com/babylonchain/rpc-client/query"
98
)
109

1110
var _ BabylonClient = &Client{}
1211

1312
type Client struct {
1413
*lensclient.ChainClient
15-
cfg *config.BabylonConfig
14+
*query.QueryClient
1615

17-
// retry attributes
18-
retrySleepTime time.Duration
19-
maxRetrySleepTime time.Duration
16+
cfg *config.BabylonConfig
2017
}
2118

22-
func New(cfg *config.BabylonConfig, retrySleepTime, maxRetrySleepTime time.Duration) (*Client, error) {
19+
func New(cfg *config.BabylonConfig) (*Client, error) {
2320
// ensure cfg is valid
2421
if err := cfg.Validate(); err != nil {
2522
return nil, err
@@ -31,8 +28,14 @@ func New(cfg *config.BabylonConfig, retrySleepTime, maxRetrySleepTime time.Durat
3128
return nil, err
3229
}
3330

31+
// create a queryClient so that the Client inherits all query functions
32+
queryClient, err := query.NewWithClient(cc.RPCClient, cfg.Timeout)
33+
if err != nil {
34+
return nil, err
35+
}
36+
3437
// wrap to our type
35-
client := &Client{cc, cfg, retrySleepTime, maxRetrySleepTime}
38+
client := &Client{cc, queryClient, cfg}
3639

3740
return client, nil
3841
}
@@ -41,15 +44,6 @@ func (c *Client) GetConfig() *config.BabylonConfig {
4144
return c.cfg
4245
}
4346

44-
func (c *Client) GetTagIdx() uint8 {
45-
tagIdxStr := c.cfg.TagIdx
46-
if len(tagIdxStr) != 1 {
47-
panic(fmt.Errorf("tag index should be one byte"))
48-
}
49-
// convert tagIdx from string to its ascii value
50-
return uint8(rune(tagIdxStr[0]))
51-
}
52-
5347
func (c *Client) Stop() {
5448
if c.ChainClient.RPCClient != nil && c.ChainClient.RPCClient.IsRunning() {
5549
<-c.ChainClient.RPCClient.Quit()

client/interface.go

+6-35
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,20 @@ package client
33
import (
44
btcctypes "github.com/babylonchain/babylon/x/btccheckpoint/types"
55
btclctypes "github.com/babylonchain/babylon/x/btclightclient/types"
6-
checkpointingtypes "github.com/babylonchain/babylon/x/checkpointing/types"
7-
epochingtypes "github.com/babylonchain/babylon/x/epoching/types"
8-
"github.com/babylonchain/rpc-client/config"
9-
"github.com/btcsuite/btcd/chaincfg/chainhash"
10-
"github.com/btcsuite/btcd/wire"
116
sdk "github.com/cosmos/cosmos-sdk/types"
12-
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
7+
8+
"github.com/babylonchain/rpc-client/config"
9+
bbnquery "github.com/babylonchain/rpc-client/query"
1310
)
1411

1512
type BabylonClient interface {
16-
Stop()
13+
bbnquery.BabylonQueryClient
14+
1715
GetConfig() *config.BabylonConfig
18-
GetTagIdx() uint8
1916
GetAddr() (sdk.AccAddress, error)
2017
MustGetAddr() sdk.AccAddress
18+
2119
InsertBTCSpvProof(msg *btcctypes.MsgInsertBTCSpvProof) (*sdk.TxResponse, error)
2220
InsertHeader(msg *btclctypes.MsgInsertHeader) (*sdk.TxResponse, error)
2321
InsertHeaders(msgs []*btclctypes.MsgInsertHeader) (*sdk.TxResponse, error)
24-
MustInsertBTCSpvProof(msg *btcctypes.MsgInsertBTCSpvProof) *sdk.TxResponse
25-
26-
// staking module related queries
27-
QueryStakingParams() (*stakingtypes.Params, error)
28-
29-
// epoch module related queries
30-
QueryEpochingParams() (*epochingtypes.Params, error)
31-
QueryCurrentEpoch() (uint64, error)
32-
33-
// btclightclient module related queries
34-
QueryBTCLightclientParams() (*btclctypes.Params, error)
35-
QueryHeaderChainTip() (*chainhash.Hash, uint64, error)
36-
QueryBaseHeader() (*wire.BlockHeader, uint64, error)
37-
QueryContainsBlock(blockHash *chainhash.Hash) (bool, error)
38-
39-
// btccheckpoint module related queries
40-
QueryBTCCheckpointParams() (*btcctypes.Params, error)
41-
MustQueryBTCCheckpointParams() *btcctypes.Params
42-
43-
// checkpointing module related queries
44-
QueryRawCheckpoint(epochNumber uint64) (*checkpointingtypes.RawCheckpointWithMeta, error)
45-
QueryRawCheckpointList(status checkpointingtypes.CheckpointStatus) ([]*checkpointingtypes.RawCheckpointWithMeta, error)
46-
BlsPublicKeyList(epochNumber uint64) ([]*checkpointingtypes.ValidatorWithBlsKey, error)
47-
48-
// monitor module related queries
49-
QueryEndedEpochBtcHeight(epochNum uint64) (uint64, error)
50-
QueryReportedCheckpointBtcHeight(hash string) (uint64, error)
5122
}

client/keys_test.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
11
package client_test
22

33
import (
4-
"math/rand"
5-
"strings"
6-
"testing"
7-
"time"
8-
94
bbn "github.com/babylonchain/babylon/app"
105
"github.com/babylonchain/babylon/testutil/datagen"
116
"github.com/babylonchain/rpc-client/client"
127
"github.com/babylonchain/rpc-client/config"
138
"github.com/cosmos/cosmos-sdk/crypto/hd"
149
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1510
"github.com/stretchr/testify/require"
11+
"math/rand"
12+
"strings"
13+
"testing"
1614
)
1715

1816
func FuzzKeys(f *testing.F) {
1917
datagen.AddRandomSeedsToFuzzer(f, 10)
2018

2119
f.Fuzz(func(t *testing.T, seed int64) {
22-
rand.Seed(seed)
20+
r := rand.New(rand.NewSource(seed))
2321

2422
// create a keyring
25-
keyringName := datagen.GenRandomHexStr(10)
23+
keyringName := datagen.GenRandomHexStr(r, 10)
2624
dir := t.TempDir()
2725
mockIn := strings.NewReader("")
28-
cdc := bbn.MakeTestEncodingConfig()
26+
cdc := bbn.GetEncodingConfig()
2927
kr, err := keyring.New(keyringName, "test", dir, mockIn, cdc.Marshaler)
3028
require.NoError(t, err)
3129

3230
// create a random key pair in this keyring
33-
keyName := datagen.GenRandomHexStr(10)
31+
keyName := datagen.GenRandomHexStr(r, 10)
3432
_, _, err = kr.NewMnemonic(
3533
keyName,
3634
keyring.English,
3735
hd.CreateHDPath(118, 0, 0).String(),
3836
keyring.DefaultBIP39Passphrase,
3937
hd.Secp256k1,
4038
)
41-
require.NoError(t, err)
39+
require.NoError(t, err)
4240

4341
// create a Babylon client with this random keyring
4442
cfg := config.DefaultBabylonConfig()
4543
cfg.KeyDirectory = dir
4644
cfg.Key = keyName
47-
cl, err := client.New(&cfg, 1*time.Minute, 5*time.Minute)
45+
cl, err := client.New(&cfg)
4846
require.NoError(t, err)
4947

5048
// retrieve the key info from key ring

client/modified_lensclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func newLensClient(ccc *lensclient.ChainClientConfig, kro ...keyring.Option) (*l
2121
cc := &lensclient.ChainClient{
2222
KeyringOptions: keyringOptions,
2323
Config: ccc,
24-
Codec: lensclient.MakeCodec(ccc.Modules),
24+
Codec: lensclient.MakeCodec(ccc.Modules, []string{}),
2525
}
2626
if err := cc.Init(); err != nil {
2727
return nil, err

client/query_btc_checkpoint.go

-38
This file was deleted.

client/query_btc_lightclient.go

-73
This file was deleted.

0 commit comments

Comments
 (0)