-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw.go
49 lines (40 loc) · 1.1 KB
/
raw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2018 The VeChainThor developers
// Copyright (c) 2019 The PlayMaker developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package block
import (
"bytes"
"github.com/ethereum/go-ethereum/rlp"
"github.com/playmakerchain/powerplay/tx"
)
// Raw allows to partially decode components of a block.
type Raw []byte
// DecodeHeader decode only the header.
func (r Raw) DecodeHeader() (*Header, error) {
content, _, err := rlp.SplitList(r)
if err != nil {
return nil, err
}
var header Header
if err := rlp.Decode(bytes.NewReader(content), &header); err != nil {
return nil, err
}
return &header, nil
}
// DecodeBody decode only the body.
func (r Raw) DecodeBody() (*Body, error) {
content, _, err := rlp.SplitList(r)
if err != nil {
return nil, err
}
_, _, rest, err := rlp.Split(content)
if err != nil {
return nil, err
}
var txs tx.Transactions
if err := rlp.Decode(bytes.NewReader(rest), &txs); err != nil {
return nil, err
}
return &Body{txs}, nil
}