github.com/diadata-org/diadata@v1.4.593/pkg/dia/helpers/flowhelper/connections.go (about)

     1  package flowhelper
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/onflow/flow-go-sdk/client"
     8  	"google.golang.org/grpc"
     9  	"google.golang.org/grpc/credentials/insecure"
    10  )
    11  
    12  const (
    13  	FlowAPI1       = "access-001.mainnet1.nodes.onflow.org:9000"
    14  	FlowAPI2       = "access-001.mainnet2.nodes.onflow.org:9000"
    15  	FlowAPI3       = "access-001.mainnet3.nodes.onflow.org:9000"
    16  	FlowAPI4       = "access-001.mainnet4.nodes.onflow.org:9000"
    17  	FlowAPI5       = "access-001.mainnet5.nodes.onflow.org:9000"
    18  	FlowAPI6       = "access-001.mainnet6.nodes.onflow.org:9000"
    19  	FlowAPI7       = "access-001.mainnet7.nodes.onflow.org:9000"
    20  	FlowAPI8       = "access-001.mainnet8.nodes.onflow.org:9000"
    21  	FlowAPI9       = "access-001.mainnet9.nodes.onflow.org:9000"
    22  	FlowAPI10      = "access-001.mainnet10.nodes.onflow.org:9000"
    23  	FlowAPI11      = "access-001.mainnet11.nodes.onflow.org:9000"
    24  	FlowAPI12      = "access-001.mainnet12.nodes.onflow.org:9000"
    25  	FlowAPI13      = "access-001.mainnet13.nodes.onflow.org:9000"
    26  	FlowAPI14      = "access-001.mainnet14.nodes.onflow.org:9000"
    27  	FlowAPI15      = "access-001.mainnet15.nodes.onflow.org:9000"
    28  	FlowAPI16      = "access-001.mainnet16.nodes.onflow.org:9000"
    29  	FlowAPICurrent = "access.mainnet.nodes.onflow.org:9000"
    30  	RequestLimit   = uint64(249)
    31  )
    32  
    33  var (
    34  	RootHeight1       = uint64(7601063)
    35  	RootHeight2       = uint64(8742959)
    36  	RootHeight3       = uint64(9737133)
    37  	RootHeight4       = uint64(9992020)
    38  	RootHeight5       = uint64(12020337)
    39  	RootHeight6       = uint64(12609237)
    40  	RootHeight7       = uint64(13404174)
    41  	RootHeight8       = uint64(13950742)
    42  	RootHeight9       = uint64(14892104)
    43  	RootHeight10      = uint64(15791891)
    44  	RootHeight11      = uint64(16755602)
    45  	RootHeight12      = uint64(17544523)
    46  	RootHeight13      = uint64(18587478)
    47  	RootHeight14      = uint64(19050753)
    48  	RootHeight15      = uint64(21291692)
    49  	RootHeight16      = uint64(23830813)
    50  	RootHeightCurrent = uint64(27341470)
    51  	RootHeights       = []uint64{
    52  		RootHeight1,
    53  		RootHeight2,
    54  		RootHeight3,
    55  		RootHeight4,
    56  		RootHeight5,
    57  		RootHeight6,
    58  		RootHeight7,
    59  		RootHeight8,
    60  		RootHeight9,
    61  		RootHeight10,
    62  		RootHeight11,
    63  		RootHeight12,
    64  		RootHeight13,
    65  		RootHeight14,
    66  		RootHeight15,
    67  		RootHeight16,
    68  		RootHeightCurrent,
    69  	}
    70  )
    71  
    72  // GetFlowClient returns a feasible client corresponding to the block's startheight.
    73  // https://docs.onflow.org/node-operation/past-sporks/
    74  func GetFlowClient(startheight uint64) (*client.Client, error) {
    75  	if startheight >= RootHeightCurrent {
    76  		fmt.Printf("make flow client at current level with: %s\n", FlowAPICurrent)
    77  		return client.New(FlowAPICurrent, grpc.WithTransportCredentials(insecure.NewCredentials()))
    78  	} else if startheight >= RootHeight16 {
    79  		return client.New(FlowAPI16, grpc.WithTransportCredentials(insecure.NewCredentials()))
    80  	} else if startheight >= RootHeight15 {
    81  		return client.New(FlowAPI15, grpc.WithTransportCredentials(insecure.NewCredentials()))
    82  	} else if startheight >= RootHeight14 {
    83  		return client.New(FlowAPI14, grpc.WithTransportCredentials(insecure.NewCredentials()))
    84  	} else if startheight >= RootHeight13 {
    85  		return client.New(FlowAPI13, grpc.WithTransportCredentials(insecure.NewCredentials()))
    86  	} else if startheight >= RootHeight12 {
    87  		return client.New(FlowAPI12, grpc.WithTransportCredentials(insecure.NewCredentials()))
    88  	} else if startheight >= RootHeight11 {
    89  		return client.New(FlowAPI11, grpc.WithTransportCredentials(insecure.NewCredentials()))
    90  	} else if startheight >= RootHeight10 {
    91  		return client.New(FlowAPI10, grpc.WithTransportCredentials(insecure.NewCredentials()))
    92  	} else if startheight >= RootHeight9 {
    93  		return client.New(FlowAPI9, grpc.WithTransportCredentials(insecure.NewCredentials()))
    94  	} else if startheight >= RootHeight8 {
    95  		return client.New(FlowAPI8, grpc.WithTransportCredentials(insecure.NewCredentials()))
    96  	} else if startheight >= RootHeight7 {
    97  		return client.New(FlowAPI7, grpc.WithTransportCredentials(insecure.NewCredentials()))
    98  	} else if startheight >= RootHeight6 {
    99  		return client.New(FlowAPI6, grpc.WithTransportCredentials(insecure.NewCredentials()))
   100  	} else if startheight >= RootHeight5 {
   101  		return client.New(FlowAPI5, grpc.WithTransportCredentials(insecure.NewCredentials()))
   102  	} else if startheight >= RootHeight4 {
   103  		return client.New(FlowAPI4, grpc.WithTransportCredentials(insecure.NewCredentials()))
   104  	} else if startheight >= RootHeight3 {
   105  		return client.New(FlowAPI3, grpc.WithTransportCredentials(insecure.NewCredentials()))
   106  	} else if startheight >= RootHeight2 {
   107  		return client.New(FlowAPI2, grpc.WithTransportCredentials(insecure.NewCredentials()))
   108  	} else if startheight >= RootHeight1 {
   109  		return client.New(FlowAPI1, grpc.WithTransportCredentials(insecure.NewCredentials()))
   110  	}
   111  	return nil, errors.New("startheight too small. No client available.")
   112  }