neo encoding: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.tobytearray?view=netframework-4.7.2
(data *big.Int)
| 34 | |
| 35 | // neo encoding: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.tobytearray?view=netframework-4.7.2 |
| 36 | func BigIntToNeoBytes(data *big.Int) []byte { |
| 37 | bs := data.Bytes() |
| 38 | if len(bs) == 0 { |
| 39 | return []byte{} |
| 40 | } |
| 41 | // golang big.Int use big-endian |
| 42 | bytesReverse(bs) |
| 43 | // bs now is little-endian |
| 44 | if data.Sign() < 0 { |
| 45 | for i, b := range bs { |
| 46 | bs[i] = ^b |
| 47 | } |
| 48 | for i := 0; i < len(bs); i++ { |
| 49 | if bs[i] == 255 { |
| 50 | bs[i] = 0 |
| 51 | } else { |
| 52 | bs[i] += 1 |
| 53 | break |
| 54 | } |
| 55 | } |
| 56 | if bs[len(bs)-1] < 128 { |
| 57 | bs = append(bs, 255) |
| 58 | } |
| 59 | } else { |
| 60 | if bs[len(bs)-1] >= 128 { |
| 61 | bs = append(bs, 0) |
| 62 | } |
| 63 | } |
| 64 | return bs |
| 65 | } |
| 66 | |
| 67 | func BigIntFromNeoBytes(ba []byte) *big.Int { |
| 68 | res := big.NewInt(0) |