Commit 96f8ba44 authored by Heimdall's avatar Heimdall

Merge branch '379-issue' into 'master'

Resolve "[ADD] expose a new endpoint for constant values"

Closes #379

See merge request !690
parents c2cadd34 5197b725
Pipeline #129760711 passed with stages
in 62 minutes and 14 seconds
......@@ -130,6 +130,7 @@ func (cv ConstantValue010) MarshalJSON() ([]byte, error) {
}
result.Int64Values = make(map[string]int64)
result.BoolValues = make(map[string]bool)
result.StringValues = make(map[string]string)
for k, v := range cv.int64values {
result.Int64Values[k.String()] = v
}
......
......@@ -12,6 +12,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"gitlab.com/thorchain/thornode/common"
"gitlab.com/thorchain/thornode/constants"
q "gitlab.com/thorchain/thornode/x/thorchain/query"
)
......@@ -67,6 +68,8 @@ func NewQuerier(keeper Keeper, validatorMgr VersionedValidatorManager) sdk.Queri
return queryVaultsAddresses(ctx, keeper)
case q.QueryTSSSigners.Key:
return queryTSSSigners(ctx, path[1:], req, keeper)
case q.QueryConstantValues.Key:
return queryConstantValues(ctx, path[1:], req, keeper)
default:
return nil, sdk.ErrUnknownRequest(
fmt.Sprintf("unknown thorchain query endpoint: %s", path[0]),
......@@ -845,3 +848,14 @@ func queryTSSSigners(ctx sdk.Context, path []string, req abci.RequestQuery, keep
return res, nil
}
func queryConstantValues(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) {
ver := keeper.GetLowestActiveVersion(ctx)
constAccessor := constants.GetConstantValues(ver)
res, err := codec.MarshalJSONIndent(keeper.Cdc(), constAccessor)
if err != nil {
ctx.Logger().Error("fail to marshal constant values to json", "error", err)
return nil, sdk.ErrInternal("fail to marshal constant values to json")
}
return res, nil
}
......@@ -3,8 +3,9 @@ package thorchain
import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"gitlab.com/thorchain/thornode/common"
. "gopkg.in/check.v1"
"gitlab.com/thorchain/thornode/common"
)
type QuerierSuite struct{}
......
......@@ -33,8 +33,6 @@ func (q Query) Path(args ...string) string {
// query endpoints supported by the thorchain Querier
var (
QueryAdminConfigBnb = Query{Key: "adminconfig", EndpointTemplate: "/%s/admin/{%s}/{%s}"}
QueryAdminConfig = Query{Key: "adminconfigbnb", EndpointTemplate: "/%s/admin/{%s}"}
QueryChains = Query{Key: "chains", EndpointTemplate: "/%s/chains"}
QueryPool = Query{Key: "pool", EndpointTemplate: "/%s/pool/{%s}"}
QueryPools = Query{Key: "pools", EndpointTemplate: "/%s/pools"}
......@@ -61,12 +59,11 @@ var (
QueryVaultPubkeys = Query{Key: "vaultpubkeys", EndpointTemplate: "/%s/vaults/pubkeys"}
QueryVaultAddresses = Query{Key: "vaultaddresses", EndpointTemplate: "/%s/vaults/addresses"}
QueryTSSSigners = Query{Key: "tsssigner", EndpointTemplate: "/%s/vaults/{%s}/signers"}
QueryConstantValues = Query{Key: "constants", EndpointTemplate: "/%s/constants"}
)
// Queries all queries
var Queries = []Query{
QueryAdminConfig,
QueryAdminConfigBnb,
QueryPool,
QueryPools,
QueryChains,
......@@ -93,4 +90,5 @@ var Queries = []Query{
QueryKeygensPubkey,
QueryVaultAddresses,
QueryTSSSigners,
QueryConstantValues,
}
......@@ -16,6 +16,4 @@ func (s QuerySuite) TestQuery(c *C) {
c.Check(QueryTxIn.Endpoint("foo", "bar"), Equals, "/foo/tx/{bar}")
c.Check(QueryTxIn.Path("foo", "bar"), Equals, "custom/foo/txin/bar")
c.Check(QueryAdminConfigBnb.Endpoint("foo", "bar", "baz"), Equals, "/foo/admin/{bar}/{baz}")
c.Check(QueryAdminConfigBnb.Path("foo", "bar", "baz"), Equals, "custom/foo/adminconfig/bar/baz")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment