通過合約創(chuàng)建者和這筆交易的nonce梆掸,生成address
go-ethereum/internal/ethapi/api.go
signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())
from, err := types.Sender(signer, tx) //得到合約創(chuàng)建者地址
if err != nil {
return common.Hash{}, err
}
addr := crypto.CreateAddress(from, tx.Nonce()) //通過合約創(chuàng)建者和這筆交易的nonce购披,生成address
go-ethereum/crypto/crypto.go
// CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress(b common.Address, nonce uint64) common.Address {
data, _ := rlp.EncodeToBytes([]interface{}{b, nonce})
return common.BytesToAddress(Keccak256(data)[12:])
}