-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uallo values to get over uint64 (eg minStake) (#107)
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ v ✰ Thanks for creating a PR! You're awesome! ✰ v Please note that maintainers will only review those PRs with a completed PR template. ☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --> ## Purpose of Changes and their Description Fix to use `cosmosSdk.Int` (ie `big.Int`) on uallo amounts. This allows reputers to stake higher amounts than those covered by `uint64`. Config changes type since this needs to specify such amounts as `string` in the json. ## Are these changes tested and documented? - [x] If tested, please describe how. If not, why tests are not needed. -- Tested locally - [x] If documented, please describe where. If not, describe why docs are not needed. -- Modified README accordingly - [x] Added to `Unreleased` section of `CHANGELOG.md`?
- Loading branch information
Showing
7 changed files
with
93 additions
and
36 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,5 +1,51 @@ | ||
package lib | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strconv" | ||
|
||
cosmossdk_io_math "cosmossdk.io/math" | ||
) | ||
|
||
type Address = string | ||
type Allo = int64 | ||
type BlockHeight = int64 | ||
|
||
// FlexibleCosmosIntAmount represents amounts of tokens, where the amount can be specified or as a string | ||
type FlexibleCosmosIntAmount struct { | ||
Number cosmossdk_io_math.Int | ||
} | ||
|
||
func (fv *FlexibleCosmosIntAmount) String() string { | ||
return fv.Number.String() | ||
} | ||
|
||
func (fv *FlexibleCosmosIntAmount) UnmarshalJSON(data []byte) error { | ||
// Handle number | ||
if data[0] >= '0' && data[0] <= '9' { | ||
var num json.Number | ||
if err := json.Unmarshal(data, &num); err != nil { | ||
return fmt.Errorf("failed to parse number: %w", err) | ||
} | ||
cosmosInt, ok := cosmossdk_io_math.NewIntFromString(num.String()) | ||
if !ok { | ||
return fmt.Errorf("failed to convert number to cosmosInt: %s", num.String()) | ||
} | ||
fv.Number = cosmosInt | ||
return nil | ||
} | ||
|
||
// Handle string | ||
var str string | ||
if err := json.Unmarshal(data, &str); err == nil { | ||
num, err := strconv.ParseInt(str, 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("failed to convert string to number: %w", err) | ||
} | ||
fv.Number = cosmossdk_io_math.NewInt(num) | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("invalid value: %s", string(data)) | ||
} |