Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,45 @@ module github.com/cosmostation/cvms
go 1.23

require (
github.com/cometbft/cometbft v0.38.13-0.20240930095538-e339afc0bced // v0.38.x
github.com/go-playground/validator/v10 v10.22.0
github.com/go-resty/resty/v2 v2.13.1
github.com/golang/protobuf v1.5.4
github.com/cometbft/cometbft v0.38.16 // v0.38.x
github.com/go-playground/validator/v10 v10.24.0
github.com/go-resty/resty/v2 v2.16.5
github.com/golang/protobuf v1.5.4 // indirect
github.com/gorilla/mux v1.8.1
github.com/jhump/protoreflect v1.15.1
github.com/jhump/protoreflect v1.17.0
github.com/jinzhu/inflection v1.0.0
github.com/joho/godotenv v1.5.1
github.com/klauspost/compress v1.17.9
github.com/klauspost/compress v1.17.11
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.1
github.com/prometheus/client_golang v1.20.5
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/uptrace/bun v1.2.8
github.com/uptrace/bun/dialect/pgdialect v1.2.8
github.com/uptrace/bun/driver/pgdriver v1.2.8
github.com/uptrace/bun/extra/bundebug v1.2.8
golang.org/x/crypto v0.31.0
google.golang.org/grpc v1.66.1
golang.org/x/crypto v0.32.0
google.golang.org/grpc v1.70.0 // v1.70.x
gopkg.in/yaml.v3 v3.0.1
)

require (
cosmossdk.io/api v0.8.2
google.golang.org/protobuf v1.36.3
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/bufbuild/protocompile v0.10.0 // indirect
github.com/bufbuild/protocompile v0.14.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand All @@ -45,21 +50,23 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/petermattis/goid v0.0.0-20241211131331-93ee7e083c43 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.57.0 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sasha-s/go-deadlock v0.3.5 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/net v0.29.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/time v0.9.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250122153221-138b5a5a4fd4 // indirect
mellium.im/sasl v0.3.2 // indirect
)
155 changes: 65 additions & 90 deletions go.sum

Large diffs are not rendered by default.

105 changes: 38 additions & 67 deletions internal/common/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"context"
"encoding/json"
"net/http"
"strconv"
"time"

Expand All @@ -22,16 +21,16 @@ func GetStatus(c common.CommonClient) (
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

requester := c.RPCClient.R().SetContext(ctx)
resp, err := requester.Get(types.CosmosStatusQueryPath)
// requester := c.RPCClient.R().SetContext(ctx)
resp, err := c.RPCClient.Get(ctx, types.CosmosStatusQueryPath)
if err != nil {
return 0, time.Time{}, errors.Errorf("rpc call is failed from %s: %s", resp.Request.URL, err)
}
if resp.StatusCode() != http.StatusOK {
return 0, time.Time{}, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())
return 0, time.Time{}, errors.Errorf("rpc call is failed from: %s", err)
}
// if resp.StatusCode() != http.StatusOK {
// return 0, time.Time{}, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())
// }

latestBlockHeight, latestBlockTimestamp, err := parser.CosmosStatusParser(resp.Body())
latestBlockHeight, latestBlockTimestamp, err := parser.CosmosStatusParser(resp)
if err != nil {
return 0, time.Time{}, errors.Wrapf(err, "got data, but failed to parse the data")
}
Expand All @@ -54,17 +53,17 @@ func GetBlock(c common.CommonClient, height int64) (
defer cancel()

// create requester
requester := c.RPCClient.R().SetContext(ctx)
// requester := c.RPCClient.R().SetContext(ctx)

resp, err := requester.Get(types.CosmosBlockQueryPath(height))
resp, err := c.RPCClient.Get(ctx, types.CosmosBlockQueryPath(height))
if err != nil {
return 0, time.Time{}, "", nil, 0, nil, errors.Errorf("rpc call is failed from %s: %s", resp.Request.URL, err)
}
if resp.StatusCode() != http.StatusOK {
return 0, time.Time{}, "", nil, 0, nil, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())
return 0, time.Time{}, "", nil, 0, nil, errors.Errorf("rpc call is failed from: %s", err)
}
// if resp.StatusCode() != http.StatusOK {
// return 0, time.Time{}, "", nil, 0, nil, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())
// }

blockHeight, blockTimeStamp, blockProposerAddress, blockTxs, lastCommitBlockHeight, blockSignatures, err := parser.CosmosBlockParser(resp.Body())
blockHeight, blockTimeStamp, blockProposerAddress, blockTxs, lastCommitBlockHeight, blockSignatures, err := parser.CosmosBlockParser(resp)
if err != nil {
return 0, time.Time{}, "", nil, 0, nil, errors.Wrapf(err, "got data, but failed to parse the data")
}
Expand All @@ -78,9 +77,6 @@ func GetValidators(c common.CommonClient, height ...int64) ([]types.CosmosValida
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

// create requester
requester := c.RPCClient.R().SetContext(ctx)

totalValidators := make([]types.CosmosValidator, 0)
var queryPath string
page := 1
Expand All @@ -94,15 +90,15 @@ func GetValidators(c common.CommonClient, height ...int64) ([]types.CosmosValida
queryPath = types.CosmosValidatorQueryPath(page)
}

resp, err := requester.Get(queryPath)
resp, err := c.RPCClient.Get(ctx, queryPath)
if err != nil {
return nil, errors.Errorf("rpc call is failed from %s: %s", resp.Request.URL, err)
}
if resp.StatusCode() != http.StatusOK {
return nil, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())
return nil, errors.Errorf("rpc call is failed from: %s", err)
}
// if resp.StatusCode() != http.StatusOK {
// return nil, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())
// }

validators, totalValidatorsCount, err := parser.CosmosValidatorParser(resp.Body())
validators, totalValidatorsCount, err := parser.CosmosValidatorParser(resp)
if err != nil {
return nil, errors.Wrapf(err, "got data, but failed to parse the data")
}
Expand Down Expand Up @@ -132,25 +128,19 @@ func GetStakingValidatorsByHeight(c common.CommonClient, chainName string, heigh
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

// create requester
requester := c.APIClient.R().SetContext(ctx)

// set header by block height
heightStr := strconv.FormatInt(height, 10)
header := map[string]string{"Content-Type": "application/json", "x-cosmos-block-height": heightStr}
requester.SetHeaders(header)
c.APIClient.SetHeaders(header)

// get on-chain validators in staking module
resp, err := requester.Get(queryPath)
resp, err := c.APIClient.Get(ctx, queryPath)
if err != nil {
// c.Errorf("api error: %s", err)
return nil, errors.Wrap(err, "failed in api")
}
if resp.StatusCode() != http.StatusOK {
return nil, errors.Errorf("got %d code from %s", resp.StatusCode(), resp.Request.URL)
}

stakingValidators, err := stakingValidatorParser(resp.Body())
stakingValidators, err := stakingValidatorParser(resp)
if err != nil {
return nil, errors.Wrap(err, "failed in api")
}
Expand Down Expand Up @@ -192,19 +182,16 @@ func GetStakingValidators(c common.CommonClient, chainName string, status ...str
defer cancel()

// create requester
requester := c.APIClient.R().SetContext(ctx)
requester := c.APIClient

// get on-chain validators in staking module
resp, err := requester.Get(queryPath)
resp, err := requester.Get(ctx, queryPath)
if err != nil {
// c.Errorf("api error: %s", err)
return nil, errors.Wrap(err, "failed in api")
}
if resp.StatusCode() != http.StatusOK {
return nil, errors.Errorf("got %d code from %s", resp.StatusCode(), resp.Request.URL)
}

stakingValidators, err := stakingValidatorParser(resp.Body())
stakingValidators, err := stakingValidatorParser(resp)
if err != nil {
return nil, errors.Wrap(err, "failed in api")
}
Expand All @@ -218,17 +205,14 @@ func GetProviderValidators(c common.CommonClient, consumerID string) ([]types.Pr
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

requester := c.APIClient.R().SetContext(ctx)
resp, err := requester.Get(types.ProviderValidatorsQueryPath(consumerID))
requester := c.APIClient
resp, err := requester.Get(ctx, types.ProviderValidatorsQueryPath(consumerID))
if err != nil {
return nil, errors.Cause(err)
}
if resp.StatusCode() != http.StatusOK {
return nil, errors.Wrapf(err, "api error: got %d code from %s", resp.StatusCode(), resp.Request.URL)
}

var result types.CosmosProviderValidatorsResponse
if err := json.Unmarshal(resp.Body(), &result); err != nil {
if err := json.Unmarshal(resp, &result); err != nil {
return nil, errors.Cause(err)
}

Expand All @@ -239,17 +223,14 @@ func GetConsumerChainID(c common.CommonClient) ([]types.ConsumerChain, error) {
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

requester := c.APIClient.R().SetContext(ctx)
resp, err := requester.Get(types.ConsumerChainListQueryPath)
requester := c.APIClient
resp, err := requester.Get(ctx, types.ConsumerChainListQueryPath)
if err != nil {
return nil, err
}
if resp.StatusCode() != http.StatusOK {
return nil, errors.Errorf("api error: got %d code from %s", resp.StatusCode(), resp.Request.URL)
}

var result types.CosmosConsumerChainsResponse
if err := json.Unmarshal(resp.Body(), &result); err != nil {
if err := json.Unmarshal(resp, &result); err != nil {
return nil, err
}

Expand All @@ -260,17 +241,14 @@ func GetConsumerChainHRP(c common.CommonClient) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

requester := c.APIClient.R().SetContext(ctx)
resp, err := requester.Get(types.CosmosSlashingLimitQueryPath)
requester := c.APIClient
resp, err := requester.Get(ctx, types.CosmosSlashingLimitQueryPath)
if err != nil {
return "", errors.Cause(err)
}
if resp.StatusCode() != http.StatusOK {
return "", errors.Wrapf(err, "api error: got %d code from %s", resp.StatusCode(), resp.Request.URL)
}

var result types.CosmosSlashingResponse
if err := json.Unmarshal(resp.Body(), &result); err != nil {
if err := json.Unmarshal(resp, &result); err != nil {
return "", errors.Cause(err)
}

Expand Down Expand Up @@ -300,19 +278,12 @@ func GetBlockResults(c common.CommonClient, height int64) (
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
defer cancel()

// create requester
requester := c.RPCClient.R().SetContext(ctx)

resp, err := requester.Get(types.CosmosBlockResultsQueryPath(height))
resp, err := c.RPCClient.Get(ctx, types.CosmosBlockResultsQueryPath(height))
if err != nil {
return nil, nil, errors.Errorf("rpc call is failed from %s: %s", resp.Request.URL, err)
}
if resp.StatusCode() != http.StatusOK {
return nil, nil, errors.Errorf("stanage status code from %s: [%d]", resp.Request.URL, resp.StatusCode())

return nil, nil, errors.Errorf("rpc call is failed from %s: %s", types.CosmosBlockResultsQueryPath(height), err)
}

txsEvents, blockEvents, err := parser.CosmosBlockResultsParser(resp.Body())
txsEvents, blockEvents, err := parser.CosmosBlockResultsParser(resp)
if err != nil {
return nil, nil, errors.WithStack(err)
}
Expand Down
Loading