2015-07-06 17:54:22 -07:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-07-22 09:48:40 -07:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-06 17:54:22 -07:00
|
|
|
//
|
2015-07-23 09:35:11 -07:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-06 17:54:22 -07:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 09:48:40 -07:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-06 17:54:22 -07:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 09:48:40 -07:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-06 17:54:22 -07:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 09:48:40 -07:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-06 17:54:22 -07:00
|
|
|
|
2014-11-18 07:58:22 -08:00
|
|
|
package types
|
2014-11-11 03:16:36 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2015-03-16 15:10:26 -07:00
|
|
|
"io"
|
2014-11-11 03:16:36 -08:00
|
|
|
"math/big"
|
|
|
|
|
2015-03-16 03:27:38 -07:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2015-03-23 08:59:09 -07:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
2015-04-08 08:14:58 -07:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2014-11-11 03:16:36 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Receipt struct {
|
|
|
|
PostState []byte
|
|
|
|
CumulativeGasUsed *big.Int
|
2015-03-16 15:48:18 -07:00
|
|
|
Bloom Bloom
|
2015-07-03 17:25:04 -07:00
|
|
|
TxHash common.Hash
|
|
|
|
ContractAddress common.Address
|
2014-11-11 03:16:36 -08:00
|
|
|
logs state.Logs
|
2015-07-06 11:59:12 -07:00
|
|
|
GasUsed *big.Int
|
2014-11-11 03:16:36 -08:00
|
|
|
}
|
|
|
|
|
2014-11-18 07:58:22 -08:00
|
|
|
func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt {
|
2015-03-16 03:27:38 -07:00
|
|
|
return &Receipt{PostState: common.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumalativeGasUsed)}
|
2014-11-18 07:58:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Receipt) SetLogs(logs state.Logs) {
|
|
|
|
self.logs = logs
|
|
|
|
}
|
|
|
|
|
2015-05-22 13:44:51 -07:00
|
|
|
func (self *Receipt) Logs() state.Logs {
|
|
|
|
return self.logs
|
|
|
|
}
|
|
|
|
|
2015-03-16 15:10:26 -07:00
|
|
|
func (self *Receipt) EncodeRLP(w io.Writer) error {
|
|
|
|
return rlp.Encode(w, []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs})
|
2014-11-11 03:16:36 -08:00
|
|
|
}
|
|
|
|
|
2015-05-22 13:44:51 -07:00
|
|
|
func (self *Receipt) DecodeRLP(s *rlp.Stream) error {
|
|
|
|
var r struct {
|
|
|
|
PostState []byte
|
|
|
|
CumulativeGasUsed *big.Int
|
|
|
|
Bloom Bloom
|
2015-07-03 17:25:04 -07:00
|
|
|
TxHash common.Hash
|
|
|
|
ContractAddress common.Address
|
2015-05-22 13:44:51 -07:00
|
|
|
Logs state.Logs
|
2015-07-06 11:59:12 -07:00
|
|
|
GasUsed *big.Int
|
2015-05-22 13:44:51 -07:00
|
|
|
}
|
|
|
|
if err := s.Decode(&r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-07-06 11:59:12 -07:00
|
|
|
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
|
2015-05-22 13:44:51 -07:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReceiptForStorage Receipt
|
|
|
|
|
|
|
|
func (self *ReceiptForStorage) EncodeRLP(w io.Writer) error {
|
|
|
|
storageLogs := make([]*state.LogForStorage, len(self.logs))
|
|
|
|
for i, log := range self.logs {
|
|
|
|
storageLogs[i] = (*state.LogForStorage)(log)
|
|
|
|
}
|
2015-07-06 11:59:12 -07:00
|
|
|
return rlp.Encode(w, []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.TxHash, self.ContractAddress, storageLogs, self.GasUsed})
|
2015-05-22 13:44:51 -07:00
|
|
|
}
|
|
|
|
|
2014-11-11 03:16:36 -08:00
|
|
|
func (self *Receipt) RlpEncode() []byte {
|
2015-03-16 15:10:26 -07:00
|
|
|
bytes, err := rlp.EncodeToBytes(self)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("TMP -- RECEIPT ENCODE ERROR", err)
|
|
|
|
}
|
|
|
|
return bytes
|
2014-11-11 03:16:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Receipt) Cmp(other *Receipt) bool {
|
|
|
|
if bytes.Compare(self.PostState, other.PostState) != 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Receipt) String() string {
|
2014-11-14 05:17:54 -08:00
|
|
|
return fmt.Sprintf("receipt{med=%x cgas=%v bloom=%x logs=%v}", self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs)
|
2014-11-11 03:16:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type Receipts []*Receipt
|
|
|
|
|
2014-12-05 03:32:47 -08:00
|
|
|
func (self Receipts) RlpEncode() []byte {
|
2015-03-16 15:10:26 -07:00
|
|
|
bytes, err := rlp.EncodeToBytes(self)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("TMP -- RECEIPTS ENCODE ERROR", err)
|
|
|
|
}
|
|
|
|
return bytes
|
2014-12-05 03:32:47 -08:00
|
|
|
}
|
|
|
|
|
2014-11-11 03:16:36 -08:00
|
|
|
func (self Receipts) Len() int { return len(self) }
|
2015-03-16 03:27:38 -07:00
|
|
|
func (self Receipts) GetRlp(i int) []byte { return common.Rlp(self[i]) }
|