github.com/status-im/status-go@v1.1.0/services/wallet/bigint/big_int.go (about) 1 package bigint 2 3 import ( 4 "fmt" 5 "math/big" 6 "strings" 7 ) 8 9 type BigInt struct { 10 *big.Int 11 } 12 13 func (b BigInt) MarshalJSON() ([]byte, error) { 14 return []byte("\"" + b.String() + "\""), nil 15 } 16 17 func (b *BigInt) UnmarshalJSON(p []byte) error { 18 if string(p) == "null" { 19 return nil 20 } 21 z := new(big.Int) 22 _, ok := z.SetString(strings.Trim(string(p), "\""), 10) 23 if !ok { 24 return fmt.Errorf("not a valid big integer: %s", string(p)) 25 } 26 b.Int = z 27 return nil 28 }