Skip to content

Commit d3b65bc

Browse files
Merge pull request #73 from keep-network/gemini-sigma
go-ethereum dependency update to v1.10.1
2 parents 3203332 + ebf46d0 commit d3b65bc

10 files changed

Lines changed: 489 additions & 85 deletions

File tree

go.mod

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@ require (
1010
github.com/celo-org/celo-blockchain v0.0.0-20210222234634-f8c8f6744526
1111
github.com/cespare/cp v1.1.1 // indirect
1212
github.com/deckarep/golang-set v1.7.1 // indirect
13-
github.com/edsrzf/mmap-go v1.0.0 // indirect
14-
github.com/ethereum/go-ethereum v1.9.10
15-
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
13+
github.com/ethereum/go-ethereum v1.10.1
1614
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
17-
github.com/gorilla/websocket v1.4.1 // indirect
18-
github.com/hashicorp/golang-lru v0.5.3 // indirect
19-
github.com/huin/goupnp v1.0.0 // indirect
2015
github.com/ipfs/go-log v0.0.1
2116
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
2217
github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect
2318
github.com/olekukonko/tablewriter v0.0.2 // indirect
2419
github.com/pborman/uuid v1.2.0 // indirect
2520
github.com/prometheus/tsdb v0.10.0 // indirect
2621
github.com/rjeczalik/notify v0.9.2 // indirect
27-
github.com/rs/cors v1.7.0 // indirect
2822
github.com/status-im/keycard-go v0.0.0-20191119114148-6dd40a46baa0 // indirect
2923
github.com/tyler-smith/go-bip39 v1.0.2 // indirect
3024
github.com/urfave/cli v1.22.1

go.sum

Lines changed: 403 additions & 17 deletions
Large diffs are not rendered by default.

pkg/chain/celo/celoutil/celoutil.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ package celoutil
22

33
import (
44
"context"
5+
"crypto/ecdsa"
56
"fmt"
7+
"io/ioutil"
8+
"math/big"
9+
"time"
10+
611
"github.com/celo-org/celo-blockchain"
712
"github.com/celo-org/celo-blockchain/accounts/abi"
813
"github.com/celo-org/celo-blockchain/accounts/abi/bind"
914
"github.com/celo-org/celo-blockchain/accounts/keystore"
1015
"github.com/celo-org/celo-blockchain/common"
16+
"github.com/celo-org/celo-blockchain/core/types"
17+
"github.com/celo-org/celo-blockchain/crypto"
1118
celoclient "github.com/celo-org/celo-blockchain/ethclient"
1219
"github.com/celo-org/celo-blockchain/rpc"
1320
"github.com/ipfs/go-log"
1421
"github.com/keep-network/keep-common/pkg/chain/ethlike"
15-
"io/ioutil"
16-
"math/big"
17-
"time"
1822
)
1923

2024
var logger = log.Logger("keep-celoutil")
@@ -227,3 +231,37 @@ func NewNonceManager(
227231
ethlike.Address(account),
228232
)
229233
}
234+
235+
// NewKeyedTransactorWithChainID is a utility method to easily create
236+
// a transaction signer from a single private key.
237+
// FIXME Remove this function and rely on bind.NewKeyedTransactorWithChainID
238+
// FIXME when celo-org/celo-blockchain merges in changes from upstream
239+
// FIXME ethereum/go-ethereum beyond v1.9.25.
240+
func NewKeyedTransactorWithChainID(
241+
key *ecdsa.PrivateKey,
242+
chainID *big.Int,
243+
) (*bind.TransactOpts, error) {
244+
keyAddress := crypto.PubkeyToAddress(key.PublicKey)
245+
if chainID == nil {
246+
return nil, fmt.Errorf("no chain id specified")
247+
}
248+
return &bind.TransactOpts{
249+
From: keyAddress,
250+
Signer: func(
251+
_ types.Signer,
252+
address common.Address,
253+
tx *types.Transaction,
254+
) (*types.Transaction, error) {
255+
signer := types.NewEIP155Signer(chainID)
256+
257+
if address != keyAddress {
258+
return nil, fmt.Errorf("not authorized to sign this account")
259+
}
260+
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
261+
if err != nil {
262+
return nil, err
263+
}
264+
return tx.WithSignature(signer, signature)
265+
},
266+
}, nil
267+
}

pkg/chain/ethereum/ethutil/error_resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// neither encoded strictly as method calls nor strictly as return values, nor
1616
// strictly as events, but some various bits of it are used for unpacking the
1717
// errors. See ResolveError below.
18-
const errorABIString = "[{\"constant\":true,\"outputs\":[{\"type\":\"string\"}],\"inputs\":[{\"name\":\"message\", \"type\":\"string\"}],\"name\":\"Error\"}]"
18+
const errorABIString = "[{\"constant\":true,\"outputs\":[{\"type\":\"string\"}],\"inputs\":[{\"name\":\"message\", \"type\":\"string\"}],\"name\":\"Error\", \"type\": \"function\"}]"
1919

2020
var errorABI abi.ABI
2121

pkg/chain/ethereum/ethutil/error_resolver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717

1818
var testABIMethods = map[string]abi.Method{
1919
"Test": abi.Method{
20-
Const: false,
21-
Name: "Test",
22-
Inputs: []abi.Argument{},
23-
Outputs: []abi.Argument{},
20+
Constant: false,
21+
Name: "Test",
22+
Inputs: []abi.Argument{},
23+
Outputs: []abi.Argument{},
2424
},
2525
}
2626
var testABI = abi.ABI{

pkg/chain/ethereum/ethutil/ethutil.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ package ethutil
44

55
import (
66
"context"
7+
"crypto/ecdsa"
78
"fmt"
8-
"github.com/keep-network/keep-common/pkg/chain/ethlike"
99
"io/ioutil"
1010
"math/big"
1111
"time"
1212

13+
"github.com/keep-network/keep-common/pkg/chain/ethlike"
14+
1315
"github.com/ipfs/go-log"
1416

1517
"github.com/ethereum/go-ethereum"
@@ -140,8 +142,7 @@ func CallAtBlock(
140142
}
141143
}
142144

143-
err = contractABI.Unpack(result, method, output)
144-
145+
err = contractABI.UnpackIntoInterface(result, method, output)
145146
if err != nil {
146147
return errorResolver.ResolveError(
147148
err,
@@ -218,3 +219,12 @@ func NewNonceManager(
218219
ethlike.Address(account),
219220
)
220221
}
222+
223+
// NewKeyedTransactorWithChainID is a utility method to easily create
224+
// a transaction signer from a single private key.
225+
func NewKeyedTransactorWithChainID(
226+
privateKey *ecdsa.PrivateKey,
227+
chainID *big.Int,
228+
) (*bind.TransactOpts, error) {
229+
return bind.NewKeyedTransactorWithChainID(privateKey, chainID)
230+
}

tools/generators/ethlike/contract.go.tmpl

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,15 @@ func New{{.Class}}(
5757
From: accountKey.Address,
5858
}
5959

60-
// FIXME Switch to bind.NewKeyedTransactorWithChainID when go-ethereum dep
61-
// FIXME bumps beyond 1.9.25.
62-
key := accountKey.PrivateKey
63-
keyAddress := crypto.PubkeyToAddress(key.PublicKey)
64-
if chainId == nil {
65-
return nil, fmt.Errorf("no chain id specified")
66-
}
67-
transactorOptions := &bind.TransactOpts{
68-
From: keyAddress,
69-
Signer: func(_ types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
70-
signer := types.NewEIP155Signer(chainId)
71-
72-
if address != keyAddress {
73-
return nil, fmt.Errorf("not authorized to sign this account")
74-
}
75-
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
76-
if err != nil {
77-
return nil, err
78-
}
79-
return tx.WithSignature(signer, signature)
80-
},
60+
// FIXME Switch to bind.NewKeyedTransactorWithChainID when
61+
// FIXME celo-org/celo-blockchain merges in changes from upstream
62+
// FIXME ethereum/go-ethereum beyond v1.9.25.
63+
transactorOptions, err := chainutil.NewKeyedTransactorWithChainID(
64+
accountKey.PrivateKey,
65+
chainId,
66+
)
67+
if err != nil {
68+
return nil, fmt.Errorf("failed to instantiate transactor: [%v]", err)
8169
}
8270

8371
contract, err := abi.New{{.AbiClass}}(

tools/generators/ethlike/contract_parsing.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func buildMethodInfo(
163163
if payable {
164164
modifiers = append(modifiers, "payable")
165165
}
166-
if method.Const {
166+
if method.Constant {
167167
modifiers = append(modifiers, "constant")
168168
}
169169
modifierString := strings.Join(modifiers, " ")
@@ -176,7 +176,7 @@ func buildMethodInfo(
176176
paramInfos := make([]paramInfo, 0, 0)
177177

178178
for index, param := range method.Inputs {
179-
goType := param.Type.Type.String()
179+
goType := param.Type.GetType().String()
180180
paramName := param.Name
181181
if paramName == "" {
182182
paramName = fmt.Sprintf("arg%v", index)
@@ -211,7 +211,7 @@ func buildMethodInfo(
211211
returned.Type = strings.Replace(normalizedName, "get", "", 1)
212212

213213
for _, output := range method.Outputs {
214-
goType := output.Type.Type.String()
214+
goType := output.Type.GetType().String()
215215

216216
returned.Declarations += fmt.Sprintf(
217217
"\t%v %v\n",
@@ -224,7 +224,7 @@ func buildMethodInfo(
224224
returned.Multi = false
225225
} else {
226226
returned.Multi = false
227-
returned.Type = method.Outputs[0].Type.Type.String()
227+
returned.Type = method.Outputs[0].Type.GetType().String()
228228
returned.Vars += "ret,"
229229
}
230230

@@ -241,7 +241,7 @@ func buildMethodInfo(
241241
returned,
242242
}
243243

244-
if method.Const {
244+
if method.Constant {
245245
constMethods = append(constMethods, info)
246246
} else {
247247
nonConstMethods = append(nonConstMethods, info)
@@ -281,7 +281,7 @@ func buildEventInfo(
281281
indexedFilters := ""
282282
for _, param := range event.Inputs {
283283
upperParam := uppercaseFirst(param.Name)
284-
goType := param.Type.Type.String()
284+
goType := param.Type.GetType().String()
285285

286286
paramDeclarations += fmt.Sprintf("%v %v,\n", upperParam, goType)
287287
paramExtractors += fmt.Sprintf("event.%v,\n", upperParam)

tools/generators/ethlike/contract_parsing_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func TestMethodStability(t *testing.T) {
118118
allMethods := make(map[string]abi.Method)
119119
allMethods["boop"] = abi.Method{Name: "boop", RawName: "boop"}
120120
allMethods["boop0"] = abi.Method{Name: "boop0", RawName: "boop"}
121-
allMethods["bap"] = abi.Method{Name: "bap", RawName: "bap", Const: true}
121+
allMethods["bap"] = abi.Method{Name: "bap", RawName: "bap", Constant: true}
122122
allMethods["sap"] = abi.Method{Name: "sap", RawName: "sap"}
123-
allMethods["map"] = abi.Method{Name: "map", RawName: "map", Const: true}
123+
allMethods["map"] = abi.Method{Name: "map", RawName: "map", Constant: true}
124124
allMethods["map0"] = abi.Method{Name: "map0", RawName: "map"}
125125

126126
payableMethods := make(map[string]struct{})

tools/generators/ethlike/contract_template_content.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,15 @@ func New{{.Class}}(
6060
From: accountKey.Address,
6161
}
6262
63-
// FIXME Switch to bind.NewKeyedTransactorWithChainID when go-ethereum dep
64-
// FIXME bumps beyond 1.9.25.
65-
key := accountKey.PrivateKey
66-
keyAddress := crypto.PubkeyToAddress(key.PublicKey)
67-
if chainId == nil {
68-
return nil, fmt.Errorf("no chain id specified")
69-
}
70-
transactorOptions := &bind.TransactOpts{
71-
From: keyAddress,
72-
Signer: func(_ types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
73-
signer := types.NewEIP155Signer(chainId)
74-
75-
if address != keyAddress {
76-
return nil, fmt.Errorf("not authorized to sign this account")
77-
}
78-
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
79-
if err != nil {
80-
return nil, err
81-
}
82-
return tx.WithSignature(signer, signature)
83-
},
63+
// FIXME Switch to bind.NewKeyedTransactorWithChainID when
64+
// FIXME celo-org/celo-blockchain merges in changes from upstream
65+
// FIXME ethereum/go-ethereum beyond v1.9.25.
66+
transactorOptions, err := chainutil.NewKeyedTransactorWithChainID(
67+
accountKey.PrivateKey,
68+
chainId,
69+
)
70+
if err != nil {
71+
return nil, fmt.Errorf("failed to instantiate transactor: [%v]", err)
8472
}
8573
8674
contract, err := abi.New{{.AbiClass}}(

0 commit comments

Comments
 (0)