-
Notifications
You must be signed in to change notification settings - Fork 217
/
section.go
139 lines (130 loc) · 5.77 KB
/
section.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
136
137
138
139
package snapshot
import "io"
type SectionName string
const (
SectionNameChainSnapshotHeader SectionName = "eosio::chain::chain_snapshot_header"
SectionNameBlockState SectionName = "eosio::chain::block_state"
SectionNameAccountObject SectionName = "eosio::chain::account_object"
SectionNameAccountMetadataObject SectionName = "eosio::chain::account_metadata_object"
SectionNameAccountRamCorrectionObject SectionName = "eosio::chain::account_ram_correction_object"
SectionNameGlobalPropertyObject SectionName = "eosio::chain::global_property_object"
SectionNameProtocolStateObject SectionName = "eosio::chain::protocol_state_object"
SectionNameDynamicGlobalPropertyObject SectionName = "eosio::chain::dynamic_global_property_object"
SectionNameBlockSummaryObject SectionName = "eosio::chain::block_summary_object"
SectionNameTransactionObject SectionName = "eosio::chain::transaction_object"
SectionNameGeneratedTransactionObject SectionName = "eosio::chain::generated_transaction_object"
SectionNameCodeObject SectionName = "eosio::chain::code_object"
SectionNameContractTables SectionName = "contract_tables"
SectionNamePermissionObject SectionName = "eosio::chain::permission_object"
SectionNamePermissionLinkObject SectionName = "eosio::chain::permission_link_object"
SectionNameResourceLimitsObject SectionName = "eosio::chain::resource_limits::resource_limits_object"
SectionNameResourceUsageObject SectionName = "eosio::chain::resource_limits::resource_usage_object"
SectionNameResourceLimitsStateObject SectionName = "eosio::chain::resource_limits::resource_limits_state_object"
SectionNameResourceLimitsConfigObject SectionName = "eosio::chain::resource_limits::resource_limits_config_object"
SectionNameGenesisState SectionName = "eosio::chain::genesis_state"
)
func stringToSectionName(name string) SectionName {
switch name {
case "eosio::chain::chain_snapshot_header":
return SectionNameChainSnapshotHeader
case "eosio::chain::block_state":
return SectionNameBlockState
case "eosio::chain::account_object":
return SectionNameAccountObject
case "eosio::chain::account_metadata_object":
return SectionNameAccountMetadataObject
case "eosio::chain::account_ram_correction_object":
return SectionNameAccountRamCorrectionObject
case "eosio::chain::global_property_object":
return SectionNameGlobalPropertyObject
case "eosio::chain::protocol_state_object":
return SectionNameProtocolStateObject
case "eosio::chain::dynamic_global_property_object":
return SectionNameDynamicGlobalPropertyObject
case "eosio::chain::block_summary_object":
return SectionNameBlockSummaryObject
case "eosio::chain::transaction_object":
return SectionNameTransactionObject
case "eosio::chain::generated_transaction_object":
return SectionNameGeneratedTransactionObject
case "eosio::chain::code_object":
return SectionNameCodeObject
case "contract_tables":
return SectionNameContractTables
case "eosio::chain::permission_object":
return SectionNamePermissionObject
case "eosio::chain::permission_link_object":
return SectionNamePermissionLinkObject
case "eosio::chain::resource_limits::resource_limits_object":
return SectionNameResourceLimitsObject
case "eosio::chain::resource_limits::resource_usage_object":
return SectionNameResourceUsageObject
case "eosio::chain::resource_limits::resource_limits_state_object":
return SectionNameResourceLimitsStateObject
case "eosio::chain::resource_limits::resource_limits_config_object":
return SectionNameResourceLimitsConfigObject
case "eosio::chain::genesis_state":
return SectionNameGenesisState
default:
panic("unsupported section name: " + name)
}
}
type Section struct {
Name SectionName
Offset uint64
Size uint64 // This includes the section name and row count
BufferSize uint64 // This represents the bytes that are following the section header
RowCount uint64 // This is a count of rows packed in `Buffer`
Buffer io.Reader
}
// Next reads the next row
func (s *Section) Next() ([]byte, error) {
return nil, nil
}
type callbackFunc func(obj interface{}) error
func (s *Section) Process(f callbackFunc) error {
switch s.Name {
case SectionNameChainSnapshotHeader:
return s.readChainSnapshotHeader(f)
case SectionNameBlockState:
return s.readBlockState(f)
case SectionNameAccountObject:
return s.readAccountObjects(f)
case SectionNameAccountMetadataObject:
return s.readAccountMetadataObjects(f)
case SectionNameAccountRamCorrectionObject:
return s.readAccountRAMCorrectionObject(f)
case SectionNameGlobalPropertyObject:
return s.readGlobalPropertyObject(f)
case SectionNameProtocolStateObject:
return s.readProtocolStateObject(f)
case SectionNameDynamicGlobalPropertyObject:
return s.readDynamicGlobalPropertyObject(f)
case SectionNameBlockSummaryObject:
return s.readBlockSummary(f)
case SectionNameTransactionObject:
return s.readTransactionObject(f)
case SectionNameGeneratedTransactionObject:
return s.readGeneratedTransactionObject(f)
case SectionNameCodeObject:
return s.readCodeObject(f)
case SectionNameContractTables:
return s.readContractTables(f)
case SectionNamePermissionObject:
return s.readPermissionObject(f)
case SectionNamePermissionLinkObject:
return s.readPermissionLinkObject(f)
case SectionNameResourceLimitsObject:
return s.readResourceLimitsObject(f)
case SectionNameResourceUsageObject:
return s.readResourceUsageObject(f)
case SectionNameResourceLimitsStateObject:
return s.readResourceLimitsStateObject(f)
case SectionNameResourceLimitsConfigObject:
return s.readResourceLimitsConfigObject(f)
case SectionNameGenesisState:
return s.readGenesisState(f)
default:
panic("unsupported section: " + s.Name)
}
}