Fix geth port wrong for double

This commit is contained in:
Oskar Thoren 2019-04-09 12:53:18 +08:00
parent 76884be68f
commit 4025b95f85
1 changed files with 22 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"log" "log"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
@ -80,10 +81,30 @@ func getPrivateKeyFromFile(keyfile string) *ecdsa.PrivateKey {
return privateKey return privateKey
} }
/////////////////////////////////////////////////////////////////////////////
func getp2pConfig(listenaddr string) p2p.Config {
return p2p.Config{
ListenAddr: listenaddr,
MaxPeers: 25,
NAT: nat.Any(),
}
}
// Create a node // Create a node
func newNode(port int) (*node.Node, error) { func newNode(port int) (*node.Node, error) {
cfg := &node.DefaultConfig cfg := &node.DefaultConfig
cfg.DataDir = fmt.Sprintf("%s%d", ".data_", port) cfg.DataDir = fmt.Sprintf("%s%d", ".data_", port)
// XXX: Lol
if port == 9600 {
cfg.P2P = getp2pConfig(":30400")
} else if port == 9601 {
cfg.P2P = getp2pConfig(":30401")
} else {
log.Fatal("Ports be fucked up")
}
cfg.HTTPPort = port cfg.HTTPPort = port
fmt.Printf("Current data directory is %s\n", cfg.DataDir) fmt.Printf("Current data directory is %s\n", cfg.DataDir)