mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 03:56:36 +00:00
core/types: more easily extensible tx signing (#30372)
This change makes the code slightly easier for downstream-projects to extend with more signer-types, but if functionalily equivalent to the previous code.
This commit is contained in:
parent
4c4f21293e
commit
03424962f1
1 changed files with 21 additions and 15 deletions
|
|
@ -64,21 +64,24 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint
|
||||||
// Use this in transaction-handling code where the current block number is unknown. If you
|
// Use this in transaction-handling code where the current block number is unknown. If you
|
||||||
// have the current block number available, use MakeSigner instead.
|
// have the current block number available, use MakeSigner instead.
|
||||||
func LatestSigner(config *params.ChainConfig) Signer {
|
func LatestSigner(config *params.ChainConfig) Signer {
|
||||||
|
var signer Signer
|
||||||
if config.ChainID != nil {
|
if config.ChainID != nil {
|
||||||
if config.CancunTime != nil {
|
switch {
|
||||||
return NewCancunSigner(config.ChainID)
|
case config.CancunTime != nil:
|
||||||
}
|
signer = NewCancunSigner(config.ChainID)
|
||||||
if config.LondonBlock != nil {
|
case config.LondonBlock != nil:
|
||||||
return NewLondonSigner(config.ChainID)
|
signer = NewLondonSigner(config.ChainID)
|
||||||
}
|
case config.BerlinBlock != nil:
|
||||||
if config.BerlinBlock != nil {
|
signer = NewEIP2930Signer(config.ChainID)
|
||||||
return NewEIP2930Signer(config.ChainID)
|
case config.EIP155Block != nil:
|
||||||
}
|
signer = NewEIP155Signer(config.ChainID)
|
||||||
if config.EIP155Block != nil {
|
default:
|
||||||
return NewEIP155Signer(config.ChainID)
|
signer = HomesteadSigner{}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
signer = HomesteadSigner{}
|
||||||
}
|
}
|
||||||
return HomesteadSigner{}
|
return signer
|
||||||
}
|
}
|
||||||
|
|
||||||
// LatestSignerForChainID returns the 'most permissive' Signer available. Specifically,
|
// LatestSignerForChainID returns the 'most permissive' Signer available. Specifically,
|
||||||
|
|
@ -89,10 +92,13 @@ func LatestSigner(config *params.ChainConfig) Signer {
|
||||||
// configuration are unknown. If you have a ChainConfig, use LatestSigner instead.
|
// configuration are unknown. If you have a ChainConfig, use LatestSigner instead.
|
||||||
// If you have a ChainConfig and know the current block number, use MakeSigner instead.
|
// If you have a ChainConfig and know the current block number, use MakeSigner instead.
|
||||||
func LatestSignerForChainID(chainID *big.Int) Signer {
|
func LatestSignerForChainID(chainID *big.Int) Signer {
|
||||||
if chainID == nil {
|
var signer Signer
|
||||||
return HomesteadSigner{}
|
if chainID != nil {
|
||||||
|
signer = NewCancunSigner(chainID)
|
||||||
|
} else {
|
||||||
|
signer = HomesteadSigner{}
|
||||||
}
|
}
|
||||||
return NewCancunSigner(chainID)
|
return signer
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignTx signs the transaction using the given signer and private key.
|
// SignTx signs the transaction using the given signer and private key.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue