laconicd/app/params/config.go
prathamesh0 e513f79b81
Add a minimal chain and placeholders for bond module (#1)
* Setup minimal chain

* Change app and command name

* Rename command folder

* Add run instructions

* Add placeholder files for bond module

* Missing new line
2024-02-01 10:18:40 +05:30

70 lines
2.1 KiB
Go

package params
import (
"cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
CoinUnit = "photon"
DefaultBondDenom = CoinUnit
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address.
Bech32PrefixAccAddr = "photon"
)
var (
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key.
Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub"
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address.
Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper"
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key.
Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub"
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address.
Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons"
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key.
Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub"
)
func init() {
SetAddressPrefixes()
RegisterDenoms()
}
func RegisterDenoms() {
err := sdk.RegisterDenom(CoinUnit, math.LegacyOneDec())
if err != nil {
panic(err)
}
}
func SetAddressPrefixes() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
// This is copied from the cosmos sdk v0.43.0-beta1
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return errors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}
if len(bytes) > address.MaxAddrLen {
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}
if len(bytes) != 20 && len(bytes) != 32 {
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}
return nil
})
}