-
Notifications
You must be signed in to change notification settings - Fork 178
/
machine_account.go
32 lines (26 loc) · 1.03 KB
/
machine_account.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
package cmd
import (
"encoding/json"
"fmt"
"path/filepath"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/io"
)
// LoadNodeMachineAccountInfoFile loads machine account info from the default location within the
// bootstrap directory - Currently being used by Collection and Consensus nodes
func LoadNodeMachineAccountInfoFile(bootstrapDir string, nodeID flow.Identifier) (*bootstrap.NodeMachineAccountInfo, error) {
// attempt to read file
machineAccountInfoPath := filepath.Join(bootstrapDir, fmt.Sprintf(bootstrap.PathNodeMachineAccountInfoPriv, nodeID))
bz, err := io.ReadFile(machineAccountInfoPath)
if err != nil {
return nil, fmt.Errorf("could not read machine account info: %w", err)
}
// unmashal machine account info
var machineAccountInfo bootstrap.NodeMachineAccountInfo
err = json.Unmarshal(bz, &machineAccountInfo)
if err != nil {
return nil, fmt.Errorf("could not unmarshal machine account info: %w", err)
}
return &machineAccountInfo, nil
}