diff --git a/app/process-connection/process-connection.go b/app/process-connection/process-connection.go index bad88b649138961645e1adeb7849be0cd9f5a58e..9e8322fcc99f0eb39c52f8df2202dd66b21c1292 100644 --- a/app/process-connection/process-connection.go +++ b/app/process-connection/process-connection.go @@ -36,15 +36,9 @@ func listAllTransactionsToClient(conn net.Conn, objectStorage Blob) { } func processTransaction(serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { - var trans Transaction - var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) - // Convert mess to transaction fmt.Println("Processing transaction") - trans.Id = body["id"].(string) - trans.Receiver = body["receiver"].(string) - trans.Sender = body["sender"].(string) - trans.Amount = body["amount"].(string) + trans := utilities.TranslateMessageToTransaction(mess) utilities.PrintTransaction(trans) database := ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage) @@ -98,12 +92,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object fmt.Println("***********************************") } func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { - var trans Transaction - var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) - trans.Id = body["id"].(string) - trans.Receiver = body["receiver"].(string) - trans.Sender = body["sender"].(string) - trans.Amount = body["amount"].(string) + trans := utilities.TranslateMessageToTransaction(mess) utilities.PrintTransaction(trans) // todo change this for cloud @@ -171,10 +160,7 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd } if mess.MessageType == "AckResponse" { - 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) + newAck = utilities.TranslateMessageToAckTransaction(mess) if ack.Id == newAck.Id { ack.TotalNodes += newAck.TotalNodes ack.AmountOfCorrectNode += newAck.AmountOfCorrectNode @@ -211,16 +197,14 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd } func processFakeRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { - var trans Transaction - var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) + trans := utilities.TranslateMessageToTransaction(mess) + utilities.PrintTransaction(trans) } func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { - var trans Transaction - var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) + trans := utilities.TranslateMessageToTransaction(mess) - fmt.Println("Received back a transaction") utilities.PrintTransaction(trans) }