github.com/koko1123/flow-go-1@v0.29.6/cmd/machine_account.go (about)

     1  package cmd
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"path/filepath"
     7  
     8  	"github.com/koko1123/flow-go-1/model/bootstrap"
     9  	"github.com/koko1123/flow-go-1/model/flow"
    10  	"github.com/koko1123/flow-go-1/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  }