forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_loader.go
113 lines (102 loc) · 2.51 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
package sqlsol
import (
"fmt"
"github.com/hyperledger/burrow/txs"
"github.com/hyperledger/burrow/vent/types"
)
// SpecLoader loads spec files and parses them
func SpecLoader(specFileOrDirs []string, createBlkTxTables bool) (*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)
}
if createBlkTxTables {
// add block & tx to tables definition
blkTxTables := getBlockTxTablesDefinition()
for k, v := range blkTxTables {
projection.Tables[k] = v
}
}
return projection, nil
}
// getBlockTxTablesDefinition returns block & transaction structures
func getBlockTxTablesDefinition() types.EventTables {
return types.EventTables{
types.SQLBlockTableName: &types.SQLTable{
Name: types.SQLBlockTableName,
Columns: []*types.SQLTableColumn{
{
Name: types.SQLColumnLabelHeight,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: types.SQLColumnLabelBlockHeader,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
types.SQLTxTableName: &types.SQLTable{
Name: types.SQLTxTableName,
Columns: []*types.SQLTableColumn{
// transaction table
{
Name: types.SQLColumnLabelHeight,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: types.SQLColumnLabelTxHash,
Type: types.SQLColumnTypeVarchar,
Length: txs.HashLengthHex,
Primary: true,
},
{
Name: types.SQLColumnLabelIndex,
Type: types.SQLColumnTypeNumeric,
Length: 0,
Primary: false,
},
{
Name: types.SQLColumnLabelTxType,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: false,
},
{
Name: types.SQLColumnLabelEnvelope,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelEvents,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelResult,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelReceipt,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelException,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
}
}