github.com/MetalBlockchain/metalgo@v1.11.9/genesis/validators.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package genesis
     5  
     6  import (
     7  	"encoding/json"
     8  	"fmt"
     9  
    10  	_ "embed"
    11  
    12  	"github.com/MetalBlockchain/metalgo/ids"
    13  	"github.com/MetalBlockchain/metalgo/utils/constants"
    14  	"github.com/MetalBlockchain/metalgo/utils/set"
    15  )
    16  
    17  var (
    18  	//go:embed validators.json
    19  	validatorsPerNetworkJSON []byte
    20  
    21  	validatorsPerNetwork map[string]set.Set[ids.NodeID]
    22  )
    23  
    24  func init() {
    25  	if err := json.Unmarshal(validatorsPerNetworkJSON, &validatorsPerNetwork); err != nil {
    26  		panic(fmt.Sprintf("failed to decode validators.json: %v", err))
    27  	}
    28  }
    29  
    30  // GetValidators returns recent validators for the requested network.
    31  func GetValidators(networkID uint32) set.Set[ids.NodeID] {
    32  	networkName := constants.NetworkIDToNetworkName[networkID]
    33  	return validatorsPerNetwork[networkName]
    34  }