Skip to content

Commit

Permalink
Rename, split.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed May 15, 2024
1 parent 4b4d368 commit 687c85c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 55 deletions.
55 changes: 0 additions & 55 deletions abi/codecForBigInt.go → abi/bigIntValue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,6 @@ import (
twos "github.com/multiversx/mx-components-big-int/twos-complement"
)

// BigUIntValue is a wrapper for a big integer (unsigned)
type BigUIntValue struct {
Value *big.Int
}

func (value *BigUIntValue) encodeNested(writer io.Writer) error {
data := value.Value.Bytes()
dataLength := len(data)

// Write the length of the payload
err := encodeLength(writer, uint32(dataLength))
if err != nil {
return err
}

// Write the payload
_, err = writer.Write(data)
if err != nil {
return err
}

return nil
}

func (value *BigUIntValue) encodeTopLevel(writer io.Writer) error {
data := value.Value.Bytes()
_, err := writer.Write(data)
if err != nil {
return err
}

return nil
}

func (value *BigUIntValue) decodeNested(reader io.Reader) error {
// Read the length of the payload
length, err := decodeLength(reader)
if err != nil {
return err
}

// Read the payload
data, err := readBytesExactly(reader, int(length))
if err != nil {
return err
}

value.Value = big.NewInt(0).SetBytes(data)
return nil
}

func (value *BigUIntValue) decodeTopLevel(data []byte) {
value.Value = big.NewInt(0).SetBytes(data)
}

// BigIntValue is a wrapper for a big integer (signed)
type BigIntValue struct {
Value *big.Int
Expand Down
File renamed without changes.
61 changes: 61 additions & 0 deletions abi/bigUIntValue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package abi

import (
"io"
"math/big"
)

// BigUIntValue is a wrapper for a big integer (unsigned)
type BigUIntValue struct {
Value *big.Int
}

func (value *BigUIntValue) encodeNested(writer io.Writer) error {
data := value.Value.Bytes()
dataLength := len(data)

// Write the length of the payload
err := encodeLength(writer, uint32(dataLength))
if err != nil {
return err
}

// Write the payload
_, err = writer.Write(data)
if err != nil {
return err
}

return nil
}

func (value *BigUIntValue) encodeTopLevel(writer io.Writer) error {
data := value.Value.Bytes()
_, err := writer.Write(data)
if err != nil {
return err
}

return nil
}

func (value *BigUIntValue) decodeNested(reader io.Reader) error {
// Read the length of the payload
length, err := decodeLength(reader)
if err != nil {
return err
}

// Read the payload
data, err := readBytesExactly(reader, int(length))
if err != nil {
return err
}

value.Value = big.NewInt(0).SetBytes(data)
return nil
}

func (value *BigUIntValue) decodeTopLevel(data []byte) {
value.Value = big.NewInt(0).SetBytes(data)
}
File renamed without changes.

0 comments on commit 687c85c

Please sign in to comment.