WIP: upgrade cosmos-sdk from 0.45 to SMT 0.46

This commit is contained in:
Sai Kumar
2022-04-11 13:39:39 +05:30
parent 4ddc8afd18
commit a0e2858d4f
56 changed files with 1124 additions and 3255 deletions
+4 -4
View File
@@ -1,7 +1,6 @@
package backend
import (
"bytes"
"context"
"encoding/json"
"fmt"
@@ -15,7 +14,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
tmrpctypes "github.com/tendermint/tendermint/rpc/coretypes"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
@@ -334,8 +334,8 @@ func (e *EVMBackend) BlockBloom(height *int64) (ethtypes.Bloom, error) {
}
for _, attr := range event.Attributes {
if bytes.Equal(attr.Key, bAttributeKeyEthereumBloom) {
return ethtypes.BytesToBloom(attr.Value), nil
if attr.Key == string(bAttributeKeyEthereumBloom) {
return ethtypes.BytesToBloom([]byte(attr.Value)), nil
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
tmrpctypes "github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tharsis/ethermint/rpc/ethereum/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)
+2 -2
View File
@@ -238,12 +238,12 @@ func TxLogsFromEvents(events []abci.Event, msgIndex int) ([]*ethtypes.Log, error
func ParseTxLogsFromEvent(event abci.Event) ([]*ethtypes.Log, error) {
logs := make([]*evmtypes.Log, 0, len(event.Attributes))
for _, attr := range event.Attributes {
if !bytes.Equal(attr.Key, []byte(evmtypes.AttributeKeyTxLog)) {
if !bytes.Equal([]byte(attr.Key), []byte(evmtypes.AttributeKeyTxLog)) {
continue
}
var log evmtypes.Log
if err := json.Unmarshal(attr.Value, &log); err != nil {
if err := json.Unmarshal([]byte(attr.Value), &log); err != nil {
return nil, err
}
+1 -1
View File
@@ -14,7 +14,7 @@ import (
"time"
"github.com/davecgh/go-spew/spew"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
tmrpctypes "github.com/tendermint/tendermint/rpc/coretypes"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
+7 -2
View File
@@ -20,7 +20,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/log"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
tmrpctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -74,6 +74,7 @@ func NewPublicAPI(
viper.GetString(flags.FlagKeyringBackend),
clientCtx.KeyringDir,
clientCtx.Input,
clientCtx.Codec,
hd.EthSecp256k1Option(),
)
if err != nil {
@@ -242,7 +243,11 @@ func (e *PublicAPI) Accounts() ([]common.Address, error) {
}
for _, info := range infos {
addressBytes := info.GetPubKey().Address().Bytes()
pubKey, err := info.GetPubKey()
if err != nil {
return addresses, err
}
addressBytes := pubKey.Address().Bytes()
addresses = append(addresses, common.BytesToAddress(addressBytes))
}
+8 -2
View File
@@ -11,7 +11,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
tmtypes "github.com/tendermint/tendermint/types"
@@ -371,7 +371,13 @@ func (api *PublicFilterAPI) Logs(ctx context.Context, crit filters.FilterCriteri
}
// filter only events from EVM module txs
_, isMsgEthereumTx := ev.Events[evmtypes.TypeMsgEthereumTx]
var isMsgEthereumTx bool
for _, event := range ev.Events {
if event.Type == evmtypes.TypeMsgEthereumTx {
isMsgEthereumTx = true
}
}
if !isMsgEthereumTx {
// ignore transaction as it's not from the evm module
@@ -10,8 +10,7 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
tmtypes "github.com/tendermint/tendermint/types"
@@ -27,9 +26,9 @@ import (
)
var (
txEvents = tmtypes.QueryForEvent(tmtypes.EventTx).String()
evmEvents = tmquery.MustParse(fmt.Sprintf("%s='%s' AND %s.%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTx, sdk.EventTypeMessage, sdk.AttributeKeyModule, evmtypes.ModuleName)).String()
headerEvents = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeader).String()
txEvents = tmtypes.QueryForEvent(tmtypes.EventTxValue).String()
evmEvents = fmt.Sprintf("%s='%s' AND %s.%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTx, sdk.EventTypeMessage, sdk.AttributeKeyModule, evmtypes.ModuleName)
headerEvents = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeaderValue).String()
)
// EventSystem creates subscriptions, processes events and broadcasts them to the
@@ -7,7 +7,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/rpc"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
)
// Subscription defines a wrapper for the private subscription
+1 -1
View File
@@ -124,7 +124,7 @@ func (api *API) SetEtherbase(etherbase common.Address) bool {
return false
}
if err := tx.Sign(txFactory, keyInfo.GetName(), builder, false); err != nil {
if err := tx.Sign(txFactory, keyInfo.Name, builder, false); err != nil {
api.logger.Debug("failed to sign tx", "error", err.Error())
return false
}
+7 -2
View File
@@ -102,7 +102,11 @@ func (api *PrivateAccountAPI) ListAccounts() ([]common.Address, error) {
}
for _, info := range list {
addrs = append(addrs, common.BytesToAddress(info.GetPubKey().Address()))
pubKey, err := info.GetPubKey()
if err != nil {
return nil, err
}
addrs = append(addrs, common.BytesToAddress(pubKey.Address()))
}
return addrs, nil
@@ -131,7 +135,8 @@ func (api *PrivateAccountAPI) NewAccount(password string) (common.Address, error
return common.Address{}, err
}
addr := common.BytesToAddress(info.GetPubKey().Address().Bytes())
pubKeyAddr, err := info.GetAddress()
addr := common.BytesToAddress(pubKeyAddr.Bytes())
api.logger.Info("Your new key was generated", "address", addr.String())
api.logger.Info("Please backup your key file!", "path", os.Getenv("HOME")+"/.ethermint/"+name) // TODO: pass the correct binary
api.logger.Info("Please remember your password!")
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/pkg/errors"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
)
type UnsubscribeFunc func()
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"time"
"github.com/stretchr/testify/require"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
)
func TestAddTopic(t *testing.T) {
+11 -3
View File
@@ -242,7 +242,7 @@ func BaseFeeFromEvents(events []abci.Event) *big.Int {
}
for _, attr := range event.Attributes {
if bytes.Equal(attr.Key, []byte(feemarkettypes.AttributeKeyBaseFee)) {
if attr.Key == feemarkettypes.AttributeKeyBaseFee {
result, success := new(big.Int).SetString(string(attr.Value), 10)
if success {
return result
@@ -250,6 +250,14 @@ func BaseFeeFromEvents(events []abci.Event) *big.Int {
return nil
}
// if bytes.Equal(attr.Key, []byte(feemarkettypes.AttributeKeyBaseFee)) {
// result, success := new(big.Int).SetString(string(attr.Value), 10)
// if success {
// return result
// }
// return nil
// }
}
}
return nil
@@ -310,10 +318,10 @@ func FindTxAttributesByIndex(events []abci.Event, txIndex uint64) int {
// FindAttribute find event attribute with specified key, if not found returns nil.
func FindAttribute(attrs []abci.EventAttribute, key []byte) []byte {
for _, attr := range attrs {
if !bytes.Equal(attr.Key, key) {
if !bytes.Equal([]byte(attr.Key), key) {
continue
}
return attr.Value
return []byte(attr.Value)
}
return nil
}