-
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 <[email protected]>
- Loading branch information
Showing
5 changed files
with
177 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
// GetSwapped get all parameters as types.Swapped | ||
func (k Keeper) GetSwapped(ctx sdk.Context) types.Swapped { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get([]byte{types.SwappedKey}) | ||
var swapped types.Swapped | ||
//todo | ||
if bz == nil { | ||
panic(types.ErrParamsNotFound) | ||
} | ||
k.cdc.MustUnmarshal(bz, &swapped) | ||
return swapped | ||
} | ||
|
||
// SetSwapped set the types.Swapped | ||
func (k Keeper) SetSwapped(ctx sdk.Context, swapped types.Swapped) error { | ||
store := ctx.KVStore(k.storeKey) | ||
bz, err := k.cdc.Marshal(&swapped) | ||
if err != nil { | ||
return err | ||
} | ||
store.Set([]byte{types.SwappedKey}, bz) | ||
return nil | ||
} | ||
|
||
func (k Keeper) GetTotalSupply(ctx sdk.Context) sdk.DecCoin { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get([]byte{types.TotalSupplyKey}) | ||
var totalSupply sdk.DecCoin | ||
if bz == nil { | ||
//todo | ||
panic(types.ErrParamsNotFound) | ||
} | ||
k.cdc.MustUnmarshal(bz, &totalSupply) | ||
return totalSupply | ||
} | ||
|
||
func (k Keeper) SetTotalSupply(ctx sdk.Context, totalSupply sdk.DecCoin) error { | ||
store := ctx.KVStore(k.storeKey) | ||
bz, err := k.cdc.Marshal(&totalSupply) | ||
if err != nil { | ||
return err | ||
} | ||
store.Set([]byte{types.TotalSupplyKey}, bz) | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package types | ||
|
||
import ( | ||
"errors" | ||
fmt "fmt" | ||
"strings" | ||
|
||
sdk "github.com/Finschia/finschia-sdk/types" | ||
) | ||
|
||
// NewSwapped creates a new Swapped instance | ||
func NewSwapped( | ||
oldCoin sdk.Coin, | ||
newCoin sdk.Coin, | ||
) Swapped { | ||
return Swapped{ | ||
OldCoinAmount: oldCoin, | ||
NewCoinAmount: newCoin, | ||
} | ||
} | ||
|
||
// DefaultSwapped returns an initial Swapped object | ||
func DefaultSwapped() Swapped { | ||
return NewSwapped( | ||
sdk.NewCoin("cony", sdk.NewInt(0)), | ||
sdk.NewCoin(DefaultNewCoinDenom, sdk.NewInt(0)), | ||
) | ||
} | ||
|
||
func validateCoin(i interface{}) error { | ||
v, ok := i.(sdk.Coin) | ||
if !ok { | ||
return fmt.Errorf("invalid coin amount: %T", i) | ||
} | ||
|
||
if strings.TrimSpace(v.Denom) == "" { | ||
return errors.New("denom cannot be blank") | ||
} | ||
if err := sdk.ValidateDenom(v.Denom); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Validate validates the set of swapped | ||
func (s Swapped) Validate() error { | ||
if err := validateCoin(s.OldCoinAmount); err != nil { | ||
return err | ||
} | ||
if err := validateCoin(s.NewCoinAmount); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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