skyfffire 2 жил өмнө
parent
commit
e9fc38a1f7
2 өөрчлөгдсөн 16 нэмэгдсэн , 3 устгасан
  1. 8 2
      cmd/p2p/main.go
  2. 8 1
      p2p/server.go

+ 8 - 2
cmd/p2p/main.go

@@ -1,9 +1,15 @@
 package main
 
-import "blockchain-go/p2p"
+import (
+	"blockchain-go/p2p"
+	"github.com/ethereum/go-ethereum/crypto"
+)
 
 func main() {
-	server := &p2p.Server{}
+	key, _ := crypto.GenerateKey()
+	server := &p2p.Server{
+		Config: p2p.Config{PrivateKey: key},
+	}
 
 	err := server.Start()
 	if err != nil {

+ 8 - 1
p2p/server.go

@@ -3,6 +3,7 @@ package p2p
 import (
 	"errors"
 	"fmt"
+	"github.com/ethereum/go-ethereum/crypto"
 	"sync"
 )
 
@@ -13,7 +14,7 @@ var (
 // Server manages all peer connections.
 type Server struct {
 	// Config fields may not be modified while the server is running.
-	//Config
+	Config
 
 	// Hooks for testing. These are useful because we can inhibit
 	// the whole protocol stack.
@@ -56,3 +57,9 @@ func (srv *Server) Start() (err error) {
 
 	return nil
 }
+
+func (srv *Server) setupLocalNode() (err error) {
+	_ = crypto.FromECDSAPub(&srv.PrivateKey.PublicKey)
+
+	return nil
+}