log.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package state
  17. import (
  18. "fmt"
  19. "io"
  20. "github.com/ethereum/go-ethereum/common"
  21. "github.com/ethereum/go-ethereum/rlp"
  22. )
  23. type Log struct {
  24. Address common.Address
  25. Topics []common.Hash
  26. Data []byte
  27. Number uint64
  28. TxHash common.Hash
  29. TxIndex uint
  30. BlockHash common.Hash
  31. Index uint
  32. }
  33. func NewLog(address common.Address, topics []common.Hash, data []byte, number uint64) *Log {
  34. return &Log{Address: address, Topics: topics, Data: data, Number: number}
  35. }
  36. func (self *Log) EncodeRLP(w io.Writer) error {
  37. return rlp.Encode(w, []interface{}{self.Address, self.Topics, self.Data})
  38. }
  39. func (self *Log) String() string {
  40. return fmt.Sprintf(`log: %x %x %x %x %d %x %d`, self.Address, self.Topics, self.Data, self.TxHash, self.TxIndex, self.BlockHash, self.Index)
  41. }
  42. type Logs []*Log
  43. type LogForStorage Log
  44. func (self *LogForStorage) EncodeRLP(w io.Writer) error {
  45. return rlp.Encode(w, []interface{}{
  46. self.Address,
  47. self.Topics,
  48. self.Data,
  49. self.Number,
  50. self.TxHash,
  51. self.TxIndex,
  52. self.BlockHash,
  53. self.Index,
  54. })
  55. }