-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 170210 <j170210@icloud.com>
- Loading branch information
Showing
10 changed files
with
56 additions
and
39 deletions.
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
const ( | ||
DefaultOldCoins string = "cony" | ||
) | ||
|
||
var ( | ||
DefaultSwapRate = sdk.NewDecWithPrec(148079656, 6) | ||
) | ||
|
||
// InitGenesis initializes the capability module's state from a provided genesis | ||
// state. | ||
func (k Keeper) InitGenesis(ctx sdk.Context, bk types.BankKeeper, genState types.GenesisState) error { | ||
if err := k.SetParams(ctx, genState.Params); err != nil { | ||
return err | ||
} | ||
if err := k.SetSwapped(ctx, genState.Swapped); err != nil { | ||
return err | ||
} | ||
totalOldCoinsSupply := bk.GetSupply(ctx, DefaultOldCoins).Amount | ||
totalNewCoinsSupply := DefaultSwapRate.MulInt(totalOldCoinsSupply) | ||
totalNewCoins := sdk.NewDecCoinFromDec(genState.Params.NewCoinDenom, totalNewCoinsSupply) | ||
if err := k.SetTotalSupply(ctx, totalNewCoins); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// ExportGenesis returns the capability module's exported genesis. | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
return &types.GenesisState{ | ||
Params: k.GetParams(ctx), | ||
Swapped: k.GetSwapped(ctx), | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
package keeper_test |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package types | ||
|
||
import ( | ||
// this line is used by starport scaffolding # genesis/types/import | ||
) | ||
|
||
// DefaultIndex is the default capability global index | ||
const DefaultIndex uint64 = 1 | ||
|
||
// DefaultGenesis returns the default Capability genesis state | ||
func DefaultGenesis() *GenesisState { | ||
return &GenesisState{ | ||
// this line is used by starport scaffolding # genesis/types/default | ||
Params: DefaultParams(), | ||
Params: DefaultParams(), | ||
Swapped: DefaultSwapped(), | ||
} | ||
} | ||
|
||
// Validate performs basic genesis state validation returning an error upon any | ||
// failure. | ||
func (gs GenesisState) Validate() error { | ||
// this line is used by starport scaffolding # genesis/types/validate | ||
if err := gs.Params.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
if err := gs.Swapped.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
return gs.Params.Validate() | ||
return nil | ||
} |