fix(client/v2): *big.Int unmarshal (#21853)
This commit is contained in:
@@ -53,6 +53,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* [#17709](https://github.com/cosmos/cosmos-sdk/pull/17709) Address codecs have been removed from `autocli.AppOptions` and `flag.Builder`. Instead client/v2 uses the address codecs present in the context (introduced in [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503)).
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [#21853](https://github.com/cosmos/cosmos-sdk/pull/21853) Fix `*big.Int` unmarshalling in txs.
|
||||
|
||||
## [v2.0.0-beta.5] - 2024-09-18
|
||||
|
||||
### Improvements
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString"
|
||||
ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString"
|
||||
PubkeyScalarType = "cosmos.Pubkey"
|
||||
DecScalarType = "cosmos.Dec"
|
||||
)
|
||||
|
||||
// Builder manages options for building pflag flags for protobuf messages.
|
||||
@@ -67,6 +68,7 @@ func (b *Builder) init() {
|
||||
b.scalarFlagTypes[ValidatorAddressStringScalarType] = validatorAddressStringType{}
|
||||
b.scalarFlagTypes[ConsensusAddressStringScalarType] = consensusAddressStringType{}
|
||||
b.scalarFlagTypes[PubkeyScalarType] = pubkeyType{}
|
||||
b.scalarFlagTypes[DecScalarType] = decType{}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user