Skip to content

Commit

Permalink
feat: set default denom (#137)
Browse files Browse the repository at this point in the history
* feat: set default denom

* feat: set bae denom return error
  • Loading branch information
emidev98 authored May 23, 2023
1 parent 792dcd3 commit f513434
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 20 deletions.
6 changes: 6 additions & 0 deletions app/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const (
// BondDenom staking denom
BondDenom = "uluna"

// More denoms
// Luna = "luna" // 1 (base denom unit)
// MilliLuna = "mluna" // 10^-3 (milli)
MicroLuna = BondDenom // 10^-6 (micro)
// NanoLuna = "nluna" // 10^-9 (nano)

AuthzMsgExec = "/cosmos.authz.v1beta1.MsgExec"
AuthzMsgGrant = "/cosmos.authz.v1beta1.MsgGrant"
AuthzMsgRevoke = "/cosmos.authz.v1beta1.MsgRevoke"
Expand Down
24 changes: 24 additions & 0 deletions app/params/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package params

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/terra-money/core/v2/app/config"
)

func RegisterAddressesConfig() *sdk.Config {
sdkConfig := sdk.GetConfig()
sdkConfig.SetCoinType(config.CoinType)

accountPubKeyPrefix := config.AccountAddressPrefix + "pub"
validatorAddressPrefix := config.AccountAddressPrefix + "valoper"
validatorPubKeyPrefix := config.AccountAddressPrefix + "valoperpub"
consNodeAddressPrefix := config.AccountAddressPrefix + "valcons"
consNodePubKeyPrefix := config.AccountAddressPrefix + "valconspub"

sdkConfig.SetBech32PrefixForAccount(config.AccountAddressPrefix, accountPubKeyPrefix)
sdkConfig.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
sdkConfig.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
sdkConfig.SetAddressVerifier(wasmtypes.VerifyAddressLen())
return sdkConfig.Seal()
}
18 changes: 18 additions & 0 deletions app/params/denoms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package params

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/terra-money/core/v2/app/config"
)

func RegisterDenomsConfig() error {
// sdk.RegisterDenom(config.Luna, sdk.OneDec())
// sdk.RegisterDenom(config.MilliLuna, sdk.NewDecWithPrec(1, 3))
err := sdk.RegisterDenom(config.MicroLuna, sdk.NewDecWithPrec(1, 6))
if err != nil {
return err
}
// sdk.RegisterDenom(config.NanoLuna, sdk.NewDecWithPrec(1, 9))

return nil
}
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,11 @@ paths:
summary: >-
Query a delegation to an alliance by delegator addr, validator_addr and
denom

@deprecated: this endpoint will be replaced for by the encoded version

of the denom e.g.:
GET:/terra/alliances/terradr1231/terravaloper41234/ibc%2Falliance
operationId: IBCAllianceDelegation
responses:
'200':
Expand Down Expand Up @@ -1045,7 +1050,10 @@ paths:
- Query
/terra/alliances/ibc/{hash}:
get:
summary: Query a specific alliance by ibc hash
summary: |-
Query a specific alliance by ibc hash
@deprecated: this endpoint will be replaced for by the encoded version
of the denom e.g.: GET:/terra/alliances/ibc%2Falliance
operationId: IBCAlliance
responses:
'200':
Expand Down Expand Up @@ -1186,7 +1194,13 @@ paths:
- Query
/terra/alliances/rewards/{delegator_addr}/{validator_addr}/ibc/{hash}:
get:
summary: Query for rewards by delegator addr, validator_addr and denom
summary: >-
Query for rewards by delegator addr, validator_addr and denom

@deprecated: this endpoint will be replaced for by the encoded version

of the denom e.g.:
GET:/terra/alliances/terradr1231/terravaloper41234/ibc%2Falliance
operationId: IBCAllianceDelegationRewards
responses:
'200':
Expand Down
22 changes: 5 additions & 17 deletions cmd/terrad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
sdkconfig "github.com/cosmos/cosmos-sdk/client/config"
Expand All @@ -35,7 +34,6 @@ import (
tmcfg "github.com/tendermint/tendermint/config"

terraapp "github.com/terra-money/core/v2/app"
config "github.com/terra-money/core/v2/app/config"
"github.com/terra-money/core/v2/app/params"
"github.com/terra-money/core/v2/app/wasmconfig"
)
Expand All @@ -47,21 +45,11 @@ const flagIAVLCacheSize = "iavl-cache-size"
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
encodingConfig := terraapp.MakeEncodingConfig()

sdkConfig := sdk.GetConfig()
sdkConfig.SetCoinType(config.CoinType)

accountPubKeyPrefix := config.AccountAddressPrefix + "pub"
validatorAddressPrefix := config.AccountAddressPrefix + "valoper"
validatorPubKeyPrefix := config.AccountAddressPrefix + "valoperpub"
consNodeAddressPrefix := config.AccountAddressPrefix + "valcons"
consNodePubKeyPrefix := config.AccountAddressPrefix + "valconspub"

sdkConfig.SetBech32PrefixForAccount(config.AccountAddressPrefix, accountPubKeyPrefix)
sdkConfig.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
sdkConfig.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
sdkConfig.SetAddressVerifier(wasmtypes.VerifyAddressLen())
sdkConfig.Seal()
err := params.RegisterDenomsConfig()
if err != nil {
panic(err)
}
params.RegisterAddressesConfig()

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
Expand Down

0 comments on commit f513434

Please sign in to comment.