MCPcopy Create free account
hub / github.com/DNAProject/DNA / BigIntToNeoBytes

Function BigIntToNeoBytes

common/bigint.go:36–65  ·  view source on GitHub ↗

neo encoding: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.tobytearray?view=netframework-4.7.2

(data *big.Int)

Source from the content-addressed store, hash-verified

34
35// neo encoding: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.tobytearray?view=netframework-4.7.2
36func 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
67func BigIntFromNeoBytes(ba []byte) *big.Int {
68 res := big.NewInt(0)

Callers 15

PushNumMethod · 0.92
GetProgramInfoFunction · 0.92
EmitPushIntegerMethod · 0.92
TestIntValue_AbsFunction · 0.92
compareFuncBigIntFunction · 0.92
CheckBigIntegerFunction · 0.92
TestIntValFromNeoBytesFunction · 0.92
AsBytesMethod · 0.92
buildParamToNativeMethod · 0.92
SerializeMethod · 0.92
ToNeoBytesMethod · 0.92

Calls 3

bytesReverseFunction · 0.85
SignMethod · 0.80
BytesMethod · 0.45

Tested by 8

TestIntValue_AbsFunction · 0.74
compareFuncBigIntFunction · 0.74
CheckBigIntegerFunction · 0.74
TestIntValFromNeoBytesFunction · 0.74
TestVmValue_AsBoolFunction · 0.74
TestBigIntFromBytesFunction · 0.68
TestBigIntFunction · 0.68
TestRandBigIntFromBytesFunction · 0.68