-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b4d368
commit 687c85c
Showing
4 changed files
with
61 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.