diff --git a/core/types/callback_signer.go b/core/types/callback_signer.go new file mode 100644 index 000000000000..4e45ef1d9190 --- /dev/null +++ b/core/types/callback_signer.go @@ -0,0 +1,44 @@ +package types + +import ( + "fmt" + "github.com/ethereum/go-ethereum/common" + "math/big" +) + +var _ Signer = callbackSigner{} + +type callbackSigner struct { + chainID *big.Int + relayerAddress common.Address +} + +func NewCallbackSigner(chainID *big.Int, relayerAddress common.Address) Signer { + return callbackSigner{chainID: chainID, relayerAddress: relayerAddress} +} + +func (c callbackSigner) Sender(tx *Transaction) (common.Address, error) { + if c.relayerAddress == (common.Address{}) { + return common.Address{}, fmt.Errorf("relayer address not set") + } + return c.relayerAddress, nil +} + +func (c callbackSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) { + // TODO: Return dummy values for now + return new(big.Int), new(big.Int), new(big.Int), nil +} + +func (c callbackSigner) ChainID() *big.Int { + return c.chainID +} + +func (c callbackSigner) Hash(tx *Transaction) common.Hash { + // Assume a simple RLP hash of the transaction is sufficient + return rlpHash([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}) +} + +func (c callbackSigner) Equal(signer Signer) bool { + _, ok := signer.(callbackSigner) + return ok +} diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index b3850d643f14..ad3301a3b1ec 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -37,9 +37,11 @@ type sigCache struct { } // MakeSigner returns a Signer based on the given chain config and block number. -func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer { +func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, senderAddr common.Address) Signer { var signer Signer switch { + case senderAddr != (common.Address{}): + signer = NewCallbackSigner(config.ChainID, senderAddr) case config.IsLondon(blockNumber): signer = NewLondonSigner(config.ChainID) case config.IsBerlin(blockNumber):