github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/cmd/machine_account.go (about)

     1  package cmd
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"path/filepath"
     7  
     8  	"github.com/onflow/flow-go/model/bootstrap"
     9  	"github.com/onflow/flow-go/model/flow"
    10  	"github.com/onflow/flow-go/utils/io"
    11  )
    12  
    13  // LoadNodeMachineAccountInfoFile loads machine account info from the default location within the
    14  // bootstrap directory - Currently being used by Collection and Consensus nodes
    15  func LoadNodeMachineAccountInfoFile(bootstrapDir string, nodeID flow.Identifier) (*bootstrap.NodeMachineAccountInfo, error) {
    16  
    17  	// attempt to read file
    18  	machineAccountInfoPath := filepath.Join(bootstrapDir, fmt.Sprintf(bootstrap.PathNodeMachineAccountInfoPriv, nodeID))
    19  	bz, err := io.ReadFile(machineAccountInfoPath)
    20  	if err != nil {
    21  		return nil, fmt.Errorf("could not read machine account info: %w", err)
    22  	}
    23  
    24  	// unmashal machine account info
    25  	var machineAccountInfo bootstrap.NodeMachineAccountInfo
    26  	err = json.Unmarshal(bz, &machineAccountInfo)
    27  	if err != nil {
    28  		return nil, fmt.Errorf("could not unmarshal machine account info: %w", err)
    29  	}
    30  
    31  	return &machineAccountInfo, nil
    32  }