This repository has been archived by the owner on Nov 3, 2024. It is now read-only.
forked from streamingfast/bstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
55 lines (43 loc) · 1.63 KB
/
registry.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
package bstream
import (
"fmt"
)
var GetBlockReaderFactory BlockReaderFactory
var GetBlockWriterFactory BlockWriterFactory
var GetBlockDecoder BlockDecoder
var GetBlockWriterHeaderLen int
var GetProtocolFirstStreamableBlock = uint64(0)
var GetMaxNormalLIBDistance = uint64(1000)
var NormalizeBlockID = func(in string) string { // some chains have block IDs that optionally start with 0x or are case insensitive
return in
}
func ValidateRegistry() error {
if GetBlockReaderFactory == nil {
return fmt.Errorf(missingInitializationErrorMessage("GetBlockReaderFactory"))
}
if GetBlockDecoder == nil {
return fmt.Errorf(missingInitializationErrorMessage("GetBlockDecoder"))
}
if GetBlockWriterFactory == nil {
return fmt.Errorf(missingInitializationErrorMessage("GetBlockWriterFactory"))
}
if GetBlockWriterHeaderLen == 0 {
return fmt.Errorf(missingInitializationErrorMessage("GetBlockWriterHeaderLen"))
}
return nil
}
func getBlockReaderFactory() BlockReaderFactory {
if GetBlockReaderFactory == nil {
panic(missingInitializationErrorMessage("GetBlockReaderFactory"))
}
return GetBlockReaderFactory
}
func getBlockDecoder() BlockDecoder {
if GetBlockDecoder == nil {
panic(missingInitializationErrorMessage("GetBlockDecoder"))
}
return GetBlockDecoder
}
func missingInitializationErrorMessage(field string) string {
return fmt.Sprintf(`the global variable 'bstream.%s' is nil, it was not initialized correctly, you are probably missing a critical chain specific import that sets those value, usually in the form '_ "github.com/streamingfast/firehose-<chain>/types"' where '<chain>' is one of firehose supported chain`, field)
}