core: leave contract addr in receipt empty when deployment fails

This commit is contained in:
Bas van Kervel 2016-11-30 16:18:01 +01:00
parent 86f9e836be
commit f17366534e
2 changed files with 6 additions and 2 deletions

View file

@ -97,7 +97,7 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, gp *GasPool, s
return nil, nil, nil, err return nil, nil, nil, err
} }
_, gas, err := ApplyMessage(NewEnv(statedb, config, bc, msg, header, cfg), msg, gp) ret, gas, err := ApplyMessage(NewEnv(statedb, config, bc, msg, header, cfg), msg, gp)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
@ -107,7 +107,9 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, gp *GasPool, s
receipt := types.NewReceipt(statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes(), usedGas) receipt := types.NewReceipt(statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes(), usedGas)
receipt.TxHash = tx.Hash() receipt.TxHash = tx.Hash()
receipt.GasUsed = new(big.Int).Set(gas) receipt.GasUsed = new(big.Int).Set(gas)
if MessageCreatesContract(msg) {
// ret is only not nil when the contract is deployed successful.
if MessageCreatesContract(msg) && ret != nil {
receipt.ContractAddress = crypto.CreateAddress(msg.From(), tx.Nonce()) receipt.ContractAddress = crypto.CreateAddress(msg.From(), tx.Nonce())
} }

View file

@ -235,6 +235,8 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
if err != nil { if err != nil {
ret = nil ret = nil
glog.V(logger.Core).Infoln("VM create err:", err) glog.V(logger.Core).Infoln("VM create err:", err)
} else if ret == nil { // contract deployed without code
ret = []byte{}
} }
} else { } else {
// Increment the nonce for the next transaction // Increment the nonce for the next transaction