Skip to content

Commit

Permalink
Add revert reason to transaction info.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed May 13, 2024
1 parent 85cdbbe commit 2a9f319
Show file tree
Hide file tree
Showing 9 changed files with 614 additions and 163 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func connect(ctx context.Context) error {
return err
}

signer = types.NewLondonSigner(c.ChainID())
signer = types.NewCancunSigner(c.ChainID())

return nil
}
Expand Down
53 changes: 52 additions & 1 deletion cmd/transactioninfo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017-2022 Weald Technology Trading
// Copyright © 2017-2024 Weald Technology Trading
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -22,6 +22,7 @@ import (
"os"
"strings"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -121,8 +122,13 @@ In quiet mode this will return 0 if the transaction exists, otherwise 1.`,
defer cancel()
receipt, err = c.Client().TransactionReceipt(ctx, txHash)
if receipt != nil {
fmt.Printf("Block:\t\t\t%d\n", receipt.BlockNumber)
if receipt.Status == 0 {
fmt.Printf("Result:\t\t\tFailed\n")
revertReason := obtainRevertReason(tx, receipt)
if revertReason != "" {
fmt.Printf("Reason:\t\t\t%s\n", revertReason)
}
} else {
fmt.Printf("Result:\t\t\tSucceeded\n")
}
Expand Down Expand Up @@ -257,6 +263,51 @@ In quiet mode this will return 0 if the transaction exists, otherwise 1.`,
},
}

func obtainRevertReason(tx *types.Transaction, receipt *types.Receipt) string {
// To obtain the revert reason we rerun the transaction as a call.
from, err := types.Sender(types.NewCancunSigner(tx.ChainId()), tx)
if err != nil {
// Failed to obtain sender; not a transaction error.
return ""
}

msg := ethereum.CallMsg{
From: from,
To: tx.To(),
Gas: tx.Gas(),
Value: tx.Value(),
Data: tx.Data(),
}
switch tx.Type() {
case types.LegacyTxType:
msg.GasPrice = tx.GasPrice()
case types.AccessListTxType:
msg.AccessList = tx.AccessList()
case types.DynamicFeeTxType:
msg.GasFeeCap = tx.GasFeeCap()
msg.GasTipCap = tx.GasTipCap()
msg.AccessList = tx.AccessList()
case types.BlobTxType:
msg.GasFeeCap = tx.GasFeeCap()
msg.GasTipCap = tx.GasTipCap()
msg.AccessList = tx.AccessList()
}

_, err = c.Client().CallContract(context.Background(), msg, receipt.BlockNumber)
if err == nil {
// Did not fail.
return ""
}

revertReason := err.Error()
if !strings.Contains(revertReason, "reverted") {
// Did not revert.
return ""
}

return revertReason
}

func init() {
transactionCmd.AddCommand(transactionInfoCmd)
transactionFlags(transactionInfoCmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{
ethereal version.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("2.9.1")
fmt.Println("2.9.2")
if viper.GetBool("verbose") {
buildInfo, ok := dbg.ReadBuildInfo()
if ok {
Expand Down
2 changes: 1 addition & 1 deletion conn/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *Conn) SignTransaction(_ context.Context,
if signer != keyAddr {
return nil, errors.New("not authorized to sign this account")
}
signedTx, err = types.SignTx(tx, types.NewLondonSigner(c.ChainID()), key)
signedTx, err = types.SignTx(tx, types.NewCancunSigner(c.ChainID()), key)
if err != nil {
return nil, err
}
Expand Down
102 changes: 52 additions & 50 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,96 @@ go 1.21

require (
github.com/antlr4-go/antlr/v4 v4.13.0
github.com/attestantio/go-execution-client v0.9.0
github.com/ethereum/go-ethereum v1.13.10
github.com/miekg/dns v1.1.57
github.com/attestantio/go-execution-client v0.9.1
github.com/ethereum/go-ethereum v1.14.3
github.com/miekg/dns v1.1.59
github.com/mitchellh/go-homedir v1.1.0
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/rs/zerolog v1.32.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/wealdtech/go-ens/v3 v3.6.0
github.com/wealdtech/go-erc1820 v1.2.4
github.com/wealdtech/go-string2eth v1.2.1
golang.org/x/crypto v0.21.0
golang.org/x/text v0.14.0
golang.org/x/crypto v0.23.0
golang.org/x/text v0.15.0
)

require (
github.com/DataDog/zstd v1.5.5 // indirect
github.com/DataDog/zstd v1.4.5 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231205143816-408dbffb2041 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.26.0 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/karalabe/usb v0.0.2 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/karalabe/hid v1.0.1-0.20240306101548-573246063e52 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-base32 v0.0.3 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand All @@ -100,21 +102,21 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/wealdtech/go-multicodec v1.4.0 // indirect
github.com/ybbus/jsonrpc/v2 v2.1.7 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
lukechampine.com/blake3 v1.1.6 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit 2a9f319

Please sign in to comment.