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:
parent
6e983a9da1
commit
e6f1874cfc
@ -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),
|
||||
|
@ -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 {
|
||||
|
@ -216,3 +216,14 @@ func (msg MsgEthereumTx) AsTransaction() *ethtypes.Transaction {
|
||||
func (msg MsgEthereumTx) AsMessage(signer ethtypes.Signer) (core.Message, error) {
|
||||
return msg.AsTransaction().AsMessage(signer)
|
||||
}
|
||||
|
||||
// GetSender extracts the sender address from the signature values using the latest signer for the given chainID.
|
||||
func (msg *MsgEthereumTx) GetSender(chainID *big.Int) (common.Address, error) {
|
||||
signer := ethtypes.LatestSignerForChainID(chainID)
|
||||
from, err := signer.Sender(msg.AsTransaction())
|
||||
if err != nil {
|
||||
return common.Address{}, err
|
||||
}
|
||||
msg.From = from.Hex()
|
||||
return from, nil
|
||||
}
|
||||
|
@ -183,9 +183,7 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_Sign() {
|
||||
if tc.expectPass {
|
||||
suite.Require().NoError(err, "valid test %d failed: %s", i, tc.msg)
|
||||
|
||||
tx := tc.tx.AsTransaction()
|
||||
|
||||
sender, err := ethtypes.Sender(tc.ethSigner, tx)
|
||||
sender, err := tc.tx.GetSender(suite.chainID)
|
||||
suite.Require().NoError(err, tc.msg)
|
||||
suite.Require().Equal(tc.tx.From, sender.Hex(), tc.msg)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user