ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.
(s string)
| 76 | // ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. |
| 77 | // Leading zeros are accepted. The empty string parses as zero. |
| 78 | func ParseBig256(s string) (*big.Int, bool) { |
| 79 | if s == "" { |
| 80 | return new(big.Int), true |
| 81 | } |
| 82 | var bigint *big.Int |
| 83 | var ok bool |
| 84 | if len(s) >= 2 && (s[:2] == "0x" || s[:2] == "0X") { |
| 85 | bigint, ok = new(big.Int).SetString(s[2:], 16) |
| 86 | } else { |
| 87 | bigint, ok = new(big.Int).SetString(s, 10) |
| 88 | } |
| 89 | if ok && bigint.BitLen() > 256 { |
| 90 | bigint, ok = nil, false |
| 91 | } |
| 92 | return bigint, ok |
| 93 | } |
| 94 | |
| 95 | // MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid. |
| 96 | func MustParseBig256(s string) *big.Int { |
no outgoing calls
no test coverage detected