feat: import ethermint without forking (#378)

* cmd: cleanup

* update gh action

* lint

* more cleanup

* update config

* register denom
This commit is contained in:
Federico Kunze Küllmer 2021-07-28 05:47:29 -04:00 committed by GitHub
parent bc2a2eb8f3
commit 09746c6a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 166 additions and 138 deletions

View File

@ -82,7 +82,7 @@ jobs:
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
filename=$(echo $filename | sed 's/^./github.com\/tharsis\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
@ -121,7 +121,7 @@ jobs:
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
filename=$(echo $filename | sed 's/^./github.com\/tharsis\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
@ -160,7 +160,7 @@ jobs:
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
filename=$(echo $filename | sed 's/^./github.com\/tharsis\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
@ -199,7 +199,7 @@ jobs:
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
filename=$(echo $filename | sed 's/^./github.com\/tharsis\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done

View File

@ -104,11 +104,6 @@ import (
)
func init() {
// set the address prefixes
config := sdk.GetConfig()
ethermint.SetBech32Prefixes(config)
ethermint.SetBip44CoinType(config)
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)

View File

@ -42,29 +42,6 @@ func InitConfig(cmd *cobra.Command) error {
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
}
// GenerateChainID wraps a cobra command with a RunE function with base 10 integer chain-id random generation
// when a chain-id is not provided.
func GenerateChainID(baseCmd *cobra.Command) *cobra.Command {
// Copy base run command to be used after chain verification
baseRunE := baseCmd.RunE
// Function to replace command's RunE function
generateFn := func(cmd *cobra.Command, args []string) error {
chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
if chainID != "" {
if err := cmd.Flags().Set(flags.FlagChainID, ethermint.GenerateRandomChainID()); err != nil {
return fmt.Errorf("could not set random chain-id: %w", err)
}
}
return baseRunE(cmd, args)
}
baseCmd.RunE = generateFn
return baseCmd
}
// ValidateChainID wraps a cobra command with a RunE function with base 10 integer chain-id verification.
func ValidateChainID(baseCmd *cobra.Command) *cobra.Command {
// Copy base run command to be used after chain verification

View File

@ -39,8 +39,8 @@ import (
mintypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/tharsis/ethermint/cmd/ethermintd/config"
"github.com/tharsis/ethermint/crypto/hd"
"github.com/tharsis/ethermint/server/config"
ethermint "github.com/tharsis/ethermint/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)

View File

@ -1,11 +1,9 @@
package types
package config
import (
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
ethaccounts "github.com/ethereum/go-ethereum/accounts"
ethermint "github.com/tharsis/ethermint/types"
)
const (
@ -24,17 +22,11 @@ const (
Bech32PrefixConsAddr = EthBech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = EthBech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
// Bip44CoinType satisfies EIP84. See https://github.com/ethereum/EIPs/issues/84 for more info.
Bip44CoinType = 60
)
var (
// BIP44HDPath is the BIP44 HD path used on Ethereum.
BIP44HDPath = ethaccounts.DefaultBaseDerivationPath.String()
// PowerReduction defines the default power reduction value for staking
PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
const (
// DisplayDenom defines the denomination displayed to users in client applications.
DisplayDenom = "photon"
)
// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
@ -46,6 +38,18 @@ func SetBech32Prefixes(config *sdk.Config) {
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
func SetBip44CoinType(config *sdk.Config) {
config.SetCoinType(Bip44CoinType)
config.SetFullFundraiserPath(BIP44HDPath)
config.SetCoinType(ethermint.Bip44CoinType)
config.SetPurpose(sdk.Purpose) // Shared
config.SetFullFundraiserPath(ethermint.BIP44HDPath) // nolint: staticcheck
}
// 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(ethermint.AttoPhoton, sdk.NewDecWithPrec(1, ethermint.BaseDenomUnit)); err != nil {
panic(err)
}
}

View File

@ -1,9 +1,10 @@
package types
package config
import (
"testing"
"github.com/stretchr/testify/require"
ethermint "github.com/tharsis/ethermint/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -41,14 +42,14 @@ func TestSetCoinType(t *testing.T) {
require.Equal(t, sdk.FullFundraiserPath, config.GetFullFundraiserPath())
SetBip44CoinType(config)
require.Equal(t, Bip44CoinType, int(config.GetCoinType()))
require.Equal(t, int(ethermint.Bip44CoinType), int(config.GetCoinType()))
require.Equal(t, sdk.GetConfig().GetCoinType(), config.GetCoinType())
require.Equal(t, sdk.GetConfig().GetFullFundraiserPath(), config.GetFullFundraiserPath())
}
func TestHDPath(t *testing.T) {
params := *hd.NewFundraiserParams(0, Bip44CoinType, 0)
params := *hd.NewFundraiserParams(0, ethermint.Bip44CoinType, 0)
hdPath := params.String()
require.Equal(t, "m/44'/60'/0'/0/0", hdPath)
require.Equal(t, hdPath, BIP44HDPath)
require.Equal(t, hdPath, ethermint.BIP44HDPath)
}

View File

@ -3,10 +3,7 @@ package main
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tharsis/ethermint/version"
)
@ -29,51 +26,3 @@ var (
},
}
)
var (
fromPassphrase string
ethNodeWS string
ethNodeHTTP string
statsdEnabled bool
statsdPrefix string
statsdAddress string
statsdStuckFunc string
evmDebug bool
)
// addTxFlags adds common flags for commands to post tx
func addTxFlags(cmd *cobra.Command) *cobra.Command {
cmd.PersistentFlags().String(flags.FlagChainID, "testnet", "Specify Chain ID for sending Tx")
cmd.PersistentFlags().String(flags.FlagFrom, "", "Name or address of private key with which to sign")
cmd.PersistentFlags().StringVar(&fromPassphrase, "from-passphrase", "12345678", "Passphrase for private key specified with 'from'")
cmd.PersistentFlags().StringVar(&ethNodeWS, "eth-node-ws", "ws://localhost:8546", "WebSocket endpoint for an Ethereum node.")
cmd.PersistentFlags().StringVar(&ethNodeHTTP, "eth-node-http", "http://localhost:8545", "HTTP endpoint for an Ethereum node.")
cmd.PersistentFlags().BoolVar(&statsdEnabled, "statsd-enabled", false, "Enabled StatsD reporting.")
cmd.PersistentFlags().StringVar(&statsdPrefix, "statsd-prefix", "ethermintd", "Specify StatsD compatible metrics prefix.")
cmd.PersistentFlags().StringVar(&statsdAddress, "statsd-address", "localhost:8125", "UDP address of a StatsD compatible metrics aggregator.")
cmd.PersistentFlags().StringVar(&statsdStuckFunc, "statsd-stuck-func", "5m", "Sets a duration to consider a function to be stuck (e.g. in deadlock).")
cmd.PersistentFlags().String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10aphoton")
cmd.PersistentFlags().String(flags.FlagGasPrices, "", "Gas prices to determine the transaction fee (e.g. 10aphoton)")
cmd.PersistentFlags().String(flags.FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
cmd.PersistentFlags().Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ")
cmd.PersistentFlags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block)")
cmd.PersistentFlags().BoolVar(&evmDebug, "evm-debug", false, "Enable EVM debug traces")
cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendFile, "Select keyring's backend")
// --gas can accept integers and "simulate"
// cmd.PersistentFlags().Var(&flags.GasFlagVar, "gas", fmt.Sprintf(
// "gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)",
// flags.GasFlagAuto, flags.DefaultGasLimit,
// ))
// viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
// TODO: we need to handle the errors for these, decide if we should return error upward and handle
// nolint: errcheck
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
// nolint: errcheck
viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend))
// nolint: errcheck
cmd.MarkFlagRequired(flags.FlagChainID)
return cmd
}

View File

@ -11,7 +11,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@ -45,8 +44,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
depCdc := clientCtx.JSONCodec
cdc := depCdc.(codec.Codec)
cdc := clientCtx.Codec
serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
@ -173,7 +171,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
appState[authtypes.ModuleName] = authGenStateBz
bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState)
bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState)
bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)

View File

@ -5,11 +5,16 @@ import (
"github.com/cosmos/cosmos-sdk/server"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tharsis/ethermint/app"
cmdcfg "github.com/tharsis/ethermint/cmd/config"
)
func main() {
setupConfig()
cmdcfg.RegisterDenoms()
rootCmd, _ := NewRootCmd()
if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil {
@ -22,3 +27,11 @@ func main() {
}
}
}
func setupConfig() {
// set the address prefixes
config := sdk.GetConfig()
cmdcfg.SetBech32Prefixes(config)
cmdcfg.SetBip44CoinType(config)
config.Seal()
}

View File

@ -34,10 +34,11 @@ import (
"github.com/tharsis/ethermint/app"
ethermintclient "github.com/tharsis/ethermint/client"
ethermintconfig "github.com/tharsis/ethermint/cmd/ethermintd/config"
"github.com/tharsis/ethermint/crypto/hd"
"github.com/tharsis/ethermint/encoding"
"github.com/tharsis/ethermint/server"
servercfg "github.com/tharsis/ethermint/server/config"
ethermint "github.com/tharsis/ethermint/types"
)
const EnvPrefix = "ETHERMINT"
@ -77,7 +78,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return err
}
customAppTemplate, customAppConfig := ethermintconfig.AppConfig()
customAppTemplate, customAppConfig := servercfg.AppConfig(ethermint.AttoPhoton)
return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig)
},
@ -114,7 +115,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
txCommand(),
ethermintclient.KeyCommands(app.DefaultNodeHome),
)
rootCmd = addTxFlags(rootCmd)
rootCmd = server.AddTxFlags(rootCmd)
// add rosetta
rootCmd.AddCommand(sdkserver.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))

View File

@ -27,15 +27,25 @@ import (
// PrivateAccountAPI is the personal_ prefixed set of APIs in the Web3 JSON-RPC spec.
type PrivateAccountAPI struct {
ethAPI *eth.PublicAPI
logger log.Logger
ethAPI *eth.PublicAPI
logger log.Logger
hdPathIter ethermint.HDPathIterator
}
// NewAPI creates an instance of the public Personal Eth API.
func NewAPI(logger log.Logger, ethAPI *eth.PublicAPI) *PrivateAccountAPI {
cfg := sdk.GetConfig()
basePath := cfg.GetFullFundraiserPath()
iterator, err := ethermint.NewHDPathIterator(basePath, true)
if err != nil {
panic(err)
}
return &PrivateAccountAPI{
ethAPI: ethAPI,
logger: logger.With("api", "personal"),
ethAPI: ethAPI,
logger: logger.With("api", "personal"),
hdPathIter: iterator,
}
}
@ -109,14 +119,16 @@ func (api *PrivateAccountAPI) NewAccount(password string) (common.Address, error
name := "key_" + time.Now().UTC().Format(time.RFC3339)
// create the mnemonic and save the account
info, _, err := api.ethAPI.ClientCtx().Keyring.NewMnemonic(name, keyring.English, ethermint.BIP44HDPath, password, hd.EthSecp256k1)
hdPath := api.hdPathIter()
info, _, err := api.ethAPI.ClientCtx().Keyring.NewMnemonic(name, keyring.English, hdPath.String(), password, hd.EthSecp256k1)
if err != nil {
return common.Address{}, err
}
addr := common.BytesToAddress(info.GetPubKey().Address().Bytes())
api.logger.Info("Your new key was generated", "address", addr.String())
api.logger.Info("Please backup your key file!", "path", os.Getenv("HOME")+"/.ethermint/"+name)
api.logger.Info("Please backup your key file!", "path", os.Getenv("HOME")+"/.ethermint/"+name) // TODO: pass the correct binary
api.logger.Info("Please remember your password!")
return addr, nil
}

View File

@ -3,8 +3,6 @@ package config
import (
"github.com/cosmos/cosmos-sdk/server/config"
"github.com/spf13/viper"
ethermint "github.com/tharsis/ethermint/types"
)
const (
@ -25,7 +23,7 @@ func GetDefaultAPINamespaces() []string {
// AppConfig helps to override default appConfig template and configs.
// return "", nil if no custom configuration is required for the application.
func AppConfig() (string, interface{}) {
func AppConfig(denom string) (string, interface{}) {
// Optionally allow the chain developer to overwrite the SDK's default
// server config.
srvCfg := config.DefaultConfig()
@ -42,7 +40,9 @@ func AppConfig() (string, interface{}) {
// own app.toml to override, or use this default value.
//
// In ethermint, we set the min gas prices to 0.
srvCfg.MinGasPrices = "0" + ethermint.AttoPhoton
if denom != "" {
srvCfg.MinGasPrices = "0" + denom
}
customAppConfig := Config{
Config: *srvCfg,
@ -79,10 +79,11 @@ type EVMRPCConfig struct {
// DefaultEVMConfig returns an EVM config with the JSON-RPC API enabled by default
func DefaultEVMConfig() *EVMRPCConfig {
return &EVMRPCConfig{
Enable: true,
API: GetDefaultAPINamespaces(),
RPCAddress: DefaultEVMAddress,
WsAddress: DefaultEVMWSAddress,
Enable: true,
API: GetDefaultAPINamespaces(),
RPCAddress: DefaultEVMAddress,
WsAddress: DefaultEVMWSAddress,
EnableUnsafeCORS: false,
}
}
@ -96,16 +97,16 @@ type Config struct {
// GetConfig returns a fully parsed Config object.
func GetConfig(v *viper.Viper) Config {
cfg := config.GetConfig(v)
return Config{
Config: cfg,
EVMRPC: EVMRPCConfig{
Enable: v.GetBool("evm-rpc.enable"),
API: v.GetStringSlice("evm-rpc.api"),
RPCAddress: v.GetString("evm-rpc.address"),
WsAddress: v.GetString("evm-rpc.ws-address"),
Enable: v.GetBool("evm-rpc.enable"),
API: v.GetStringSlice("evm-rpc.api"),
RPCAddress: v.GetString("evm-rpc.address"),
WsAddress: v.GetString("evm-rpc.ws-address"),
EnableUnsafeCORS: v.GetBool("evm-rpc.enable-unsafe-cors"),
},
}
}

View File

@ -16,4 +16,10 @@ address = "{{ .EVMRPC.RPCAddress }}"
# Address defines the EVM WebSocket server address to bind to.
ws-address = "{{ .EVMRPC.WsAddress }}"
# API defines a list of JSON-RPC namespaces that should be enabled
api = "{{ .EVMRPC.API }}"
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
enable-unsafe-cors = "{{ .EVMRPC.EnableUnsafeCORS }}"
`

View File

@ -12,8 +12,9 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/types"
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/tharsis/ethermint/cmd/ethermintd/config"
"github.com/tharsis/ethermint/ethereum/rpc"
"github.com/tharsis/ethermint/server/config"
)
// StartEVMRPC start evm rpc server

37
server/flags.go Normal file
View File

@ -0,0 +1,37 @@
package server
import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// AddTxFlags adds common flags for commands to post tx
func AddTxFlags(cmd *cobra.Command) *cobra.Command {
cmd.PersistentFlags().String(flags.FlagChainID, "testnet", "Specify Chain ID for sending Tx")
cmd.PersistentFlags().String(flags.FlagFrom, "", "Name or address of private key with which to sign")
cmd.PersistentFlags().String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10aphoton")
cmd.PersistentFlags().String(flags.FlagGasPrices, "", "Gas prices to determine the transaction fee (e.g. 10aphoton)")
cmd.PersistentFlags().String(flags.FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
cmd.PersistentFlags().Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ")
cmd.PersistentFlags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block)")
cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendFile, "Select keyring's backend")
// --gas can accept integers and "simulate"
// cmd.PersistentFlags().Var(&flags.GasFlagVar, "gas", fmt.Sprintf(
// "gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)",
// flags.GasFlagAuto, flags.DefaultGasLimit,
// ))
// viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
// TODO: we need to handle the errors for these, decide if we should return error upward and handle
// nolint: errcheck
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
// nolint: errcheck
viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend))
// nolint: errcheck
cmd.MarkFlagRequired(flags.FlagChainID)
return cmd
}

View File

@ -40,8 +40,8 @@ import (
ethlog "github.com/ethereum/go-ethereum/log"
"github.com/tharsis/ethermint/cmd/ethermintd/config"
ethdebug "github.com/tharsis/ethermint/ethereum/rpc/namespaces/debug"
"github.com/tharsis/ethermint/server/config"
)
// Tendermint full-node start flags

View File

@ -50,9 +50,9 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/tharsis/ethermint/app"
srvconfig "github.com/tharsis/ethermint/cmd/ethermintd/config"
"github.com/tharsis/ethermint/crypto/hd"
"github.com/tharsis/ethermint/encoding"
srvconfig "github.com/tharsis/ethermint/server/config"
ethermint "github.com/tharsis/ethermint/types"
)

View File

@ -7,7 +7,6 @@ import (
"strings"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
var (
@ -47,8 +46,3 @@ func ParseChainID(chainID string) (*big.Int, error) {
return chainIDInt, nil
}
// GenerateRandomChainID returns a random chain-id in the valid format.
func GenerateRandomChainID() string {
return fmt.Sprintf("ethermint-%d", 10+tmrand.Intn(10000))
}

View File

@ -1,6 +1,8 @@
package types
import (
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -19,6 +21,11 @@ const (
BaseDenomUnit = 18
)
var (
// PowerReduction defines the default power reduction value for staking
PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(BaseDenomUnit), nil))
)
// NewPhotonCoin is a utility function that returns an "aphoton" coin with the given sdk.Int amount.
// The function will panic if the provided amount is negative.
func NewPhotonCoin(amount sdk.Int) sdk.Coin {

32
types/hdpath.go Normal file
View File

@ -0,0 +1,32 @@
package types
import (
ethaccounts "github.com/ethereum/go-ethereum/accounts"
)
var (
// Bip44CoinType satisfies EIP84. See https://github.com/ethereum/EIPs/issues/84 for more info.
Bip44CoinType uint32 = 60
// BIP44HDPath is the default BIP44 HD path used on Ethereum.
BIP44HDPath = ethaccounts.DefaultBaseDerivationPath.String()
)
type (
HDPathIterator func() ethaccounts.DerivationPath
)
// HDPathIterator receives a base path as a string and a boolean for the desired iterator type and
// returns a function that iterates over the base HD path, returning the string.
func NewHDPathIterator(basePath string, ledgerIter bool) (HDPathIterator, error) {
hdPath, err := ethaccounts.ParseDerivationPath(basePath)
if err != nil {
return nil, err
}
if ledgerIter {
return ethaccounts.LedgerLiveIterator(hdPath), nil
}
return ethaccounts.DefaultIterator(hdPath), nil
}