forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_data.go
50 lines (42 loc) · 1.36 KB
/
block_data.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
50
package sqlsol
import (
"fmt"
"github.com/hyperledger/burrow/vent/types"
)
// BlockData contains EventData definition
type BlockData struct {
Data types.EventData
}
// NewBlockData returns a pointer to an empty BlockData structure
func NewBlockData(height uint64) *BlockData {
data := types.EventData{
Tables: make(map[string]types.EventDataTable),
BlockHeight: height,
}
return &BlockData{
Data: data,
}
}
// AddRow appends a row to a specific table name in structure
func (b *BlockData) AddRow(tableName string, row types.EventDataRow) {
if _, ok := b.Data.Tables[tableName]; !ok {
b.Data.Tables[tableName] = types.EventDataTable{}
}
b.Data.Tables[tableName] = append(b.Data.Tables[tableName], row)
}
// GetRows gets data rows for a given table name from structure
func (b *BlockData) GetRows(tableName string) (types.EventDataTable, error) {
if table, ok := b.Data.Tables[tableName]; ok {
return table, nil
}
return nil, fmt.Errorf("GetRows: tableName does not exists as a table in data structure: %s ", tableName)
}
// PendingRows returns true if the given block has at least one pending row to upsert
func (b *BlockData) PendingRows(height uint64) bool {
hasRows := false
// TODO: understand why the guard on height is needed - what does it prevent?
if b.Data.BlockHeight == height && len(b.Data.Tables) > 0 {
hasRows = true
}
return hasRows
}