-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionThread.java
More file actions
70 lines (55 loc) · 1.96 KB
/
TransactionThread.java
File metadata and controls
70 lines (55 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.security.PublicKey;
import java.util.Iterator;
public class TransactionThread extends Thread implements Serializable{
String rcvID;
float sendValue;
static MemberInfo memberInfo;
TransactionThread(MemberInfo memberInfo){
System.out.println("Transaction Node Start...");
this.memberInfo = memberInfo;
}
public void run() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
try {
while(true) {
System.out.println(">>Enter ID of MemberNode you want to send to.");
rcvID = bufferedReader.readLine();
System.out.println(">>Enter How much Coins you want to send");
sendValue = Float.parseFloat(bufferedReader.readLine());
TransactionInfo transactionInfo = new TransactionInfo(rcvID, sendValue);
boolean flag = send_Transaction(transactionInfo);
if(flag)
System.out.println("Transaction Succecced");
else
System.out.println("Transaction Failed");
}
}catch(Exception e) {
e.printStackTrace();
}
}
private static boolean send_Transaction(TransactionInfo transactionInfo) {
try {
Socket consortiumSocket = new Socket(memberInfo.getConsortiumIp(), memberInfo.getConsortiumPort());
ObjectOutputStream out = new ObjectOutputStream(consortiumSocket.getOutputStream());
ObjectInputStream in = new ObjectInputStream(consortiumSocket.getInputStream());
out.writeObject(transactionInfo);
/*Transaction tr = new Transaction(memberInfo.getId(),
transactionInfo.getRcvId(),
memberInfo.getWallet().publicKey,
transactionInfo.getFundValue());
(PublicKey)in.readObject(),*/
consortiumSocket.close();
return (boolean)in.readObject();
}catch(Exception e) {
System.out.println(e);
}
return false;
}
}