2020-10-28 17:35:56 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2020-10-31 03:48:15 +00:00
|
|
|
"errors"
|
2020-10-28 17:35:56 +00:00
|
|
|
"math/big"
|
|
|
|
|
|
|
|
big2 "github.com/filecoin-project/go-state-types/big"
|
2020-10-31 03:48:15 +00:00
|
|
|
validation "github.com/go-ozzo/ozzo-validation"
|
2020-10-28 17:35:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var EmptyInt = BigInt{}
|
|
|
|
|
|
|
|
type BigInt = big2.Int
|
|
|
|
|
|
|
|
func NewInt(i uint64) BigInt {
|
|
|
|
return BigInt{Int: big.NewInt(0).SetUint64(i)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BigFromBytes(b []byte) BigInt {
|
|
|
|
i := big.NewInt(0).SetBytes(b)
|
|
|
|
return BigInt{Int: i}
|
|
|
|
}
|
2020-10-31 03:48:15 +00:00
|
|
|
|
|
|
|
func ValidateBigInt(i *big.Int) validation.RuleFunc {
|
|
|
|
return func(value interface{}) error {
|
|
|
|
bigInt := i.IsInt64()
|
|
|
|
if !bigInt {
|
|
|
|
return errors.New("expected big integer")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|