diff --git a/chaincfg/coin.go b/chaincfg/coin.go new file mode 100644 index 00000000..05cf16ab --- /dev/null +++ b/chaincfg/coin.go @@ -0,0 +1,22 @@ +package chaincfg + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + // Bip44CoinType satisfies EIP84. See https://github.com/ethereum/EIPs/issues/84 for more info. + Bip44CoinType uint32 = 459 // TODO: need new coin type for 0g-chain (a0gi) + // eth = 60 + // kava = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md + // BIP44HDPath is the default BIP44 HD path used on Ethereum. + //BIP44HDPath = ethaccounts.DefaultBaseDerivationPath.String() +) + +// TODO: Implement BIP44CoinType and BIP44HDPath +// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets. +func setBip44CoinType(config *sdk.Config) { + config.SetCoinType(Bip44CoinType) + //config.SetPurpose(sdk.Purpose) // Shared + //config.SetFullFundraiserPath(BIP44HDPath) //nolint: staticcheck +} diff --git a/chaincfg/config.go b/chaincfg/config.go new file mode 100644 index 00000000..88fadbda --- /dev/null +++ b/chaincfg/config.go @@ -0,0 +1,15 @@ +package chaincfg + +import sdk "github.com/cosmos/cosmos-sdk/types" + +const ( + AppName = "0gchain" + EnvPrefix = "0GCHAIN" +) + +func SetSDKConfig() *sdk.Config { + config := sdk.GetConfig() + setBech32Prefixes(config) + setBip44CoinType(config) + return config +} diff --git a/chaincfg/denoms.go b/chaincfg/denoms.go new file mode 100644 index 00000000..cbd61280 --- /dev/null +++ b/chaincfg/denoms.go @@ -0,0 +1,27 @@ +package chaincfg + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // DisplayDenom defines the denomination displayed to users in client applications. + DisplayDenom = "a0gi" + // BaseDenom defines to the default denomination used in 0g-chain + BaseDenom = "neuron" + + BaseDenomUnit = 18 + + ConversionMultiplier = 1e18 +) + +// RegisterDenoms registers the base and display denominations to the SDK. +func RegisterDenoms() { + if err := sdk.RegisterDenom(DisplayDenom, sdk.OneDec()); err != nil { + panic(err) + } + + if err := sdk.RegisterDenom(BaseDenom, sdk.NewDecWithPrec(1, BaseDenomUnit)); err != nil { + panic(err) + } +} diff --git a/chaincfg/homedir.go b/chaincfg/homedir.go new file mode 100644 index 00000000..2a4cb933 --- /dev/null +++ b/chaincfg/homedir.go @@ -0,0 +1,25 @@ +package chaincfg + +import ( + stdlog "log" + "os" + "path/filepath" +) + +const ( + HomeDirName = ".0gchain" +) + +var ( + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string +) + +func init() { + userHomeDir, err := os.UserHomeDir() + if err != nil { + stdlog.Printf("Failed to get home dir %v", err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, HomeDirName) +} diff --git a/chaincfg/prefix.go b/chaincfg/prefix.go new file mode 100644 index 00000000..b45c8f6c --- /dev/null +++ b/chaincfg/prefix.go @@ -0,0 +1,44 @@ +package chaincfg + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // Bech32Prefix defines the Bech32 prefix used for EthAccounts + Bech32Prefix = "0g" + + // PrefixAccount is the prefix for account keys + PrefixAccount = "acc" + // PrefixValidator is the prefix for validator keys + PrefixValidator = "val" + // PrefixConsensus is the prefix for consensus keys + PrefixConsensus = "cons" + // PrefixPublic is the prefix for public keys + PrefixPublic = "pub" + // PrefixOperator is the prefix for operator keys + PrefixOperator = "oper" + + // PrefixAddress is the prefix for addresses + PrefixAddress = "addr" + + // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address + Bech32PrefixAccAddr = Bech32Prefix + // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key + Bech32PrefixAccPub = Bech32Prefix + PrefixPublic + // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address + Bech32PrefixValAddr = Bech32Prefix + PrefixValidator + PrefixOperator + // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key + Bech32PrefixValPub = Bech32Prefix + PrefixValidator + PrefixOperator + PrefixPublic + // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address + Bech32PrefixConsAddr = Bech32Prefix + PrefixValidator + PrefixConsensus + // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key + Bech32PrefixConsPub = Bech32Prefix + PrefixValidator + PrefixConsensus + PrefixPublic +) + +// setBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. +func setBech32Prefixes(config *sdk.Config) { + config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) + config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) + config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) +}