core, eth, rpc: proper gas used. Closes #1417
Added some additional backward compatibility code for old receipts
This commit is contained in:
@ -82,6 +82,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
|
||||
usedGas.Add(usedGas, gas)
|
||||
receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas)
|
||||
receipt.TxHash = tx.Hash()
|
||||
receipt.GasUsed = new(big.Int).Set(gas)
|
||||
if MessageCreatesContract(tx) {
|
||||
from, _ := tx.From()
|
||||
receipt.ContractAddress = crypto.CreateAddress(from, tx.Nonce())
|
||||
|
@ -64,7 +64,7 @@ func GetReceipt(db common.Database, txHash common.Hash) *types.Receipt {
|
||||
var receipt types.Receipt
|
||||
err := rlp.DecodeBytes(data, &receipt)
|
||||
if err != nil {
|
||||
glog.V(logger.Error).Infoln("GetReceipt err:", err)
|
||||
glog.V(logger.Core).Infoln("GetReceipt err:", err)
|
||||
}
|
||||
return &receipt
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ type Receipt struct {
|
||||
TxHash common.Hash
|
||||
ContractAddress common.Address
|
||||
logs state.Logs
|
||||
GasUsed *big.Int
|
||||
}
|
||||
|
||||
func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt {
|
||||
@ -44,11 +45,12 @@ func (self *Receipt) DecodeRLP(s *rlp.Stream) error {
|
||||
TxHash common.Hash
|
||||
ContractAddress common.Address
|
||||
Logs state.Logs
|
||||
GasUsed *big.Int
|
||||
}
|
||||
if err := s.Decode(&r); err != nil {
|
||||
return err
|
||||
}
|
||||
self.PostState, self.CumulativeGasUsed, self.Bloom, self.TxHash, self.ContractAddress, self.logs = r.PostState, r.CumulativeGasUsed, r.Bloom, r.TxHash, r.ContractAddress, r.Logs
|
||||
self.PostState, self.CumulativeGasUsed, self.Bloom, self.TxHash, self.ContractAddress, self.logs, self.GasUsed = r.PostState, r.CumulativeGasUsed, r.Bloom, r.TxHash, r.ContractAddress, r.Logs, r.GasUsed
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -60,7 +62,7 @@ func (self *ReceiptForStorage) EncodeRLP(w io.Writer) error {
|
||||
for i, log := range self.logs {
|
||||
storageLogs[i] = (*state.LogForStorage)(log)
|
||||
}
|
||||
return rlp.Encode(w, []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.TxHash, self.ContractAddress, storageLogs})
|
||||
return rlp.Encode(w, []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.TxHash, self.ContractAddress, storageLogs, self.GasUsed})
|
||||
}
|
||||
|
||||
func (self *Receipt) RlpEncode() []byte {
|
||||
|
Reference in New Issue
Block a user