laconicd/types/int.go
Federico Kunze 5a3d514ba0
conflicts
2021-04-17 12:00:07 +02:00

27 lines
614 B
Go

package types
import (
"math/big"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// MarshalBigInt marshals big int into text string for consistent encoding
func MarshalBigInt(i *big.Int) (string, error) {
bz, err := i.MarshalText()
if err != nil {
return "", sdkerrors.Wrap(ErrMarshalBigInt, err.Error())
}
return string(bz), nil
}
// UnmarshalBigInt unmarshals string from *big.Int
func UnmarshalBigInt(s string) (*big.Int, error) {
ret := new(big.Int)
err := ret.UnmarshalText([]byte(s))
if err != nil {
return nil, sdkerrors.Wrap(ErrUnmarshalBigInt, err.Error())
}
return ret, nil
}