-
Notifications
You must be signed in to change notification settings - Fork 248
/
block_reader.go
39 lines (33 loc) · 935 Bytes
/
block_reader.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
// Copyright (c) 2018 The VeChainThor 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 subscriptions
import (
"github.com/vechain/thor/chain"
"github.com/vechain/thor/thor"
)
type blockReader struct {
repo *chain.Repository
blockReader chain.BlockReader
}
func newBlockReader(repo *chain.Repository, position thor.Bytes32) *blockReader {
return &blockReader{
repo: repo,
blockReader: repo.NewBlockReader(position),
}
}
func (br *blockReader) Read() ([]interface{}, bool, error) {
blocks, err := br.blockReader.Read()
if err != nil {
return nil, false, err
}
var msgs []interface{}
for _, block := range blocks {
msg, err := convertBlock(block)
if err != nil {
return nil, false, err
}
msgs = append(msgs, msg)
}
return msgs, len(blocks) > 0, nil
}