forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_loader.go
135 lines (122 loc) · 2.61 KB
/
spec_loader.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package sqlsol
import (
"fmt"
"github.com/hyperledger/burrow/txs"
"github.com/hyperledger/burrow/vent/types"
)
type SpecOpt uint64
const (
Block SpecOpt = 1 << iota
Tx
)
const (
None SpecOpt = 0
BlockTx = Block | Tx
)
func (so SpecOpt) Enabled(opt SpecOpt) bool {
return so&opt > 0
}
// SpecLoader loads spec files and parses them
func SpecLoader(specFileOrDirs []string, opts SpecOpt) (*Projection, error) {
var projection *Projection
var err error
if len(specFileOrDirs) == 0 {
return nil, fmt.Errorf("please provide a spec file or directory")
}
projection, err = NewProjectionFromFolder(specFileOrDirs...)
if err != nil {
return nil, fmt.Errorf("error parsing spec: %v", err)
}
// add block & tx to tables definition
if opts.Enabled(Block) {
for k, v := range blockTables() {
projection.Tables[k] = v
}
}
if opts.Enabled(Tx) {
for k, v := range txTables() {
projection.Tables[k] = v
}
}
return projection, nil
}
// getBlockTxTablesDefinition returns block & transaction structures
func blockTables() types.EventTables {
return types.EventTables{
tables.Block: &types.SQLTable{
Name: tables.Block,
Columns: []*types.SQLTableColumn{
{
Name: columns.Height,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: columns.BlockHeader,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
}
}
func txTables() types.EventTables {
return types.EventTables{
tables.Tx: &types.SQLTable{
Name: tables.Tx,
Columns: []*types.SQLTableColumn{
// transaction table
{
Name: columns.Height,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: columns.TxHash,
Type: types.SQLColumnTypeVarchar,
Length: txs.HashLengthHex,
Primary: true,
},
{
Name: columns.TxIndex,
Type: types.SQLColumnTypeNumeric,
Length: 0,
Primary: false,
},
{
Name: columns.TxType,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: false,
},
{
Name: columns.Envelope,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: columns.Events,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: columns.Result,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: columns.Receipt,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: columns.Exception,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
}
}