rpc: extract sender address from msg signature (#217)

* extract real from address in rpc tx query api

Closes: #210

* Update x/evm/types/msg.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
yihuang
2021-07-02 09:34:15 +00:00
committed by GitHub
co-authored by Federico Kunze Küllmer
parent 6e983a9da1
commit e6f1874cfc
4 changed files with 32 additions and 6 deletions
+11 -1
View File
@@ -49,15 +49,21 @@ type EVMBackend struct {
clientCtx client.Context
queryClient *types.QueryClient // gRPC query client
logger log.Logger
chainID *big.Int
}
// NewEVMBackend creates a new EVMBackend instance
func NewEVMBackend(clientCtx client.Context) *EVMBackend {
chainID, err := ethermint.ParseChainID(clientCtx.ChainID)
if err != nil {
panic(err)
}
return &EVMBackend{
ctx: context.Background(),
clientCtx: clientCtx,
queryClient: types.NewQueryClient(clientCtx),
logger: log.WithField("module", "evm-backend"),
chainID: chainID,
}
}
@@ -151,9 +157,13 @@ func (e *EVMBackend) EthBlockFromTendermint(
hash := msg.AsTransaction().Hash()
if fullTx {
from, err := msg.GetSender(e.chainID)
if err != nil {
from = common.HexToAddress(msg.From)
}
ethTx, err := types.NewTransactionFromData(
msg.Data,
common.HexToAddress(msg.From),
from,
hash,
common.BytesToHash(block.Hash()),
uint64(block.Height),
+9 -2
View File
@@ -723,9 +723,13 @@ func (e *PublicAPI) GetTransactionByHash(hash common.Hash) (*rpctypes.RPCTransac
return nil, fmt.Errorf("invalid tx type: %T", tx)
}
from, err := msg.GetSender(e.chainIDEpoch)
if err != nil {
return nil, err
}
return rpctypes.NewTransactionFromData(
msg.Data,
common.HexToAddress(msg.From),
from,
hash,
common.BytesToHash(resBlock.Block.Hash()),
uint64(res.Height),
@@ -880,7 +884,10 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac
status = hexutil.Uint(ethtypes.ReceiptStatusFailed)
}
from := common.HexToAddress(msg.From)
from, err := msg.GetSender(e.chainIDEpoch)
if err != nil {
return nil, err
}
resLogs, err := e.queryClient.TxLogs(e.ctx, &evmtypes.QueryTxLogsRequest{Hash: hash.Hex()})
if err != nil {