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

fake

parent eba6b368
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
......@@ -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)
}
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment