|
@@ -13,81 +13,50 @@ public class Transaction {
|
13
|
13
|
@Id
|
14
|
14
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
15
|
15
|
// private String transactionId;
|
16
|
|
- private Wallet sender;
|
17
|
|
- private Wallet recipient;
|
18
|
|
- private int transactionHash;
|
19
|
|
- // private String sender;
|
20
|
|
-// private String recipient;
|
|
16
|
+ private String senderPublicKey;
|
|
17
|
+ private String recipientPublicKey;
|
|
18
|
+ private String transactionHash;
|
21
|
19
|
private Float amount;
|
22
|
20
|
//@OneToMany
|
23
|
21
|
//private List<Integer> coins;
|
24
|
22
|
//public Signature signature;
|
25
|
23
|
|
26
|
|
-// public Transaction(String from, String to, float amount/*,List<Integer> coins*/) {
|
27
|
|
-// this.sender = from;
|
28
|
|
-// this.recipient = to;
|
29
|
|
-// this.amount = amount;
|
30
|
|
-// //this.coins=coins;
|
31
|
|
-// }
|
32
|
|
-
|
33
|
|
- public Transaction(){
|
|
24
|
+ public Transaction(String senderPublicKey, String recipientPublicKey, Float amount){
|
34
|
25
|
|
35
|
26
|
}
|
36
|
27
|
|
37
|
|
- public Transaction(Wallet sender, Wallet recipient, Float amount){
|
38
|
|
- this.sender = sender;
|
39
|
|
- this.recipient = recipient;
|
40
|
|
- this.amount = amount;
|
41
|
|
- this.transactionHash = (sender.toString() + recipient.toString() + amount.toString()).hashCode();
|
42
|
|
-
|
|
28
|
+ public String getSenderPublicKey() {
|
|
29
|
+ return senderPublicKey;
|
43
|
30
|
}
|
44
|
31
|
|
45
|
|
- public void transact(Wallet sender, Wallet recipient, Float amount){
|
46
|
|
- new Transaction(sender, recipient, amount);
|
47
|
|
-
|
48
|
|
- sender.setAmount(sender.getAmount() - amount);
|
49
|
|
- recipient.setAmount(recipient.getAmount() + amount);
|
|
32
|
+ public String getRecipientPublicKey() {
|
|
33
|
+ return recipientPublicKey;
|
50
|
34
|
}
|
51
|
35
|
|
|
36
|
+ public Float getAmount() {
|
|
37
|
+ return amount;
|
|
38
|
+ }
|
52
|
39
|
|
53
|
40
|
|
54
|
41
|
|
|
42
|
+ public void calculateAndSetHash() {
|
|
43
|
+ String transactionHash = DigestUtils.sha256Hex(senderPublicKey + recipientPublicKey + Float.toString(amount));
|
|
44
|
+ setTransactionHash(transactionHash);
|
|
45
|
+ }
|
55
|
46
|
|
|
47
|
+ public void setTransactionHash(String transactionHash) {
|
|
48
|
+ this.transactionHash = transactionHash;
|
|
49
|
+ }
|
56
|
50
|
|
57
|
51
|
|
58
|
|
-
|
59
|
|
-
|
60
|
|
-
|
61
|
|
-
|
62
|
|
-
|
63
|
|
-
|
64
|
|
-
|
65
|
|
-
|
66
|
|
-
|
67
|
|
-
|
68
|
|
-
|
69
|
|
-
|
70
|
|
-
|
71
|
|
-
|
72
|
|
-
|
73
|
|
-
|
74
|
|
-
|
75
|
|
-
|
76
|
|
-
|
77
|
|
-
|
78
|
|
-
|
79
|
|
-
|
80
|
|
-
|
81
|
|
-
|
82
|
|
-
|
83
|
|
-
|
84
|
|
-
|
85
|
|
-//
|
86
|
|
-// private String calculateHash() {
|
87
|
|
-// return DigestUtils.sha256Hex(sender + recipient + Float.toString(amount));
|
|
52
|
+// public Transaction(String from, String to, float amount/*,List<Integer> coins*/) {
|
|
53
|
+// this.sender = from;
|
|
54
|
+// this.recipient = to;
|
|
55
|
+// this.amount = amount;
|
|
56
|
+// //this.coins=coins;
|
88
|
57
|
// }
|
89
|
58
|
|
90
|
|
- //Above commented out by Ken
|
|
59
|
+
|
91
|
60
|
|
92
|
61
|
// public void generateSignature(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException {
|
93
|
62
|
// String data = StringUtil.getStringFromKey(sender) + StringUtil.getStringFromKey(reciepient) + Float.toString(value) ;
|