forked from cerc-io/laconicd-deprecated
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:
co-authored by
Federico Kunze Küllmer
parent
6e983a9da1
commit
e6f1874cfc
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user