From 77af82ed774a08f9d0c5275f8859a0fe6297b35e Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 7 Aug 2024 19:47:38 +0700 Subject: [PATCH] Create sssc_node.go --- consensus/sssc/sssc_node.go | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 consensus/sssc/sssc_node.go diff --git a/consensus/sssc/sssc_node.go b/consensus/sssc/sssc_node.go new file mode 100644 index 000000000..11bbfa433 --- /dev/null +++ b/consensus/sssc/sssc_node.go @@ -0,0 +1,43 @@ +package sssc + +import ( + "context" + "fmt" + "log" + "sync" + + "github.com/KOSASIH/pi-nexus-autonomous-banking-network/consensus/sssc/pb" + "google.golang.org/grpc" +) + +type SSSCNode struct { + pb.UnimplementedSSSCNodeServer + shardID string + nodes map[string]*grpc.ClientConn +} + +func (n *SSSCNode) JoinShard(ctx context.Context, req *pb.JoinShardRequest) (*pb.JoinShardResponse, error) { + // TO DO: implement shard joining logic + log.Printf("Received join shard request from %s", req.NodeID) + n.nodes[req.NodeID] = req.Conn + return &pb.JoinShardResponse{Result: "success"}, nil +} + +func (n *SSSCNode) ProposeBlock(ctx context.Context, req *pb.ProposeBlockRequest) (*pb.ProposeBlockResponse, error) { + // TO DO: implement block proposal logic + log.Printf("Received propose block request from %s", req.NodeID) + return &pb.ProposeBlockResponse{Result: "success"}, nil +} + +func main() { + lis, err := net.Listen("tcp", ":50053") + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + + srv := grpc.NewServer() + pb.RegisterSSSCNodeServer(srv, &SSSCNode{shardID: "shard-1", nodes: make(map[string]*grpc.ClientConn)}) + + log.Println("SSSC node listening on port 50053") + srv.Serve(lis) +}