| 
									
										
										
										
											2014-10-31 14:43:14 +01:00
										 |  |  | package state | 
					
						
							| 
									
										
										
										
											2014-10-27 11:44:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 12:16:36 +01:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/ethutil" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2014-10-27 11:44:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Log struct { | 
					
						
							|  |  |  | 	Address []byte | 
					
						
							| 
									
										
										
										
											2014-10-29 10:34:40 +01:00
										 |  |  | 	Topics  [][]byte | 
					
						
							| 
									
										
										
										
											2014-10-27 11:44:16 +01:00
										 |  |  | 	Data    []byte | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-10-29 10:34:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 22:51:26 +01:00
										 |  |  | func NewLogFromValue(decoder *ethutil.Value) *Log { | 
					
						
							|  |  |  | 	log := &Log{ | 
					
						
							| 
									
										
										
										
											2014-10-29 10:34:40 +01:00
										 |  |  | 		Address: decoder.Get(0).Bytes(), | 
					
						
							|  |  |  | 		Data:    decoder.Get(2).Bytes(), | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it := decoder.Get(1).NewIterator() | 
					
						
							|  |  |  | 	for it.Next() { | 
					
						
							|  |  |  | 		log.Topics = append(log.Topics, it.Value().Bytes()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return log | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 22:51:26 +01:00
										 |  |  | func (self *Log) RlpData() interface{} { | 
					
						
							| 
									
										
										
										
											2014-10-29 10:34:40 +01:00
										 |  |  | 	return []interface{}{self.Address, ethutil.ByteSliceToInterface(self.Topics), self.Data} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 22:51:26 +01:00
										 |  |  | func (self *Log) String() string { | 
					
						
							| 
									
										
										
										
											2014-11-11 12:16:36 +01:00
										 |  |  | 	return fmt.Sprintf(`log: %x %x %x`, self.Address, self.Topics, self.Data) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 22:51:26 +01:00
										 |  |  | type Logs []*Log | 
					
						
							| 
									
										
										
										
											2014-10-29 10:34:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (self Logs) RlpData() interface{} { | 
					
						
							|  |  |  | 	data := make([]interface{}, len(self)) | 
					
						
							|  |  |  | 	for i, log := range self { | 
					
						
							|  |  |  | 		data[i] = log.RlpData() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return data | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-11-11 12:16:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (self Logs) String() string { | 
					
						
							|  |  |  | 	var logs []string | 
					
						
							|  |  |  | 	for _, log := range self { | 
					
						
							|  |  |  | 		logs = append(logs, log.String()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return "[ " + strings.Join(logs, ", ") + " ]" | 
					
						
							|  |  |  | } |