From 4a913086f33192b22cdc270d8ba36f9604b581b7 Mon Sep 17 00:00:00 2001 From: Xavier Perret <xa.perret@outlook.com> Date: Sun, 30 Oct 2022 19:00:23 +0100 Subject: [PATCH] fake --- app/command-line/userinput.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/app/command-line/userinput.go b/app/command-line/userinput.go index 30611a3..78d1f53 100644 --- a/app/command-line/userinput.go +++ b/app/command-line/userinput.go @@ -72,10 +72,13 @@ func ServerUserInputLoop(config Config, isAlsoServer bool, objectStorage Blob) { switch operation { case "1": fmt.Println("You chose to fabricate a fake transaction") - fmt.Println("You chose to fake a transaction") + fmt.Println("by giving us the id or index of the transaction you wish to modify (=fake)") + fmt.Println("we will first look for a transaction with the given id then try the index") database = ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage) utilities.PrintingDatabaseToConsole(database) - fmt.Print("\nPlease enter the index of the transaction you want to overwrite by faking:") + fmt.Print("\nPlease enter the index or id of the transaction you want to overwrite by faking:") + + database = ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage) var transID string _, err := fmt.Scanln(&transID) @@ -83,17 +86,26 @@ func ServerUserInputLoop(config Config, isAlsoServer bool, objectStorage Blob) { fmt.Println("error :", err.Error()) os.Exit(1) } - - transIDInt, err := strconv.ParseInt(transID, 10, 64) - if err != nil { - fmt.Println("error :", err.Error()) - os.Exit(1) + trans := Transaction{ + Id: transID, + Sender: "", + Receiver: "", + Amount: "", + } + trans = ObjectStorageAPI.GetTransactionInDatabaseById(objectStorage, trans) + if trans.Id == "" { + transIDInt, err := strconv.ParseInt(transID, 10, 64) + if err != nil { + fmt.Println("error :", err.Error()) + os.Exit(1) + } + trans = database[transIDInt] } tmpFakeTrans := userCreatedTransaction(config) - database = ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage) - database = ObjectStorageAPI.FakeTransaction(database[transIDInt], tmpFakeTrans, database) + database = ObjectStorageAPI.FakeTransaction(trans, tmpFakeTrans, database) ObjectStorageAPI.WriteDatabaseToBlobStorage(database, objectStorage) + database = ObjectStorageAPI.ReadDatabaseFromBlobStorage(objectStorage) fmt.Println("Database after faking:") utilities.PrintingDatabaseToConsole(database) -- GitLab