log.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package state
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/ethereum/go-ethereum/common"
  6. "github.com/ethereum/go-ethereum/rlp"
  7. )
  8. type Log interface {
  9. Address() common.Address
  10. Topics() []common.Hash
  11. Data() []byte
  12. Number() uint64
  13. }
  14. type StateLog struct {
  15. address common.Address
  16. topics []common.Hash
  17. data []byte
  18. number uint64
  19. }
  20. func NewLog(address common.Address, topics []common.Hash, data []byte, number uint64) *StateLog {
  21. return &StateLog{address, topics, data, number}
  22. }
  23. func (self *StateLog) Address() common.Address {
  24. return self.address
  25. }
  26. func (self *StateLog) Topics() []common.Hash {
  27. return self.topics
  28. }
  29. func (self *StateLog) Data() []byte {
  30. return self.data
  31. }
  32. func (self *StateLog) Number() uint64 {
  33. return self.number
  34. }
  35. /*
  36. func NewLogFromValue(decoder *common.Value) *StateLog {
  37. var extlog struct {
  38. }
  39. log := &StateLog{
  40. address: decoder.Get(0).Bytes(),
  41. data: decoder.Get(2).Bytes(),
  42. }
  43. it := decoder.Get(1).NewIterator()
  44. for it.Next() {
  45. log.topics = append(log.topics, it.Value().Bytes())
  46. }
  47. return log
  48. }
  49. */
  50. func (self *StateLog) EncodeRLP(w io.Writer) error {
  51. return rlp.Encode(w, []interface{}{self.address, self.topics, self.data})
  52. }
  53. /*
  54. func (self *StateLog) RlpData() interface{} {
  55. return []interface{}{self.address, common.ByteSliceToInterface(self.topics), self.data}
  56. }
  57. */
  58. func (self *StateLog) String() string {
  59. return fmt.Sprintf(`log: %x %x %x`, self.address, self.topics, self.data)
  60. }
  61. type Logs []Log
  62. /*
  63. func (self Logs) RlpData() interface{} {
  64. data := make([]interface{}, len(self))
  65. for i, log := range self {
  66. data[i] = log.RlpData()
  67. }
  68. return data
  69. }
  70. */
  71. func (self Logs) String() (ret string) {
  72. for _, log := range self {
  73. ret += fmt.Sprintf("%v", log)
  74. }
  75. return "[" + ret + "]"
  76. }