2019-09-26 15:36:23 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import "math/big"
|
|
|
|
|
|
|
|
// MarshalBigInt marshalls big int into text string for consistent encoding
|
|
|
|
func MarshalBigInt(i *big.Int) string {
|
|
|
|
bz, err := i.MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return string(bz)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalBigInt unmarshalls string from *big.Int
|
|
|
|
func UnmarshalBigInt(s string) (*big.Int, error) {
|
|
|
|
ret := new(big.Int)
|
|
|
|
err := ret.UnmarshalText([]byte(s))
|
|
|
|
return ret, err
|
|
|
|
}
|
2019-10-16 00:46:50 +00:00
|
|
|
|
|
|
|
// MustUnmarshalBigInt unmarshalls string from *big.Int
|
|
|
|
func MustUnmarshalBigInt(s string) *big.Int {
|
|
|
|
ret := new(big.Int)
|
|
|
|
err := ret.UnmarshalText([]byte(s))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|