Skip to content

Commit 4dca5d4

Browse files
committed
core/types, params: EIP#155
1 parent 5cd8644 commit 4dca5d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1068
-464
lines changed

accounts/abi/bind/auth.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
4848
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
4949
return &TransactOpts{
5050
From: keyAddr,
51-
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
51+
Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
5252
if address != keyAddr {
5353
return nil, errors.New("not authorized to sign this account")
5454
}
55-
signature, err := crypto.SignEthereum(tx.SigHash().Bytes(), key)
55+
signature, err := crypto.SignEthereum(signer.Hash(tx).Bytes(), key)
5656
if err != nil {
5757
return nil, err
5858
}
59-
return tx.WithSignature(signature)
59+
return tx.WithSignature(signer, signature)
6060
},
6161
}
6262
}

accounts/abi/bind/backends/simulated.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
237237
b.mu.Lock()
238238
defer b.mu.Unlock()
239239

240-
sender, err := tx.From()
240+
sender, err := types.Sender(types.HomesteadSigner{}, tx)
241241
if err != nil {
242242
panic(fmt.Errorf("invalid transaction: %v", err))
243243
}
@@ -262,12 +262,11 @@ type callmsg struct {
262262
ethereum.CallMsg
263263
}
264264

265-
func (m callmsg) From() (common.Address, error) { return m.CallMsg.From, nil }
266-
func (m callmsg) FromFrontier() (common.Address, error) { return m.CallMsg.From, nil }
267-
func (m callmsg) Nonce() uint64 { return 0 }
268-
func (m callmsg) CheckNonce() bool { return false }
269-
func (m callmsg) To() *common.Address { return m.CallMsg.To }
270-
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
271-
func (m callmsg) Gas() *big.Int { return m.CallMsg.Gas }
272-
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
273-
func (m callmsg) Data() []byte { return m.CallMsg.Data }
265+
func (m callmsg) From() common.Address { return m.CallMsg.From }
266+
func (m callmsg) Nonce() uint64 { return 0 }
267+
func (m callmsg) CheckNonce() bool { return false }
268+
func (m callmsg) To() *common.Address { return m.CallMsg.To }
269+
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
270+
func (m callmsg) Gas() *big.Int { return m.CallMsg.Gas }
271+
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
272+
func (m callmsg) Data() []byte { return m.CallMsg.Data }

accounts/abi/bind/base.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// SignerFn is a signer function callback when a contract requires a method to
3333
// sign the transaction before submission.
34-
type SignerFn func(common.Address, *types.Transaction) (*types.Transaction, error)
34+
type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Transaction, error)
3535

3636
// CallOpts is the collection of options to fine tune a contract call request.
3737
type CallOpts struct {
@@ -214,7 +214,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
214214
if opts.Signer == nil {
215215
return nil, errors.New("no signer to authorize the transaction with")
216216
}
217-
signedTx, err := opts.Signer(opts.From, rawTx)
217+
signedTx, err := opts.Signer(types.HomesteadSigner{}, opts.From, rawTx)
218218
if err != nil {
219219
return nil, err
220220
}

accounts/abi/bind/util_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestWaitDeployed(t *testing.T) {
6060

6161
// Create the transaction.
6262
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code))
63-
tx, _ = tx.SignECDSA(testKey)
63+
tx, _ = tx.SignECDSA(types.HomesteadSigner{}, testKey)
6464

6565
// Wait for it to get mined in the background.
6666
var (

cmd/utils/flags.go

+4
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *params.ChainCon
825825
Fatalf("Could not make chain configuration: %v", err)
826826
}
827827
}
828+
// set chain id in case it's zero.
829+
if config.ChainId == nil {
830+
config.ChainId = new(big.Int)
831+
}
828832
// Check whether we are allowed to set default config params or not:
829833
// - If no genesis is set, we're running either mainnet or testnet (private nets use `geth init`)
830834
// - If a genesis is already set, ensure we have a configuration for it (mainnet or testnet)

common/registrar/ethreg/api.go

+12-16
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,20 @@ func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr
174174

175175
from.SetBalance(common.MaxBig)
176176

177-
msg := callmsg{
178-
from: from,
179-
gas: common.Big(gasStr),
180-
gasPrice: common.Big(gasPriceStr),
181-
value: common.Big(valueStr),
182-
data: common.FromHex(dataStr),
183-
}
177+
var to *common.Address
184178
if len(toStr) > 0 {
185179
addr := common.HexToAddress(toStr)
186-
msg.to = &addr
180+
to = &addr
187181
}
188-
189-
if msg.gas.Cmp(big.NewInt(0)) == 0 {
190-
msg.gas = big.NewInt(50000000)
182+
gas := common.Big(gasStr)
183+
if gas.BitLen() == 0 {
184+
gas = big.NewInt(50000000)
191185
}
192-
193-
if msg.gasPrice.Cmp(big.NewInt(0)) == 0 {
194-
msg.gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
186+
gasPrice := common.Big(gasPriceStr)
187+
if gasPrice.BitLen() == 0 {
188+
gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
195189
}
190+
msg := types.NewMessage(from.Address(), to, 0, common.Big(valueStr), gas, gasPrice, common.FromHex(dataStr))
196191

197192
header := be.bc.CurrentBlock().Header()
198193
vmenv := core.NewEnv(statedb, be.config, be.bc, msg, header, vm.Config{})
@@ -258,11 +253,12 @@ func (be *registryAPIBackend) Transact(fromStr, toStr, nonceStr, valueStr, gasSt
258253
tx = types.NewTransaction(nonce, to, value, gas, price, data)
259254
}
260255

261-
signature, err := be.am.SignEthereum(from, tx.SigHash().Bytes())
256+
sigHash := (types.HomesteadSigner{}).Hash(tx)
257+
signature, err := be.am.SignEthereum(from, sigHash.Bytes())
262258
if err != nil {
263259
return "", err
264260
}
265-
signedTx, err := tx.WithSignature(signature)
261+
signedTx, err := tx.WithSignature(types.HomesteadSigner{}, signature)
266262
if err != nil {
267263
return "", err
268264
}

console/console_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
9797
t.Fatalf("failed to create node: %v", err)
9898
}
9999
ethConf := &eth.Config{
100-
ChainConfig: &params.ChainConfig{HomesteadBlock: new(big.Int)},
100+
ChainConfig: &params.ChainConfig{HomesteadBlock: new(big.Int), ChainId: new(big.Int)},
101101
Etherbase: common.HexToAddress(testAddress),
102102
PowTest: true,
103103
}

core/bench_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
8383
toaddr := common.Address{}
8484
data := make([]byte, nbytes)
8585
gas := IntrinsicGas(data, false, false)
86-
tx, _ := types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data).SignECDSA(benchRootKey)
86+
tx, _ := types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data).SignECDSA(types.HomesteadSigner{}, benchRootKey)
8787
gen.AddTx(tx)
8888
}
8989
}
@@ -123,7 +123,7 @@ func genTxRing(naccounts int) func(int, *BlockGen) {
123123
nil,
124124
nil,
125125
)
126-
tx, _ = tx.SignECDSA(ringKeys[from])
126+
tx, _ = tx.SignECDSA(types.HomesteadSigner{}, ringKeys[from])
127127
gen.AddTx(tx)
128128
from = to
129129
}

core/blockchain.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,19 @@ func (self *BlockChain) Rollback(chain []common.Hash) {
634634
}
635635

636636
// SetReceiptsData computes all the non-consensus fields of the receipts
637-
func SetReceiptsData(block *types.Block, receipts types.Receipts) {
637+
func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts types.Receipts) {
638+
signer := types.MakeSigner(config, block.Number())
639+
638640
transactions, logIndex := block.Transactions(), uint(0)
639641

640642
for j := 0; j < len(receipts); j++ {
641643
// The transaction hash can be retrieved from the transaction itself
642644
receipts[j].TxHash = transactions[j].Hash()
643645

646+
tx, _ := transactions[j].AsMessage(signer)
644647
// The contract address can be derived from the transaction itself
645-
if MessageCreatesContract(transactions[j]) {
646-
from, _ := transactions[j].From()
647-
receipts[j].ContractAddress = crypto.CreateAddress(from, transactions[j].Nonce())
648+
if MessageCreatesContract(tx) {
649+
receipts[j].ContractAddress = crypto.CreateAddress(tx.From(), tx.Nonce())
648650
}
649651
// The used gas can be calculated based on previous receipts
650652
if j == 0 {
@@ -666,6 +668,7 @@ func SetReceiptsData(block *types.Block, receipts types.Receipts) {
666668

667669
// InsertReceiptChain attempts to complete an already existing header chain with
668670
// transaction and receipt data.
671+
// XXX should this be moved to the test?
669672
func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts) (int, error) {
670673
self.wg.Add(1)
671674
defer self.wg.Done()
@@ -705,7 +708,7 @@ func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain
705708
continue
706709
}
707710
// Compute all the non-consensus fields of the receipts
708-
SetReceiptsData(block, receipts)
711+
SetReceiptsData(self.config, block, receipts)
709712
// Write all the data out into the database
710713
if err := WriteBody(self.chainDb, block.Hash(), block.NumberU64(), block.Body()); err != nil {
711714
errs[index] = fmt.Errorf("failed to write block body: %v", err)

0 commit comments

Comments
 (0)