github.com/karalabe/go-ethereum@v0.8.5/core/types/receipt.go (about)

     1  package types
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"math/big"
     7  
     8  	"github.com/ethereum/go-ethereum/ethutil"
     9  	"github.com/ethereum/go-ethereum/state"
    10  )
    11  
    12  type Receipt struct {
    13  	PostState         []byte
    14  	CumulativeGasUsed *big.Int
    15  	Bloom             []byte
    16  	logs              state.Logs
    17  }
    18  
    19  func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt {
    20  	return &Receipt{PostState: ethutil.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumalativeGasUsed)}
    21  }
    22  
    23  func NewRecieptFromValue(val *ethutil.Value) *Receipt {
    24  	r := &Receipt{}
    25  	r.RlpValueDecode(val)
    26  
    27  	return r
    28  }
    29  
    30  func (self *Receipt) SetLogs(logs state.Logs) {
    31  	self.logs = logs
    32  }
    33  
    34  func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) {
    35  	self.PostState = decoder.Get(0).Bytes()
    36  	self.CumulativeGasUsed = decoder.Get(1).BigInt()
    37  	self.Bloom = decoder.Get(2).Bytes()
    38  
    39  	it := decoder.Get(3).NewIterator()
    40  	for it.Next() {
    41  		self.logs = append(self.logs, state.NewLogFromValue(it.Value()))
    42  	}
    43  }
    44  
    45  func (self *Receipt) RlpData() interface{} {
    46  	return []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs.RlpData()}
    47  }
    48  
    49  func (self *Receipt) RlpEncode() []byte {
    50  	return ethutil.Encode(self.RlpData())
    51  }
    52  
    53  func (self *Receipt) Cmp(other *Receipt) bool {
    54  	if bytes.Compare(self.PostState, other.PostState) != 0 {
    55  		return false
    56  	}
    57  
    58  	return true
    59  }
    60  
    61  func (self *Receipt) String() string {
    62  	return fmt.Sprintf("receipt{med=%x cgas=%v bloom=%x logs=%v}", self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs)
    63  }
    64  
    65  type Receipts []*Receipt
    66  
    67  func (self Receipts) RlpData() interface{} {
    68  	data := make([]interface{}, len(self))
    69  	for i, receipt := range self {
    70  		data[i] = receipt.RlpData()
    71  	}
    72  
    73  	return data
    74  }
    75  
    76  func (self Receipts) RlpEncode() []byte {
    77  	return ethutil.Encode(self.RlpData())
    78  }
    79  
    80  func (self Receipts) Len() int            { return len(self) }
    81  func (self Receipts) GetRlp(i int) []byte { return ethutil.Rlp(self[i]) }