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

updated method name and moved utilities function to proper package

parent 107a6fef
Branches
No related tags found
1 merge request!2added file to separate client function from the server
...@@ -11,12 +11,19 @@ import ( ...@@ -11,12 +11,19 @@ import (
"log" "log"
"math/rand" "math/rand"
. "node/types" . "node/types"
. "node/utilities"
"os" "os"
"strconv" "strconv"
"time" "time"
) )
func addTransactionToBlobStorage(transaction Transaction, database Database, os Blob) Database { // AddTransactionToBlobStorage Add transaction to blob storage if it isn't in the database already and returns the database
func AddTransactionToBlobStorage(transaction Transaction, database Database, os Blob) Database {
for _, transactionInDatabase := range database {
if transactionInDatabase.Id == transaction.Id {
return database
}
}
database = append(database, transaction) database = append(database, transaction)
writeDatabaseToBlobStorage(database, os) writeDatabaseToBlobStorage(database, os)
return database return database
...@@ -33,7 +40,7 @@ func fakeTransaction(transactionToFake Transaction, fakeTransaction Transaction, ...@@ -33,7 +40,7 @@ func fakeTransaction(transactionToFake Transaction, fakeTransaction Transaction,
return database return database
} }
func readDatabaseFromBlobStorage(blob Blob) Database { func ReadDatabaseFromBlobStorage(blob Blob) Database {
ctx := context.Background() ctx := context.Background()
// Download the blob // Download the blob
...@@ -208,18 +215,6 @@ func ListBlobs(blob Blob) { ...@@ -208,18 +215,6 @@ func ListBlobs(blob Blob) {
} }
} }
func PrintingDatabaseToConsole(database Database) {
for i, trans := range database {
fmt.Println("--------------------")
fmt.Printf("\nListing transactions number %d in database\n", i)
fmt.Printf("Transaction id: %s\n", trans.Id)
fmt.Printf("Transaction sender: %s\n", trans.Sender)
fmt.Printf("Transaction receiver: %s\n", trans.Receiver)
fmt.Printf("Transaction amount: %s\n", trans.Amount)
fmt.Println("--------------------")
}
}
func TestObjectStorage() { func TestObjectStorage() {
ctx := context.Background() ctx := context.Background()
// url := "https://hepiadistributedsystems.blob.core.windows.net/" //replace <StorageAccountName> with your Azure storage account name // url := "https://hepiadistributedsystems.blob.core.windows.net/" //replace <StorageAccountName> with your Azure storage account name
...@@ -240,11 +235,11 @@ func TestObjectStorage() { ...@@ -240,11 +235,11 @@ func TestObjectStorage() {
Receiver: "1", Receiver: "1",
Amount: "1000", Amount: "1000",
} }
db = addTransactionToBlobStorage(t1, db, objectStorage) db = AddTransactionToBlobStorage(t1, db, objectStorage)
db = addTransactionToBlobStorage(t2, db, objectStorage) db = AddTransactionToBlobStorage(t2, db, objectStorage)
fmt.Println("Listing files in container") fmt.Println("Listing files in container")
db1 := readDatabaseFromBlobStorage(objectStorage) db1 := ReadDatabaseFromBlobStorage(objectStorage)
PrintingDatabaseToConsole(db1) PrintingDatabaseToConsole(db1)
fmt.Println("Press enter to continue") fmt.Println("Press enter to continue")
bufio.NewReader(os.Stdin).ReadBytes('\n') bufio.NewReader(os.Stdin).ReadBytes('\n')
...@@ -259,7 +254,7 @@ func TestObjectStorage() { ...@@ -259,7 +254,7 @@ func TestObjectStorage() {
db = fakeTransaction(t1, t3, db) db = fakeTransaction(t1, t3, db)
writeDatabaseToBlobStorage(db, objectStorage) writeDatabaseToBlobStorage(db, objectStorage)
fmt.Println("Listing files in container") fmt.Println("Listing files in container")
db2 := readDatabaseFromBlobStorage(objectStorage) db2 := ReadDatabaseFromBlobStorage(objectStorage)
PrintingDatabaseToConsole(db2) PrintingDatabaseToConsole(db2)
fmt.Println("Press enter to continue") fmt.Println("Press enter to continue")
bufio.NewReader(os.Stdin).ReadBytes('\n') bufio.NewReader(os.Stdin).ReadBytes('\n')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment