-
Notifications
You must be signed in to change notification settings - Fork 126
/
connections.go
111 lines (106 loc) · 3.99 KB
/
connections.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
package flowhelper
import (
"errors"
"fmt"
"github.com/onflow/flow-go-sdk/client"
"google.golang.org/grpc"
)
const (
FlowAPI1 = "access-001.mainnet1.nodes.onflow.org:9000"
FlowAPI2 = "access-001.mainnet2.nodes.onflow.org:9000"
FlowAPI3 = "access-001.mainnet3.nodes.onflow.org:9000"
FlowAPI4 = "access-001.mainnet4.nodes.onflow.org:9000"
FlowAPI5 = "access-001.mainnet5.nodes.onflow.org:9000"
FlowAPI6 = "access-001.mainnet6.nodes.onflow.org:9000"
FlowAPI7 = "access-001.mainnet7.nodes.onflow.org:9000"
FlowAPI8 = "access-001.mainnet8.nodes.onflow.org:9000"
FlowAPI9 = "access-001.mainnet9.nodes.onflow.org:9000"
FlowAPI10 = "access-001.mainnet10.nodes.onflow.org:9000"
FlowAPI11 = "access-001.mainnet11.nodes.onflow.org:9000"
FlowAPI12 = "access-001.mainnet12.nodes.onflow.org:9000"
FlowAPI13 = "access-001.mainnet13.nodes.onflow.org:9000"
FlowAPI14 = "access-001.mainnet14.nodes.onflow.org:9000"
FlowAPI15 = "access-001.mainnet15.nodes.onflow.org:9000"
FlowAPI16 = "access-001.mainnet16.nodes.onflow.org:9000"
FlowAPICurrent = "access.mainnet.nodes.onflow.org:9000"
RequestLimit = uint64(249)
)
var (
RootHeight1 = uint64(7601063)
RootHeight2 = uint64(8742959)
RootHeight3 = uint64(9737133)
RootHeight4 = uint64(9992020)
RootHeight5 = uint64(12020337)
RootHeight6 = uint64(12609237)
RootHeight7 = uint64(13404174)
RootHeight8 = uint64(13950742)
RootHeight9 = uint64(14892104)
RootHeight10 = uint64(15791891)
RootHeight11 = uint64(16755602)
RootHeight12 = uint64(17544523)
RootHeight13 = uint64(18587478)
RootHeight14 = uint64(19050753)
RootHeight15 = uint64(21291692)
RootHeight16 = uint64(23830813)
RootHeightCurrent = uint64(27341470)
RootHeights = []uint64{
RootHeight1,
RootHeight2,
RootHeight3,
RootHeight4,
RootHeight5,
RootHeight6,
RootHeight7,
RootHeight8,
RootHeight9,
RootHeight10,
RootHeight11,
RootHeight12,
RootHeight13,
RootHeight14,
RootHeight15,
RootHeight16,
RootHeightCurrent,
}
)
// GetFlowClient returns a feasible client corresponding to the block's startheight.
// https://docs.onflow.org/node-operation/past-sporks/
func GetFlowClient(startheight uint64) (*client.Client, error) {
if startheight >= RootHeightCurrent {
fmt.Printf("make flow client at current level with: %s\n", FlowAPICurrent)
return client.New(FlowAPICurrent, grpc.WithInsecure())
} else if startheight >= RootHeight16 {
return client.New(FlowAPI16, grpc.WithInsecure())
} else if startheight >= RootHeight15 {
return client.New(FlowAPI15, grpc.WithInsecure())
} else if startheight >= RootHeight14 {
return client.New(FlowAPI14, grpc.WithInsecure())
} else if startheight >= RootHeight13 {
return client.New(FlowAPI13, grpc.WithInsecure())
} else if startheight >= RootHeight12 {
return client.New(FlowAPI12, grpc.WithInsecure())
} else if startheight >= RootHeight11 {
return client.New(FlowAPI11, grpc.WithInsecure())
} else if startheight >= RootHeight10 {
return client.New(FlowAPI10, grpc.WithInsecure())
} else if startheight >= RootHeight9 {
return client.New(FlowAPI9, grpc.WithInsecure())
} else if startheight >= RootHeight8 {
return client.New(FlowAPI8, grpc.WithInsecure())
} else if startheight >= RootHeight7 {
return client.New(FlowAPI7, grpc.WithInsecure())
} else if startheight >= RootHeight6 {
return client.New(FlowAPI6, grpc.WithInsecure())
} else if startheight >= RootHeight5 {
return client.New(FlowAPI5, grpc.WithInsecure())
} else if startheight >= RootHeight4 {
return client.New(FlowAPI4, grpc.WithInsecure())
} else if startheight >= RootHeight3 {
return client.New(FlowAPI3, grpc.WithInsecure())
} else if startheight >= RootHeight2 {
return client.New(FlowAPI2, grpc.WithInsecure())
} else if startheight >= RootHeight1 {
return client.New(FlowAPI1, grpc.WithInsecure())
}
return nil, errors.New("startheight too small. No client available.")
}