Browse Source

Transactions can now have messages included

Allexit 4 years ago
parent
commit
3f233d890e

+ 3
- 2
lang-en.json View File

@@ -96,12 +96,13 @@
96 96
     ACCOUNTINFORMATION_DEBTIMPOSSIBLE: "you can not take debt.",
97 97
     ACCOUNTINFORMATION_FAILED: "Failed retrieving account information.",
98 98
     SENDTRANSACTION_HELPTEXT: "Sends some money to destined BID.",
99
-    SENDTRANSACTION_ADVANCED_HELPTEXT: "Send money with sendtransaction <bid-to> <amount>",
99
+    SENDTRANSACTION_ADVANCED_HELPTEXT: "Send money with sendtransaction <bid-to> <amount> <optional-message>",
100 100
     SENDTRANSACTION_FEW_ARGUMENTS: "Too few arguments! (see 'help sendtransaction')",
101 101
     SENDTRANSACTION_TEXT: "Attempting to complete transaction of {0} {1} to {2}..",
102 102
     TRANSACTION_SUCCESS: "Successfully transferred {0} {1} to {2}",
103 103
     TRANSACTION_FAILED: "Transfer failed to {0}, check amount and BID.",
104
-    TRANSACTION_RECEIVED: "I suddendly received {0} {1} from {2}! Thanks!",
104
+    TRANSACTION_RECEIVED_WITH_MESSAGE: "I suddendly received {0} {1} from {2} with message ''{3}''! Thanks!",
105
+    TRANSACTION_RECEIVED_WITHOUT_MESSAGE: "I suddendly received {0} {1} from {2} without message! Thanks!",
105 106
     SERVER_TRANSACTION_COMPLETE: "Completed transaction {0}.",
106 107
     SERVER_TRANSACTION_FAILED: "Transaction failed from {0}."
107 108
 }

+ 3
- 2
lang-fi.json View File

@@ -90,12 +90,13 @@
90 90
     ACCOUNTINFORMATION_DEBTIMPOSSIBLE: "pankkitili ei voi ottaa velkaa",
91 91
     ACCOUNTINFORMATION_FAILED: "Pankkitilitietojen noutaminen epäonnistui.",
92 92
     SENDTRANSACTION_HELPTEXT: "Lähettää rahaa määrätylle pankkitilille.",
93
-    SENDTRANSACTION_ADVANCED_HELPTEXT: "Lähetä rahaa komennolla 'sendtransaction <saajan-pankkitunnus> <määrä>'",
93
+    SENDTRANSACTION_ADVANCED_HELPTEXT: "Lähetä rahaa komennolla 'sendtransaction <saajan-pankkitunnus> <määrä> <valinnainen-viesti>'",
94 94
     SENDTRANSACTION_FEW_ARGUMENTS: "Liian vähän parametrejä! Kokeile 'help sendtransaction'.",
95 95
     SENDTRANSACTION_TEXT: "Yritetään viimeistellä {0} {1} lähettämistä pankkitilille {2}.",
96 96
     TRANSACTION_SUCCESS: "Onnistuneesti lähetettiin {0} {1} pankkitilille {2}.",
97 97
     TRANSACTION_FAILED: "Rahan lähetys epäonnistui pankkitilille {0}. Tarkista pankkitunnus ja rahan määrä.",
98
-    TRANSACTION_RECEIVED: "Sain satunnaisesti {0} {1} pankkitunnukselta {2}! Kiitos!",
98
+    TRANSACTION_RECEIVED_WITH_MESSAGE: "Sain satunnaisesti {0} {1} pankkitunnukselta {2} viestillä {3}! Kiitos!",
99
+    TRANSACTION_RECEIVED_WITHOUT_MESSAGE: "Sain satunnaisesti {0} {1} pankkitunnukselta {2} ilman viestiä! Kiitos!",
99 100
     SERVER_TRANSACTION_COMPLETE: "Onnistetusti siirrettiin rahaa. Siirron id: {0}.",
100 101
     SERVER_TRANSACTION_FAILED: "Pankkitunnukselta {0} saapunut rahansiirtopyyntö epäonnistui."
101 102
 }

+ 1
- 1
src/com/saltosion/neptulon/BankManager.java View File

@@ -90,7 +90,7 @@ public class BankManager {
90 90
 		Transaction transaction = 
91 91
 				new Transaction(properties.getTransactionIDLength(), 
92 92
 						transactionPackage.BIDfrom, transactionPackage.BIDto, 
93
-						transactionPackage.amount, "");
93
+						transactionPackage.amount, transactionPackage.message);
94 94
 		if (!verifyBID(transaction.bidFrom) || !verifyBID(transaction.bidTo)
95 95
                         || transaction.amount <= 0) {
96 96
 			return Problem.TRANSACTION_FAILED;

+ 1
- 0
src/com/saltosion/neptulon/ConnectionManager.java View File

@@ -185,6 +185,7 @@ public class ConnectionManager extends Listener implements PackageHandler {
185 185
             response.amount = transactionPackage.amount;
186 186
             response.BIDfrom = transactionPackage.BIDfrom;
187 187
             response.BIDto = transactionPackage.BIDto;
188
+            response.message = transactionPackage.message;
188 189
             String transactionID = bankManager.handleNewTransaction(transactionPackage);
189 190
             if (!transactionID.equals(Problem.TRANSACTION_FAILED)) {
190 191
                 response.action = TransactionAction.SUCCESS;

+ 23
- 23
src/com/saltosion/neptulon/Transaction.java View File

@@ -6,35 +6,35 @@ import java.util.Calendar;
6 6
 import java.util.Date;
7 7
 
8 8
 public class Transaction {
9
-    
10
-	private static ArrayList<String> ids = new ArrayList<String>();
11
-	
12
-	public final String id;
9
+
10
+    private static ArrayList<String> ids = new ArrayList<String>();
11
+
12
+    public final String id;
13 13
     public final String bidFrom;
14 14
     public final String bidTo;
15
-	public final String message;
15
+    public final String message;
16 16
     public final long amount;
17 17
     public final Date date = Calendar.getInstance().getTime();
18
-    
19
-    public Transaction(int idlen, String bidFrom, 
20
-			String bidTo, long amount, String message) {
18
+
19
+    public Transaction(int idlen, String bidFrom,
20
+            String bidTo, long amount, String message) {
21 21
         this.bidFrom = bidFrom;
22 22
         this.bidTo = bidTo;
23
-		this.message = message;
23
+        this.message = message;
24 24
         this.amount = amount;
25
-		id = newID(idlen);
25
+        id = newID(idlen);
26
+    }
27
+
28
+    private static String newID(int idlen) {
29
+        boolean found = false;
30
+        String str = null;
31
+        while (!found) {
32
+            str = Encrypter.getRandomHexString(idlen);
33
+            if (!ids.contains(str)) {
34
+                found = true;
35
+                ids.add(str);
36
+            }
37
+        }
38
+        return str;
26 39
     }
27
-	
28
-	private static String newID(int idlen) {
29
-		boolean found = false;
30
-		String str = null;
31
-		while (!found) {
32
-			str = Encrypter.getRandomHexString(idlen);
33
-			if (!ids.contains(str)) {
34
-				found = true;
35
-				ids.add(str);
36
-			}
37
-		}
38
-		return str;
39
-	}
40 40
 }

+ 1
- 0
src/com/saltosion/neptulon/net/packages/TransactionPackage.java View File

@@ -8,6 +8,7 @@ public class TransactionPackage extends NetPackage {
8 8
 	
9 9
 	public String BIDfrom;
10 10
 	public String BIDto;
11
+        public String message;
11 12
 	public long amount;
12 13
 	public TransactionAction action;
13 14
 	

+ 25
- 6
src/com/saltosion/neptulon/ui/ClientTBUICreator.java View File

@@ -217,6 +217,14 @@ public class ClientTBUICreator implements UICreator<TextBasedUI>, PackageHandler
217 217
                             logger.log(Level.WARNING, e.getMessage());
218 218
                             return;
219 219
                         }
220
+                        String message = "";
221
+                        if (args.size() > 2) {
222
+                            message = args.get(2);
223
+                        }
224
+                        for (int i = 3; i < args.size(); i++) {
225
+                            message += " " + args.get(i);
226
+                        }
227
+
220 228
                         logger.log(Level.INFO, Language.getText(Text.SENDTRANSACTION_TEXT),
221 229
                                 new Object[]{
222 230
                                     amount,
@@ -227,6 +235,7 @@ public class ClientTBUICreator implements UICreator<TextBasedUI>, PackageHandler
227 235
                         transaction.BIDto = bid;
228 236
                         transaction.amount = amount;
229 237
                         transaction.action = TransactionAction.SEND_TRANSACTION;
238
+                        transaction.message = message;
230 239
                         clientMain.sendPackage(transaction);
231 240
                     }
232 241
 
@@ -324,12 +333,22 @@ public class ClientTBUICreator implements UICreator<TextBasedUI>, PackageHandler
324 333
                     break;
325 334
                 }
326 335
                 case TRSANSACTION_RECEIVED: {
327
-                    logger.log(Level.INFO, Language.getText(Text.TRANSACTION_RECEIVED),
328
-                            new Object[] {
329
-                                transactionPackage.amount,
330
-                                clientMain.getBankInformation().currencySymbol,
331
-                                transactionPackage.BIDfrom
332
-                            });
336
+                    if (!transactionPackage.message.isEmpty()) {
337
+                        logger.log(Level.INFO, Language.getText(Text.TRANSACTION_RECEIVED_WITH_MESSAGE),
338
+                                new Object[]{
339
+                                    transactionPackage.amount,
340
+                                    clientMain.getBankInformation().currencySymbol,
341
+                                    transactionPackage.BIDfrom,
342
+                                    transactionPackage.message
343
+                                });
344
+                    } else {
345
+                        logger.log(Level.INFO, Language.getText(Text.TRANSACTION_RECEIVED_WITHOUT_MESSAGE),
346
+                                new Object[]{
347
+                                    transactionPackage.amount,
348
+                                    clientMain.getBankInformation().currencySymbol,
349
+                                    transactionPackage.BIDfrom
350
+                                });
351
+                    }
333 352
                 }
334 353
             }
335 354
         }

+ 2
- 1
src/com/saltosion/neptulon/util/Language.java View File

@@ -109,7 +109,8 @@ public class Language implements Json.Serializable {
109 109
 		SENDTRANSACTION_TEXT,
110 110
 		TRANSACTION_SUCCESS,
111 111
 		TRANSACTION_FAILED,
112
-                TRANSACTION_RECEIVED,
112
+                TRANSACTION_RECEIVED_WITH_MESSAGE,
113
+                TRANSACTION_RECEIVED_WITHOUT_MESSAGE,
113 114
                 SERVER_TRANSACTION_COMPLETE,
114 115
                 SERVER_TRANSACTION_FAILED
115 116
 	}