func (self *StorageBlock) DecodeRLP(s *rlp.Stream) error { var sb storageblock if err := s.Decode(&sb); err != nil { return err } self.header, self.uncles, self.transactions, self.Td = sb.Header, sb.Uncles, sb.Txs, sb.TD return nil }
func (tx *Transaction) DecodeRLP(s *rlp.Stream) error { _, size, _ := s.Kind() err := s.Decode(&tx.data) if err == nil { tx.size.Store(common.StorageSize(rlp.ListSize(size))) } return err }
func (self *Block) DecodeRLP(s *rlp.Stream) error { var eb extblock if err := s.Decode(&eb); err != nil { return err } self.header, self.uncles, self.transactions = eb.Header, eb.Uncles, eb.Txs return nil }
func (self *Value) DecodeRLP(s *rlp.Stream) error { var v interface{} if err := s.Decode(&v); err != nil { return err } self.Val = v return nil }
func (b *Block) DecodeRLP(s *rlp.Stream) error { var eb extblock _, size, _ := s.Kind() if err := s.Decode(&eb); err != nil { return err } b.header, b.uncles, b.transactions = eb.Header, eb.Uncles, eb.Txs b.size.Store(common.StorageSize(rlp.ListSize(size))) return nil }
func (l *Log) DecodeRLP(s *rlp.Stream) error { var log struct { Address common.Address Topics []common.Hash Data []byte } if err := s.Decode(&log); err != nil { return err } l.Address, l.Topics, l.Data = log.Address, log.Topics, log.Data return nil }
// DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt // from an RLP stream. func (r *Receipt) DecodeRLP(s *rlp.Stream) error { var receipt struct { PostState []byte CumulativeGasUsed *big.Int Bloom Bloom Logs vm.Logs } if err := s.Decode(&receipt); err != nil { return err } r.PostState, r.CumulativeGasUsed, r.Bloom, r.Logs = receipt.PostState, receipt.CumulativeGasUsed, receipt.Bloom, receipt.Logs return nil }
func (self *Receipt) DecodeRLP(s *rlp.Stream) error { var r struct { PostState []byte CumulativeGasUsed *big.Int Bloom Bloom Logs state.Logs } if err := s.Decode(&r); err != nil { return err } self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs = r.PostState, r.CumulativeGasUsed, r.Bloom, r.Logs return nil }
// DecodeRLP is a specialized decoder for hashOrNumber to decode the contents // into either a block hash or a block number. func (hn *hashOrNumber) DecodeRLP(s *rlp.Stream) error { _, size, _ := s.Kind() origin, err := s.Raw() if err == nil { switch { case size == 32: err = rlp.DecodeBytes(origin, &hn.Hash) case size <= 8: err = rlp.DecodeBytes(origin, &hn.Number) default: err = fmt.Errorf("invalid input size %d for origin", size) } } return err }
// DecodeRLP decodes an Envelope from an RLP data stream. func (self *Envelope) DecodeRLP(s *rlp.Stream) error { raw, err := s.Raw() if err != nil { return err } // The decoding of Envelope uses the struct fields but also needs // to compute the hash of the whole RLP-encoded envelope. This // type has the same structure as Envelope but is not an // rlp.Decoder so we can reuse the Envelope struct definition. type rlpenv Envelope if err := rlp.DecodeBytes(raw, (*rlpenv)(self)); err != nil { return err } self.hash = crypto.Sha3Hash(raw) return nil }
func (self *Receipt) DecodeRLP(s *rlp.Stream) error { var r struct { PostState []byte CumulativeGasUsed *big.Int Bloom Bloom TxHash common.Hash ContractAddress common.Address Logs state.Logs GasUsed *big.Int } if err := s.Decode(&r); err != nil { return err } 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 return nil }
// checkDecodeFromJSON decodes from s guided by exp. exp drives the // Stream by invoking decoding operations (Uint, Big, List, ...) based // on the type of each value. The value decoded from the RLP stream // must match the JSON value. func checkDecodeFromJSON(s *rlp.Stream, exp interface{}) error { switch exp := exp.(type) { case uint64: i, err := s.Uint() if err != nil { return addStack("Uint", exp, err) } if i != exp { return addStack("Uint", exp, fmt.Errorf("result mismatch: got %d", i)) } case *big.Int: big := new(big.Int) if err := s.Decode(&big); err != nil { return addStack("Big", exp, err) } if big.Cmp(exp) != 0 { return addStack("Big", exp, fmt.Errorf("result mismatch: got %d", big)) } case []byte: b, err := s.Bytes() if err != nil { return addStack("Bytes", exp, err) } if !bytes.Equal(b, exp) { return addStack("Bytes", exp, fmt.Errorf("result mismatch: got %x", b)) } case []interface{}: if _, err := s.List(); err != nil { return addStack("List", exp, err) } for i, v := range exp { if err := checkDecodeFromJSON(s, v); err != nil { return addStack(fmt.Sprintf("[%d]", i), exp, err) } } if err := s.ListEnd(); err != nil { return addStack("ListEnd", exp, err) } default: panic(fmt.Errorf("unhandled type: %T", exp)) } return nil }
// DecodeRLP implements rlp.Decoder, and loads both consensus and implementation // fields of a receipt from an RLP stream. func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error { var receipt struct { PostState []byte CumulativeGasUsed *big.Int Bloom Bloom TxHash common.Hash ContractAddress common.Address Logs []*vm.LogForStorage GasUsed *big.Int } if err := s.Decode(&receipt); err != nil { return err } // Assign the consensus fields r.PostState, r.CumulativeGasUsed, r.Bloom = receipt.PostState, receipt.CumulativeGasUsed, receipt.Bloom r.Logs = make(vm.Logs, len(receipt.Logs)) for i, log := range receipt.Logs { r.Logs[i] = (*vm.Log)(log) } // Assign the implementation fields r.TxHash, r.ContractAddress, r.GasUsed = receipt.TxHash, receipt.ContractAddress, receipt.GasUsed return nil }
func dump(s *rlp.Stream, depth int) error { kind, size, err := s.Kind() if err != nil { return err } switch kind { case rlp.Byte, rlp.String: str, err := s.Bytes() if err != nil { return err } if len(str) == 0 || !*noASCII && isASCII(str) { fmt.Printf("%s%q", ws(depth), str) } else { fmt.Printf("%s%x", ws(depth), str) } case rlp.List: s.List() defer s.ListEnd() if size == 0 { fmt.Print(ws(depth) + "[]") } else { fmt.Println(ws(depth) + "[") for i := 0; ; i++ { if i > 0 { fmt.Print(",\n") } if err := dump(s, depth+1); err == rlp.EOL { break } else if err != nil { return err } } fmt.Print(ws(depth) + "]") } } return nil }