Merge pull request #19182 from karalabe/fix-legacy-receipt-decoding

core/types: fix receipt legacy decoding
This commit is contained in:
Péter Szilágyi 2019-02-28 14:59:26 +02:00 committed by GitHub
commit 0f41356b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -115,8 +115,12 @@ func (l *LogForStorage) EncodeRLP(w io.Writer) error {
// //
// Note some redundant fields(e.g. block number, tx hash etc) will be assembled later. // Note some redundant fields(e.g. block number, tx hash etc) will be assembled later.
func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error { func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error {
blob, err := s.Raw()
if err != nil {
return err
}
var dec rlpStorageLog var dec rlpStorageLog
err := s.Decode(&dec) err = rlp.DecodeBytes(blob, &dec)
if err == nil { if err == nil {
*l = LogForStorage{ *l = LogForStorage{
Address: dec.Address, Address: dec.Address,
@ -126,7 +130,7 @@ func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error {
} else { } else {
// Try to decode log with previous definition. // Try to decode log with previous definition.
var dec LegacyRlpStorageLog var dec LegacyRlpStorageLog
err = s.Decode(&dec) err = rlp.DecodeBytes(blob, &dec)
if err == nil { if err == nil {
*l = LogForStorage{ *l = LogForStorage{
Address: dec.Address, Address: dec.Address,

View File

@ -184,10 +184,14 @@ func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
// DecodeRLP implements rlp.Decoder, and loads both consensus and implementation // DecodeRLP implements rlp.Decoder, and loads both consensus and implementation
// fields of a receipt from an RLP stream. // fields of a receipt from an RLP stream.
func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error { func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
blob, err := s.Raw()
if err != nil {
return err
}
var dec receiptStorageRLP var dec receiptStorageRLP
if err := s.Decode(&dec); err != nil { if err := rlp.DecodeBytes(blob, &dec); err != nil {
var sdec LegacyReceiptStorageRLP var sdec LegacyReceiptStorageRLP
if err := s.Decode(&sdec); err != nil { if err := rlp.DecodeBytes(blob, &sdec); err != nil {
return err return err
} }
dec.PostStateOrStatus = common.CopyBytes(sdec.PostStateOrStatus) dec.PostStateOrStatus = common.CopyBytes(sdec.PostStateOrStatus)