Skip to content

Commit

Permalink
Rename go-web3 to ethgo (umbracle#158)
Browse files Browse the repository at this point in the history
* Website

* More improvements

* Change stuff

* More docs

* Update docs

* Rename

* Remove node modules

* More stuff

* Remove web3 references

* Rebuild abigen contracts

* Last changes
  • Loading branch information
ferranbt authored Mar 3, 2022
1 parent aaa1038 commit 6f7d16b
Show file tree
Hide file tree
Showing 99 changed files with 8,115 additions and 537 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
bin/
pkg/

.idea
.idea

# website
node_modules
.next
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Go-Web3
# Eth-Go

## JsonRPC

Expand All @@ -9,8 +9,8 @@ package main
import (
"fmt"

web3 "github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/jsonrpc"
)

func main() {
Expand All @@ -24,7 +24,7 @@ func main() {
panic(err)
}

header, err := client.Eth().GetBlockByNumber(web3.BlockNumber(number), true)
header, err := client.Eth().GetBlockByNumber(ethgo.BlockNumber(number), true)
if err != nil {
panic(err)
}
Expand All @@ -40,7 +40,7 @@ The ABI codifier uses randomized tests with e2e integration tests with a real Ge
To use the library import:

```
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/ethgo/abi"
```

Declare basic objects:
Expand Down Expand Up @@ -80,20 +80,20 @@ You can also codify structs as Solidity tuples:
import (
"fmt"

web3 "github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/abi"
"math/big"
)

func main() {
typ := abi.MustNewType("tuple(address a, uint256 b)")

type Obj struct {
A web3.Address
A ethgo.Address
B *big.Int
}
obj := &Obj{
A: web3.Address{0x1},
A: ethgo.Address{0x1},
B: big.NewInt(1),
}

Expand Down Expand Up @@ -128,11 +128,11 @@ As for now the library only provides primitive abstractions to send signed abstr
// Generate a random wallet
key, _ := wallet.GenerateKey()

to := web3.Address{0x1}
to := ethgo.Address{0x1}
transferVal := big.NewInt(1000)

// Create the transaction
txn := &web3.Transaction{
txn := &ethgo.Transaction{
To: &to,
Value: transferVal,
Gas: 100000,
Expand All @@ -155,8 +155,8 @@ Resolve names on the Ethereum Name Service registrar.
import (
"fmt"

"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/go-web3/ens"
"github.com/umbracle/ethgo/jsonrpc"
"github.com/umbracle/ethgo/ens"
)

func main() {
Expand All @@ -183,9 +183,8 @@ func main() {
import (
"fmt"

web3 "github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/go-web3/blocktracker"
"github.com/umbracle/ethgo/jsonrpc"
"github.com/umbracle/ethgo/blocktracker"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"sync"

"github.com/umbracle/go-web3"
"github.com/umbracle/ethgo"
"golang.org/x/crypto/sha3"
)

Expand Down Expand Up @@ -292,7 +292,7 @@ func (e *Event) Sig() string {
}

// ID returns the id of the event used during logs
func (e *Event) ID() (res web3.Hash) {
func (e *Event) ID() (res ethgo.Hash) {
k := acquireKeccak()
k.Write([]byte(e.Sig()))
dst := k.Sum(nil)
Expand Down Expand Up @@ -364,7 +364,7 @@ func NewEventFromType(name string, typ *Type) *Event {
}

// Match checks wheter the log is from this event
func (e *Event) Match(log *web3.Log) bool {
func (e *Event) Match(log *ethgo.Log) bool {
if len(log.Topics) == 0 {
return false
}
Expand All @@ -375,7 +375,7 @@ func (e *Event) Match(log *web3.Log) bool {
}

// ParseLog parses a log with this event
func (e *Event) ParseLog(log *web3.Log) (map[string]interface{}, error) {
func (e *Event) ParseLog(log *ethgo.Log) (map[string]interface{}, error) {
if !e.Match(log) {
return nil, fmt.Errorf("log does not match this event")
}
Expand Down
6 changes: 3 additions & 3 deletions abi/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"

"github.com/mitchellh/mapstructure"
"github.com/umbracle/go-web3"
"github.com/umbracle/ethgo"
)

// Decode decodes the input with a given type
Expand Down Expand Up @@ -101,8 +101,8 @@ var (
big.NewInt(-1))
)

func readAddr(b []byte) (web3.Address, error) {
res := web3.Address{}
func readAddr(b []byte) (ethgo.Address, error) {
res := ethgo.Address{}
if len(b) != 32 {
return res, fmt.Errorf("len is not correct")
}
Expand Down
5 changes: 3 additions & 2 deletions abi/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package abi
import (
"encoding/hex"
"fmt"
"github.com/umbracle/go-web3"
"math/big"
"reflect"
"strconv"
"strings"

"github.com/umbracle/ethgo"
)

var (
Expand Down Expand Up @@ -189,7 +190,7 @@ func encodeAddress(v reflect.Value) ([]byte, error) {
v = convertArrayToBytes(v)
}
if v.Kind() == reflect.String {
var addr web3.Address
var addr ethgo.Address
if err := addr.UnmarshalText([]byte(v.String())); err != nil {
return nil, err
}
Expand Down
32 changes: 16 additions & 16 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/go-web3"
"github.com/umbracle/go-web3/compiler"
"github.com/umbracle/go-web3/testutil"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/compiler"
"github.com/umbracle/ethgo/testutil"
)

func mustDecodeHex(str string) []byte {
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestEncoding(t *testing.T) {
},
{
"address[]",
[]web3.Address{{1}, {2}},
[]ethgo.Address{{1}, {2}},
},
{
"bytes10[]",
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestEncoding(t *testing.T) {
// tuple with array slice
"tuple(address[] a)",
map[string]interface{}{
"a": []web3.Address{
"a": []ethgo.Address{
{0x1},
},
},
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestEncoding(t *testing.T) {

func TestEncodingBestEffort(t *testing.T) {
strAddress := "0xdbb881a51CD4023E4400CEF3ef73046743f08da3"
web3Address := web3.HexToAddress(strAddress)
ethAddress := ethgo.HexToAddress(strAddress)
overflowBigInt, _ := new(big.Int).SetString("50000000000000000000000000000000000000", 10)

cases := []struct {
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestEncodingBestEffort(t *testing.T) {
{
"address[]",
[]interface{}{strAddress, strAddress},
[]web3.Address{web3Address, web3Address},
[]ethgo.Address{ethAddress, ethAddress},
},
{
"uint8[]",
Expand Down Expand Up @@ -422,7 +422,7 @@ func TestEncodingBestEffort(t *testing.T) {
"a": strAddress,
},
map[string]interface{}{
"a": web3Address,
"a": ethAddress,
},
},
{
Expand All @@ -431,7 +431,7 @@ func TestEncodingBestEffort(t *testing.T) {
"a": []interface{}{strAddress, strAddress},
},
map[string]interface{}{
"a": []web3.Address{web3Address, web3Address},
"a": []ethgo.Address{ethAddress, ethAddress},
},
},
{
Expand All @@ -441,7 +441,7 @@ func TestEncodingBestEffort(t *testing.T) {
"b": float64(266),
},
map[string]interface{}{
"a": web3Address,
"a": ethAddress,
"b": int64(266),
},
},
Expand All @@ -452,7 +452,7 @@ func TestEncodingBestEffort(t *testing.T) {
"b": "50000000000000000000000000000000000000",
},
map[string]interface{}{
"a": web3Address,
"a": ethAddress,
"b": overflowBigInt,
},
},
Expand All @@ -463,7 +463,7 @@ func TestEncodingBestEffort(t *testing.T) {
"b": "0x259DA6542D43623D04C5112000000000",
},
map[string]interface{}{
"a": web3Address,
"a": ethAddress,
"b": overflowBigInt,
},
},
Expand Down Expand Up @@ -647,7 +647,7 @@ func testTypeWithContract(t *testing.T, server *testutil.TestServer, typ *Type)
if err != nil {
return err
}
txn := &web3.Transaction{
txn := &ethgo.Transaction{
Input: binBuf,
}
receipt, err := server.SendTxn(txn)
Expand All @@ -668,7 +668,7 @@ func testTypeWithContract(t *testing.T, server *testutil.TestServer, typ *Type)
return err
}

res, err := server.Call(&web3.CallMsg{
res, err := server.Call(&ethgo.CallMsg{
To: &receipt.ContractAddress,
Data: data,
})
Expand All @@ -685,11 +685,11 @@ func TestEncodingStruct(t *testing.T) {
typ := MustNewType("tuple(address a, uint256 b)")

type Obj struct {
A web3.Address
A ethgo.Address
B *big.Int
}
obj := Obj{
A: web3.Address{0x1},
A: ethgo.Address{0x1},
B: big.NewInt(1),
}

Expand Down
4 changes: 2 additions & 2 deletions 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/go-web3"
"github.com/umbracle/ethgo"
)

func randomInt(min, max int) int {
Expand Down Expand Up @@ -113,7 +113,7 @@ func generateRandomType(t *Type) interface{} {
return false

case KindAddress:
buf := web3.Address{}
buf := ethgo.Address{}
rand.Read(buf[:])
return buf

Expand Down
Loading

0 comments on commit 6f7d16b

Please sign in to comment.