Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
target-branch: "main"
schedule:
interval: monthly
open-pull-requests-limit: 20
pull-request-branch-name:
separator: "-"
reviewers:
- "Ethernal-Tech/blade-devs"
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: "1.18.1"
go-version: "1.21.6"
- name: "Setup"
run: ./scripts/setup-ci.sh
- name: "Setup geth"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: '1.18.1'
go-version: '1.21.6'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
16 changes: 11 additions & 5 deletions abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ import (
"strings"
"sync"

"github.com/umbracle/ethgo"
"github.com/Ethernal-Tech/ethgo"
"golang.org/x/crypto/sha3"
)

// ABIEncoder declares functions that are encoding and decoding data to/from ABI format
type ABIEncoder interface {
// EncodeAbi contains logic for encoding arbitrary data into ABI format
EncodeAbi() ([]byte, error)
// DecodeAbi contains logic for decoding given ABI data
DecodeAbi(b []byte) error
}

// ABI represents the ethereum abi format
type ABI struct {
Constructor *Method
Expand All @@ -24,13 +32,11 @@ type ABI struct {
}

func (a *ABI) GetMethod(name string) *Method {
m := a.Methods[name]
return m
return a.Methods[name]
}

func (a *ABI) GetMethodBySignature(methodSignature string) *Method {
m := a.MethodsBySignature[methodSignature]
return m
return a.MethodsBySignature[methodSignature]
}

func (a *ABI) addError(e *Error) {
Expand Down
56 changes: 32 additions & 24 deletions abi/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import (
"reflect"
"strconv"

"github.com/Ethernal-Tech/ethgo"
"github.com/mitchellh/mapstructure"
"github.com/umbracle/ethgo"
)

const (
storageSlotSize = 32
)

// Decode decodes the input with a given type
Expand All @@ -20,6 +24,11 @@ func Decode(t *Type, input []byte) (interface{}, error) {
return val, err
}

// DecodeWithCustomEncoder decodes the raw byte array into ABIEncoder implementation
func DecodeWithCustomEncoder(rawValues []byte, encoder ABIEncoder) error {
return encoder.DecodeAbi(rawValues)
}

// DecodeStruct decodes the input with a type to a struct
func DecodeStruct(t *Type, input []byte, out interface{}) error {
val, err := Decode(t, input)
Expand All @@ -36,19 +45,18 @@ func DecodeStruct(t *Type, input []byte, out interface{}) error {
if err != nil {
return err
}
if err = ms.Decode(val); err != nil {
return err
}
return nil
return ms.Decode(val)
}

func decode(t *Type, input []byte) (interface{}, []byte, error) {
var data []byte
var length int
var err error
var (
data []byte
length int
err error
)

// safe check, input should be at least 32 bytes
if len(input) < 32 {
if len(input) < storageSlotSize {
return nil, nil, fmt.Errorf("incorrect length")
}

Expand All @@ -58,7 +66,7 @@ func decode(t *Type, input []byte) (interface{}, []byte, error) {
return nil, nil, err
}
} else {
data = input[:32]
data = input[:storageSlotSize]
}

switch t.kind {
Expand All @@ -81,10 +89,10 @@ func decode(t *Type, input []byte) (interface{}, []byte, error) {
val = readInteger(t, data)

case KindString:
val = string(input[32 : 32+length])
val = string(input[storageSlotSize : storageSlotSize+length])

case KindBytes:
val = input[32 : 32+length]
val = input[storageSlotSize : storageSlotSize+length]

case KindAddress:
val, err = readAddr(data)
Expand All @@ -93,13 +101,13 @@ func decode(t *Type, input []byte) (interface{}, []byte, error) {
val, err = readFixedBytes(t, data)

case KindFunction:
val, err = readFunctionType(t, data)
val, err = readFunctionType(data)

default:
return nil, nil, fmt.Errorf("decoding not available for type '%s'", t.kind)
}

return val, input[32:], err
return val, input[storageSlotSize:], err
}

var (
Expand All @@ -113,7 +121,7 @@ var (

func readAddr(b []byte) (ethgo.Address, error) {
res := ethgo.Address{}
if len(b) != 32 {
if len(b) != storageSlotSize {
return res, fmt.Errorf("len is not correct")
}
copy(res[:], b[12:])
Expand Down Expand Up @@ -161,7 +169,7 @@ func readInteger(t *Type, b []byte) interface{} {
}
}

func readFunctionType(t *Type, word []byte) ([24]byte, error) {
func readFunctionType(word []byte) ([24]byte, error) {
res := [24]byte{}
if !allZeros(word[24:32]) {
return res, fmt.Errorf("function type expects the last 8 bytes to be empty but found: %b", word[24:32])
Expand All @@ -182,7 +190,7 @@ func decodeTuple(t *Type, data []byte) (interface{}, []byte, error) {
orig := data
origLen := len(orig)
for indx, arg := range t.tuple {
if len(data) < 32 {
if len(data) < storageSlotSize {
return nil, nil, fmt.Errorf("incorrect length")
}

Expand All @@ -203,7 +211,7 @@ func decodeTuple(t *Type, data []byte) (interface{}, []byte, error) {
if !arg.Elem.isDynamicType() {
data = tail
} else {
data = data[32:]
data = data[storageSlotSize:]
}

name := arg.Name
Expand All @@ -223,7 +231,7 @@ func decodeArraySlice(t *Type, data []byte, size int) (interface{}, []byte, erro
if size < 0 {
return nil, nil, fmt.Errorf("size is lower than zero")
}
if 32*size > len(data) {
if storageSlotSize*size > len(data) {
return nil, nil, fmt.Errorf("size is too big")
}

Expand All @@ -239,7 +247,7 @@ func decodeArraySlice(t *Type, data []byte, size int) (interface{}, []byte, erro
for indx := 0; indx < size; indx++ {
isDynamic := t.elem.isDynamicType()

if len(data) < 32 {
if len(data) < storageSlotSize {
return nil, nil, fmt.Errorf("incorrect length")
}

Expand All @@ -260,7 +268,7 @@ func decodeArraySlice(t *Type, data []byte, size int) (interface{}, []byte, erro
if !isDynamic {
data = tail
} else {
data = data[32:]
data = data[storageSlotSize:]
}
res.Index(indx).Set(reflect.ValueOf(val))
}
Expand All @@ -279,7 +287,7 @@ func decodeBool(data []byte) (interface{}, error) {
}

func readOffset(data []byte, len int) (int, error) {
offsetBig := big.NewInt(0).SetBytes(data[0:32])
offsetBig := big.NewInt(0).SetBytes(data[0:storageSlotSize])
if offsetBig.BitLen() > 63 {
return 0, fmt.Errorf("offset larger than int64: %v", offsetBig.Int64())
}
Expand All @@ -291,15 +299,15 @@ func readOffset(data []byte, len int) (int, error) {
}

func readLength(data []byte) (int, error) {
lengthBig := big.NewInt(0).SetBytes(data[0:32])
lengthBig := big.NewInt(0).SetBytes(data[0:storageSlotSize])
if lengthBig.BitLen() > 63 {
return 0, fmt.Errorf("length larger than int64: %v", lengthBig.Int64())
}
length := int(lengthBig.Uint64())

// if we trim the length in the data there should be enough
// bytes to cover the length
if length > len(data)-32 {
if length > len(data)-storageSlotSize {
return 0, fmt.Errorf("length insufficient %v require %v", len(data), length)
}
return length, nil
Expand Down
2 changes: 1 addition & 1 deletion abi/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/umbracle/ethgo"
"github.com/Ethernal-Tech/ethgo"
)

var (
Expand Down
15 changes: 9 additions & 6 deletions abi/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"testing"
"time"

"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/compiler"
"github.com/umbracle/ethgo/testutil"
"github.com/Ethernal-Tech/ethgo"
"github.com/Ethernal-Tech/ethgo/compiler"
"github.com/Ethernal-Tech/ethgo/testutil"
)

func mustDecodeHex(str string) []byte {
Expand Down Expand Up @@ -317,7 +317,8 @@ func TestEncoding(t *testing.T) {
server := testutil.NewTestServer(t)

for _, c := range cases {
t.Run("", func(t *testing.T) {
c := c
t.Run(c.Type, func(t *testing.T) {
t.Parallel()

tt, err := NewType(c.Type)
Expand Down Expand Up @@ -582,7 +583,7 @@ func testEncodeDecode(t *testing.T, server *testutil.TestServer, tt *Type, input
return nil
}

func generateRandomArgs(n int) *Type {
func generateRandomArgs() *Type {
inputs := []*TupleElem{}
for i := 0; i < randomInt(1, 10); i++ {
ttt, err := NewType(randomType())
Expand Down Expand Up @@ -615,7 +616,7 @@ func TestRandomEncoding(t *testing.T) {
t.Run("", func(t *testing.T) {
t.Parallel()

tt := generateRandomArgs(randomInt(1, 4))
tt := generateRandomArgs()
input := generateRandomType(tt)

if err := testEncodeDecode(t, server, tt, input); err != nil {
Expand Down Expand Up @@ -651,6 +652,8 @@ func testDecodePanic(tt *Type, input interface{}) error {
}

func testTypeWithContract(t *testing.T, server *testutil.TestServer, typ *Type) error {
t.Helper()

g := &generateContractImpl{}
source := g.run(typ)

Expand Down
2 changes: 1 addition & 1 deletion abi/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"strings"

"github.com/umbracle/ethgo"
"github.com/Ethernal-Tech/ethgo"
)

func randomInt(min, max int) int {
Expand Down
6 changes: 3 additions & 3 deletions abi/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"reflect"

"github.com/umbracle/ethgo"
"github.com/Ethernal-Tech/ethgo"
)

// ParseLog parses an event log
Expand Down Expand Up @@ -109,7 +109,7 @@ func encodeTopic(t *Type, val reflect.Value) (ethgo.Hash, error) {
return encodeTopicBool(val)

case KindUInt, KindInt:
return encodeTopicNum(t, val)
return encodeTopicNum(val)

case KindAddress:
return encodeTopicAddress(val)
Expand All @@ -134,7 +134,7 @@ func encodeTopicAddress(val reflect.Value) (res ethgo.Hash, err error) {
return
}

func encodeTopicNum(t *Type, val reflect.Value) (res ethgo.Hash, err error) {
func encodeTopicNum(val reflect.Value) (res ethgo.Hash, err error) {
var b []byte
b, err = encodeNum(val)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions abi/topics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"reflect"
"testing"

"github.com/Ethernal-Tech/ethgo"
"github.com/Ethernal-Tech/ethgo/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/testutil"
)

func TestTopicEncoding(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/umbracle/ethgo"
"github.com/Ethernal-Tech/ethgo"
)

// batch of predefined reflect types
Expand Down
4 changes: 2 additions & 2 deletions blocktracker/blocktracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sync"
"time"

"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/jsonrpc"
"github.com/Ethernal-Tech/ethgo"
"github.com/Ethernal-Tech/ethgo/jsonrpc"
)

// BlockProvider are the eth1x methods required by the block tracker
Expand Down
Loading
Loading