11package network
22
33import (
4+ "context" // Add context import
45 "crypto/sha256"
56 "fmt"
67 "io/ioutil"
@@ -9,6 +10,7 @@ import (
910 "strings"
1011
1112 "github.com/Sifchain/sifnode/tools/sifgen/common"
13+ sifgentypes "github.com/serfersac/sifnode/tools/sifgen/common/types" // Import the common types
1214 "github.com/Sifchain/sifnode/tools/sifgen/genesis"
1315 "github.com/Sifchain/sifnode/tools/sifgen/network/types"
1416 "github.com/Sifchain/sifnode/tools/sifgen/utils"
@@ -18,11 +20,23 @@ import (
1820 "gopkg.in/yaml.v3"
1921)
2022
23+
24+
2125type Network struct {
2226 ChainID string
2327 CLI utils.CLI
2428 BondAmount string
2529 MintAmount string
30+ Provider sifgentypes.Provider // Add Provider field
31+ }
32+
33+ // NewNetwork creates a new Network instance.
34+ func NewNetwork (chainID string , provider sifgentypes.Provider ) * Network {
35+ return & Network {
36+ ChainID : chainID ,
37+ CLI : utils .NewCLI (chainID , keyring .BackendTest ),
38+ Provider : provider ,
39+ }
2640}
2741
2842func Reset (chainID , networkDir string ) error {
@@ -54,14 +68,9 @@ func Reset(chainID, networkDir string) error {
5468 return nil
5569}
5670
57- func NewNetwork (chainID string ) * Network {
58- return & Network {
59- ChainID : chainID ,
60- CLI : utils .NewCLI (chainID , keyring .BackendTest ),
61- }
62- }
6371
64- func (n * Network ) Build (count int , outputDir , seedIPv4Addr string ) (* string , error ) {
72+
73+ func (n * Network ) Build (ctx context.Context , count int , outputDir , seedIPv4Addr string ) (* string , error ) { // Added ctx
6574 if err := n .CLI .Reset ([]string {outputDir }); err != nil {
6675 return nil , err
6776 }
@@ -76,7 +85,21 @@ func (n *Network) Build(count int, outputDir, seedIPv4Addr string) (*string, err
7685 }
7786
7887 gentxDir := fmt .Sprintf ("%s/%s" , outputDir , GentxsDir )
79- validators := n .initValidators (count , outputDir , seedIPv4Addr )
88+
89+ var validators []* Validator
90+ for i := 0 ; i < count ; i ++ {
91+ nodeName := fmt .Sprintf ("sifnode-validator-%d" , i )
92+ cloudNode , err := n .Provider .CreateNode (ctx , nodeName ) // Use n.Provider
93+ if err != nil {
94+ return nil , fmt .Errorf ("failed to create cloud node %s: %w" , nodeName , err )
95+ }
96+
97+ validator := NewValidator (outputDir , n .ChainID , i == 0 , cloudNode .IP ) // Assuming first node is seed
98+ validator .Moniker = cloudNode .Name
99+ validator .IPv4Address = cloudNode .IP
100+ // Set other validator fields from cloudNode if available
101+ validators = append (validators , validator )
102+ }
80103
81104 for _ , validator := range validators {
82105 appDirs := []string {validator .NodeHomeDir }
0 commit comments