Skip to content

Commit

Permalink
[AV-1898] Update [email protected] (#147)
Browse files Browse the repository at this point in the history
* update versions

* Fix updated version

* use bumped ANR branch

* dep from ANR main now

* nits

Co-authored-by: Aaron Buchwald <[email protected]>
Co-authored-by: Felipe Madero <[email protected]>
Co-authored-by: Darioush Jalali <[email protected]>
  • Loading branch information
4 people authored Jul 13, 2022
1 parent 89f613f commit 4db754c
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 387 deletions.
134 changes: 51 additions & 83 deletions cmd/abigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/ava-labs/subnet-evm/accounts/abi"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/internal/flags"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)

var (
Expand All @@ -51,93 +49,74 @@ var (
gitDate = ""

app *cli.App
)

var (
// Flags needed by abigen
abiFlag = cli.StringFlag{
abiFlag = &cli.StringFlag{
Name: "abi",
Usage: "Path to the Ethereum contract ABI json to bind, - for STDIN",
}
binFlag = cli.StringFlag{
binFlag = &cli.StringFlag{
Name: "bin",
Usage: "Path to the Ethereum contract bytecode (generate deploy method)",
}
typeFlag = cli.StringFlag{
typeFlag = &cli.StringFlag{
Name: "type",
Usage: "Struct name for the binding (default = package name)",
}
jsonFlag = cli.StringFlag{
jsonFlag = &cli.StringFlag{
Name: "combined-json",
Usage: "Path to the combined-json file generated by compiler",
}
solFlag = cli.StringFlag{
Name: "sol",
Usage: "Path to the Ethereum contract Solidity source to build and bind",
}
solcFlag = cli.StringFlag{
Name: "solc",
Usage: "Solidity compiler to use if source builds are requested",
Value: "solc",
}
vyFlag = cli.StringFlag{
Name: "vy",
Usage: "Path to the Ethereum contract Vyper source to build and bind",
}
vyperFlag = cli.StringFlag{
Name: "vyper",
Usage: "Vyper compiler to use if source builds are requested",
Value: "vyper",
Usage: "Path to the combined-json file generated by compiler, - for STDIN",
}
excFlag = cli.StringFlag{
excFlag = &cli.StringFlag{
Name: "exc",
Usage: "Comma separated types to exclude from binding",
}
pkgFlag = cli.StringFlag{
pkgFlag = &cli.StringFlag{
Name: "pkg",
Usage: "Package name to generate the binding into",
}
outFlag = cli.StringFlag{
outFlag = &cli.StringFlag{
Name: "out",
Usage: "Output file for the generated binding (default = stdout)",
}
langFlag = cli.StringFlag{
langFlag = &cli.StringFlag{
Name: "lang",
Usage: "Destination language for the bindings (go, java, objc)",
Value: "go",
}
aliasFlag = cli.StringFlag{
aliasFlag = &cli.StringFlag{
Name: "alias",
Usage: "Comma separated aliases for function and event renaming, e.g. original1=alias1, original2=alias2",
}
)

func init() {
app = flags.NewApp(gitCommit, gitDate, "ethereum checkpoint helper tool")
app.Name = "abigen"
app.Flags = []cli.Flag{
abiFlag,
binFlag,
typeFlag,
jsonFlag,
solFlag,
solcFlag,
vyFlag,
vyperFlag,
excFlag,
pkgFlag,
outFlag,
langFlag,
aliasFlag,
}
app.Action = utils.MigrateFlags(abigen)
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
app.Action = abigen
}

func abigen(c *cli.Context) error {
utils.CheckExclusive(c, abiFlag, jsonFlag, solFlag, vyFlag) // Only one source can be selected.
if c.GlobalString(pkgFlag.Name) == "" {
utils.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected.

if c.String(pkgFlag.Name) == "" {
utils.Fatalf("No destination package specified (--pkg)")
}
var lang bind.Lang
switch c.GlobalString(langFlag.Name) {
switch c.String(langFlag.Name) {
case "go":
lang = bind.LangGo
case "java":
Expand All @@ -146,7 +125,7 @@ func abigen(c *cli.Context) error {
lang = bind.LangObjC
utils.Fatalf("Objc binding generation is uncompleted")
default:
utils.Fatalf("Unsupported destination language \"%s\" (--lang)", c.GlobalString(langFlag.Name))
utils.Fatalf("Unsupported destination language \"%s\" (--lang)", c.String(langFlag.Name))
}
// If the entire solidity code was specified, build and bind based on that
var (
Expand All @@ -157,26 +136,26 @@ func abigen(c *cli.Context) error {
libs = make(map[string]string)
aliases = make(map[string]string)
)
if c.GlobalString(abiFlag.Name) != "" {
if c.String(abiFlag.Name) != "" {
// Load up the ABI, optional bytecode and type name from the parameters
var (
abi []byte
err error
)
input := c.GlobalString(abiFlag.Name)
input := c.String(abiFlag.Name)
if input == "-" {
abi, err = ioutil.ReadAll(os.Stdin)
abi, err = io.ReadAll(os.Stdin)
} else {
abi, err = ioutil.ReadFile(input)
abi, err = os.ReadFile(input)
}
if err != nil {
utils.Fatalf("Failed to read input ABI: %v", err)
}
abis = append(abis, string(abi))

var bin []byte
if binFile := c.GlobalString(binFlag.Name); binFile != "" {
if bin, err = ioutil.ReadFile(binFile); err != nil {
if binFile := c.String(binFlag.Name); binFile != "" {
if bin, err = os.ReadFile(binFile); err != nil {
utils.Fatalf("Failed to read input bytecode: %v", err)
}
if strings.Contains(string(bin), "//") {
Expand All @@ -185,47 +164,32 @@ func abigen(c *cli.Context) error {
}
bins = append(bins, string(bin))

kind := c.GlobalString(typeFlag.Name)
kind := c.String(typeFlag.Name)
if kind == "" {
kind = c.GlobalString(pkgFlag.Name)
kind = c.String(pkgFlag.Name)
}
types = append(types, kind)
} else {
// Generate the list of types to exclude from binding
exclude := make(map[string]bool)
for _, kind := range strings.Split(c.GlobalString(excFlag.Name), ",") {
for _, kind := range strings.Split(c.String(excFlag.Name), ",") {
exclude[strings.ToLower(kind)] = true
}
var err error
var contracts map[string]*compiler.Contract

switch {
case c.GlobalIsSet(solFlag.Name):
contracts, err = compiler.CompileSolidity(c.GlobalString(solcFlag.Name), c.GlobalString(solFlag.Name))
if err != nil {
utils.Fatalf("Failed to build Solidity contract: %v", err)
}
case c.GlobalIsSet(vyFlag.Name):
output, err := compiler.CompileVyper(c.GlobalString(vyperFlag.Name), c.GlobalString(vyFlag.Name))
if err != nil {
utils.Fatalf("Failed to build Vyper contract: %v", err)
}
contracts = make(map[string]*compiler.Contract)
for n, contract := range output {
name := n
// Sanitize the combined json names to match the
// format expected by solidity.
if !strings.Contains(n, ":") {
// Remove extra path components
name = abi.ToCamelCase(strings.TrimSuffix(filepath.Base(name), ".vy"))
}
contracts[name] = contract
if c.IsSet(jsonFlag.Name) {
var (
input = c.String(jsonFlag.Name)
jsonOutput []byte
err error
)
if input == "-" {
jsonOutput, err = io.ReadAll(os.Stdin)
} else {
jsonOutput, err = os.ReadFile(input)
}

case c.GlobalIsSet(jsonFlag.Name):
jsonOutput, err := ioutil.ReadFile(c.GlobalString(jsonFlag.Name))
if err != nil {
utils.Fatalf("Failed to read combined-json from compiler: %v", err)
utils.Fatalf("Failed to read combined-json: %v", err)
}
contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "")
if err != nil {
Expand All @@ -247,33 +211,37 @@ func abigen(c *cli.Context) error {
nameParts := strings.Split(name, ":")
types = append(types, nameParts[len(nameParts)-1])

libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36]
// Derive the library placeholder which is a 34 character prefix of the
// hex encoding of the keccak256 hash of the fully qualified library name.
// Note that the fully qualified library name is the path of its source
// file and the library name separated by ":".
libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36] // the first 2 chars are 0x
libs[libPattern] = nameParts[len(nameParts)-1]
}
}
// Extract all aliases from the flags
if c.GlobalIsSet(aliasFlag.Name) {
if c.IsSet(aliasFlag.Name) {
// We support multi-versions for aliasing
// e.g.
// foo=bar,foo2=bar2
// foo:bar,foo2:bar2
re := regexp.MustCompile(`(?:(\w+)[:=](\w+))`)
submatches := re.FindAllStringSubmatch(c.GlobalString(aliasFlag.Name), -1)
submatches := re.FindAllStringSubmatch(c.String(aliasFlag.Name), -1)
for _, match := range submatches {
aliases[match[1]] = match[2]
}
}
// Generate the contract binding
code, err := bind.Bind(types, abis, bins, sigs, c.GlobalString(pkgFlag.Name), lang, libs, aliases)
code, err := bind.Bind(types, abis, bins, sigs, c.String(pkgFlag.Name), lang, libs, aliases)
if err != nil {
utils.Fatalf("Failed to generate ABI binding: %v", err)
}
// Either flush it out to a file or display on the standard output
if !c.GlobalIsSet(outFlag.Name) {
if !c.IsSet(outFlag.Name) {
fmt.Printf("%s\n", code)
return nil
}
if err := ioutil.WriteFile(c.GlobalString(outFlag.Name), []byte(code), 0600); err != nil {
if err := os.WriteFile(c.String(outFlag.Name), []byte(code), 0600); err != nil {
utils.Fatalf("Failed to write ABI binding: %v", err)
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ func (pool *TxPool) checkTxState(from common.Address, tx *types.Transaction) err
}

// If the tx allow list is enabled, return an error if the from address is not allow listed.
if pool.chainconfig.IsTxAllowList(pool.currentHead.Number) {
headTimestamp := big.NewInt(int64(pool.currentHead.Time))
if pool.chainconfig.IsTxAllowList(headTimestamp) {
txAllowListRole := precompile.GetTxAllowListStatus(pool.currentState, from)
if !txAllowListRole.IsEnabled() {
return fmt.Errorf("%w: %s", precompile.ErrSenderAddressNotAllowListed, from)
Expand Down
Loading

0 comments on commit 4db754c

Please sign in to comment.