From fc55dcd193b4ca54fdb45103c4226fc7b60382c1 Mon Sep 17 00:00:00 2001
From: Xavier Perret <xa.perret@outlook.com>
Date: Sun, 30 Oct 2022 11:40:34 +0100
Subject: [PATCH] added more methods helpers to declutter the code

---
 app/utilities/utilities.go | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/app/utilities/utilities.go b/app/utilities/utilities.go
index 0958407..2360334 100644
--- a/app/utilities/utilities.go
+++ b/app/utilities/utilities.go
@@ -2,6 +2,7 @@ package utilities
 
 import (
 	"fmt"
+	"net"
 	. "node/types"
 )
 
@@ -83,3 +84,35 @@ func CompareTransactions(trans1 Transaction, trans2 Transaction, ack AckTransact
 
 	return newAck
 }
+
+func PrintConnection(connection net.Conn, connectionNumber int) {
+	fmt.Println("*****************************************")
+	fmt.Println("Processing client request number ", connectionNumber)
+	fmt.Println("The process-manage-connection is ", connection)
+	fmt.Println("The remote address is ", connection.RemoteAddr())
+	fmt.Println("The local address is ", connection.LocalAddr())
+	fmt.Println("*****************************************")
+}
+
+func TranslateMessageToAckTransaction(mess Message) AckTransaction {
+	var newAck AckTransaction
+
+	var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
+	newAck.Id = body["id"].(string)
+	newAck.AmountOfCorrectNode = body["amountOfCorrectNode"].(int)
+	newAck.TotalNodes = body["totalNodes"].(int)
+
+	return newAck
+}
+
+func TranslateMessageToTransaction(mess Message) Transaction {
+	var newTrans Transaction
+
+	var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
+	newTrans.Id = body["id"].(string)
+	newTrans.Sender = body["sender"].(string)
+	newTrans.Receiver = body["receiver"].(string)
+	newTrans.Amount = body["amount"].(string)
+
+	return newTrans
+}
\ No newline at end of file
-- 
GitLab