-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client/v2): *big.Int unmarshal (#21853)
- Loading branch information
1 parent
5fea67d
commit 43c41be
Showing
5 changed files
with
62 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
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,48 @@ | ||
package flag | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/protobuf/reflect/protoreflect" | ||
|
||
"cosmossdk.io/math" | ||
) | ||
|
||
type decType struct{} | ||
|
||
func (a decType) NewValue(_ *context.Context, _ *Builder) Value { | ||
return &decValue{} | ||
} | ||
|
||
func (a decType) DefaultValue() string { | ||
return "0" | ||
} | ||
|
||
type decValue struct { | ||
value string | ||
} | ||
|
||
func (a decValue) Get(protoreflect.Value) (protoreflect.Value, error) { | ||
return protoreflect.ValueOf(a.value), nil | ||
} | ||
|
||
func (a decValue) String() string { | ||
return a.value | ||
} | ||
|
||
func (a *decValue) Set(s string) error { | ||
dec, err := math.LegacyNewDecFromStr(s) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// we need to convert from float representation to non-float representation using default precision | ||
// 0.5 -> 500000000000000000 | ||
a.value = dec.BigInt().String() | ||
|
||
return nil | ||
} | ||
|
||
func (a decValue) Type() string { | ||
return "cosmos.Dec" | ||
} |
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