-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: refactor code & replace coinConvert with sdk RegisterDenom #2941
Open
dreamer-zq
wants to merge
6
commits into
master
Choose a base branch
from
refactor-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6e8ec3
remove unused code
dreamer-zq 01ebbfc
fix error
dreamer-zq 07e5392
format code
dreamer-zq 009f068
fix error
dreamer-zq da3e0e7
Merge branch 'master' into refactor-code
dreamer-zq 61f8562
Merge branch 'master' into refactor-code
dreamer-zq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/irisnet/irishub/v3/types" | ||
) | ||
import "encoding/json" | ||
|
||
// NewDefaultGenesisState generates the default state for the application. | ||
func NewDefaultGenesisState() types.GenesisState { | ||
encCfg := RegisterEncodingConfig() | ||
return ModuleBasics.DefaultGenesis(encCfg.Marshaler) | ||
} | ||
// GenesisState The genesis state of the blockchain is represented here as a map of raw json | ||
// messages key'd by a identifier string. | ||
// The identifier is used to determine which module genesis information belongs | ||
// to so it may be appropriately routed during init chain. | ||
// Within this application default genesis information is retrieved from | ||
// the ModuleBasicManager which populates json from each BasicModule | ||
// object provided to it during init. | ||
type GenesisState map[string]json.RawMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package types | ||
package params | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,117 @@ | ||
package params | ||
|
||
// Simulation parameter constants | ||
// MUST be loaded before running | ||
import ( | ||
"fmt" | ||
"math/big" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/cometbft/cometbft/crypto" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/evmos/ethermint/ethereum/eip712" | ||
etherminttypes "github.com/evmos/ethermint/types" | ||
|
||
tokentypes "github.com/irisnet/irismod/modules/token/types" | ||
tokenv1 "github.com/irisnet/irismod/modules/token/types/v1" | ||
) | ||
|
||
const ( | ||
StakePerAccount = "stake_per_account" | ||
InitiallyBondedValidators = "initially_bonded_validators" | ||
// AppName is the name of the app | ||
AppName = "IrisApp" | ||
EIP155ChainID = "6688" | ||
) | ||
|
||
var ( | ||
// BaseToken represents the native token | ||
BaseToken tokenv1.Token | ||
// EvmToken represents the EVM token | ||
EvmToken tokenv1.Token | ||
// DefaultNodeHome default home directories for the application daemon | ||
DefaultNodeHome string | ||
) | ||
|
||
func init() { | ||
// set bech32 prefix | ||
ConfigureBech32Prefix() | ||
|
||
// set coin denom regexs | ||
sdk.SetCoinDenomRegex(func() string { | ||
return `[a-zA-Z][a-zA-Z0-9/-]{2,127}` | ||
}) | ||
|
||
BaseToken = tokenv1.Token{ | ||
Symbol: "iris", | ||
Name: "Irishub staking token", | ||
Scale: 6, | ||
MinUnit: "uiris", | ||
InitialSupply: 2000000000, | ||
MaxSupply: 10000000000, | ||
Mintable: true, | ||
Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), | ||
} | ||
|
||
EvmToken = tokenv1.Token{ | ||
Symbol: "eris", | ||
Name: "IRISHub EVM Fee Token", | ||
Scale: 18, | ||
MinUnit: "weris", | ||
InitialSupply: 0, | ||
MaxSupply: 10000000000, | ||
Mintable: true, | ||
Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), | ||
} | ||
sdk.DefaultBondDenom = BaseToken.MinUnit | ||
|
||
if err := sdk.RegisterDenom(BaseToken.Symbol, sdk.OneDec()); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := sdk.RegisterDenom(BaseToken.MinUnit, sdk.NewDecFromIntWithPrec(sdk.OneInt(), int64(BaseToken.Scale))); err != nil { | ||
panic(err) | ||
} | ||
|
||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
DefaultNodeHome = filepath.Join(userHomeDir, ".iris") | ||
owner, err := sdk.AccAddressFromBech32(BaseToken.Owner) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// replace the default token | ||
tokenv1.SetNativeToken( | ||
BaseToken.Symbol, | ||
BaseToken.Name, | ||
BaseToken.MinUnit, | ||
BaseToken.Scale, | ||
BaseToken.InitialSupply, | ||
BaseToken.MaxSupply, | ||
BaseToken.Mintable, | ||
owner, | ||
) | ||
|
||
etherminttypes.InjectChainIDParser(parseChainID) | ||
} | ||
|
||
// InjectCodec injects an app codec | ||
func InjectCodec(legacyAmino *codec.LegacyAmino, interfaceRegistry types.InterfaceRegistry) { | ||
eip712.InjectCodec(eip712.Codec{ | ||
InterfaceRegistry: interfaceRegistry, | ||
Amino: legacyAmino, | ||
}) | ||
} | ||
|
||
func parseChainID(_ string) (*big.Int, error) { | ||
eip155ChainID, ok := new(big.Int).SetString(EIP155ChainID, 10) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid chain-id: %s", EIP155ChainID) | ||
} | ||
return eip155ChainID, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extensive additions in
params.go
introduce crucial configurations and utility functions. Ensure these are covered by unit tests.Would you like me to help in writing unit tests for these new functions?
Also applies to: 28-34, 37-101, 103-117