Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - IBC signer #31

Draft
wants to merge 3 commits into
base: release/1.10
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions core/types/callback_signer.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading