-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1584 from statechannels/refactor-init-functions
Refactor init functions to separate node from rpc server
- Loading branch information
Showing
6 changed files
with
127 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/statechannels/go-nitro/internal/chain" | ||
"github.com/statechannels/go-nitro/node" | ||
"github.com/statechannels/go-nitro/node/engine" | ||
"github.com/statechannels/go-nitro/node/engine/chainservice" | ||
"github.com/statechannels/go-nitro/node/engine/store" | ||
"github.com/tidwall/buntdb" | ||
|
||
p2pms "github.com/statechannels/go-nitro/node/engine/messageservice/p2p-message-service" | ||
) | ||
|
||
func InitializeNode(pkString string, chainOpts chain.ChainOpts, | ||
useDurableStore bool, durableStoreFolder string, msgPort int, logDestination *os.File, bootPeers []string, | ||
) (*node.Node, *store.Store, *p2pms.P2PMessageService, *chainservice.EthChainService, error) { | ||
if pkString == "" { | ||
panic("pk must be set") | ||
} | ||
|
||
pk := common.Hex2Bytes(pkString) | ||
ourStore, err := store.NewStore(pk, useDurableStore, durableStoreFolder, buntdb.Config{}) | ||
if err != nil { | ||
return nil, nil, nil, nil, err | ||
} | ||
|
||
slog.Info("Initializing message service on port " + fmt.Sprint(msgPort) + "...") | ||
messageService := p2pms.NewMessageService("127.0.0.1", msgPort, *ourStore.GetAddress(), pk, bootPeers) | ||
|
||
slog.Info("Initializing chain service and connecting to " + chainOpts.ChainUrl + "...") | ||
ourChain, err := chain.InitializeEthChainService(chainOpts) | ||
if err != nil { | ||
return nil, nil, nil, nil, err | ||
} | ||
|
||
node := node.New( | ||
messageService, | ||
ourChain, | ||
ourStore, | ||
&engine.PermissivePolicy{}, | ||
) | ||
|
||
return &node, &ourStore, messageService, ourChain, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters