Skip to content
Snippets Groups Projects
Commit dbab0779 authored by Xavier Perret's avatar Xavier Perret
Browse files

reduced code

parent 949ea52a
No related branches found
No related tags found
Loading
...@@ -36,15 +36,9 @@ func listAllTransactionsToClient(conn net.Conn, objectStorage Blob) { ...@@ -36,15 +36,9 @@ func listAllTransactionsToClient(conn net.Conn, objectStorage Blob) {
} }
func processTransaction(serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { 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 // Convert mess to transaction
fmt.Println("Processing transaction") fmt.Println("Processing transaction")
trans.Id = body["id"].(string) trans := utilities.TranslateMessageToTransaction(mess)
trans.Receiver = body["receiver"].(string)
trans.Sender = body["sender"].(string)
trans.Amount = body["amount"].(string)
utilities.PrintTransaction(trans) utilities.PrintTransaction(trans)
database := ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage) database := ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage)
...@@ -98,12 +92,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object ...@@ -98,12 +92,7 @@ func processTransaction(serverListener net.Listener, serverConfig Config, object
fmt.Println("***********************************") fmt.Println("***********************************")
} }
func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { func processRate(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) {
var trans Transaction trans := utilities.TranslateMessageToTransaction(mess)
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)
utilities.PrintTransaction(trans) utilities.PrintTransaction(trans)
// todo change this for cloud // todo change this for cloud
...@@ -171,10 +160,7 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd ...@@ -171,10 +160,7 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd
} }
if mess.MessageType == "AckResponse" { if mess.MessageType == "AckResponse" {
var body map[string]interface{} = mess.MessageBody.(map[string]interface{}) newAck = utilities.TranslateMessageToAckTransaction(mess)
newAck.Id = body["id"].(string)
newAck.AmountOfCorrectNode = body["amountOfCorrectNode"].(int)
newAck.TotalNodes = body["totalNodes"].(int)
if ack.Id == newAck.Id { if ack.Id == newAck.Id {
ack.TotalNodes += newAck.TotalNodes ack.TotalNodes += newAck.TotalNodes
ack.AmountOfCorrectNode += newAck.AmountOfCorrectNode ack.AmountOfCorrectNode += newAck.AmountOfCorrectNode
...@@ -211,16 +197,14 @@ func vote(server net.Listener, serverConfig Config, trans Transaction, parentAdd ...@@ -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) { func processFakeRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) {
var trans Transaction trans := utilities.TranslateMessageToTransaction(mess)
var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
utilities.PrintTransaction(trans)
} }
func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) { func processVoteRequest(conn net.Conn, serverListener net.Listener, serverConfig Config, objectStorage Blob, mess Message, amIRoot bool) {
var trans Transaction trans := utilities.TranslateMessageToTransaction(mess)
var body map[string]interface{} = mess.MessageBody.(map[string]interface{})
fmt.Println("Received back a transaction")
utilities.PrintTransaction(trans) utilities.PrintTransaction(trans)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment