mobile: added constructor for big int (#21597)

* mobile: added constructor for big int

* mobile: tiny nitpick
This commit is contained in:
Marius van der Wijden 2020-09-28 14:12:08 +02:00 committed by GitHub
parent 420b78659b
commit a90e645ccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,16 @@ func NewBigInt(x int64) *BigInt {
return &BigInt{big.NewInt(x)}
}
// NewBigIntFromString allocates and returns a new BigInt set to x
// interpreted in the provided base.
func NewBigIntFromString(x string, base int) *BigInt {
b, success := new(big.Int).SetString(x, base)
if !success {
return nil
}
return &BigInt{b}
}
// GetBytes returns the absolute value of x as a big-endian byte slice.
func (bi *BigInt) GetBytes() []byte {
return bi.bigint.Bytes()