-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
306 additions
and
37 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 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
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,30 +1,60 @@ | ||
package types | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
) | ||
|
||
// Validate performs basic validation of genesis data returning an error for | ||
// any failed validation criteria. | ||
func (gs *GenesisState) Validate() error { | ||
// Validate all FractionalBalances | ||
if err := gs.Balances.Validate(); err != nil { | ||
return fmt.Errorf("invalid balances: %w", err) | ||
} | ||
|
||
// TODO: | ||
// - Validate remainder amount | ||
// - Validate sum(fractionalBalances) + remainder = whole integer value | ||
// - Cannot validate here: reserve account exists & balance match | ||
if gs.Remainder.IsNil() { | ||
return fmt.Errorf("nil remainder amount") | ||
} | ||
|
||
// Validate remainder, 0 <= remainder <= maxFractionalAmount | ||
if gs.Remainder.IsNegative() { | ||
return fmt.Errorf("negative remainder amount: %s", gs.Remainder) | ||
} | ||
|
||
if gs.Remainder.GT(maxFractionalAmount) { | ||
return fmt.Errorf("remainder exceeds max of %v: %v", maxFractionalAmount, gs.Remainder) | ||
} | ||
|
||
// Determine if sum(fractionalBalances) + remainder = whole integer value | ||
// i.e total of all fractional balances + remainder == 0 fractional digits | ||
sum := gs.Balances.SumAmount() | ||
total := sum.Add(gs.Remainder) | ||
|
||
if !total.Mod(CONVERSION_FACTOR).IsZero() { | ||
return fmt.Errorf( | ||
"sum of fractional balances + remainder is not a whole integer value: %v + %v == %v, but expected to end in 12 zeros", | ||
sum, gs.Remainder, | ||
total, | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NewGenesisState creates a new genesis state. | ||
func NewGenesisState(balances FractionalBalances) *GenesisState { | ||
func NewGenesisState( | ||
balances FractionalBalances, | ||
remainder sdkmath.Int, | ||
) *GenesisState { | ||
return &GenesisState{ | ||
Balances: balances, | ||
Balances: balances, | ||
Remainder: remainder, | ||
} | ||
} | ||
|
||
// DefaultGenesisState returns a default genesis state. | ||
func DefaultGenesisState() *GenesisState { | ||
return NewGenesisState(nil) | ||
return NewGenesisState(nil, sdkmath.ZeroInt()) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.