Bläddra i källkod

hope this works

Arin Turpin 6 år sedan
förälder
incheckning
8abc4b3027

+ 65
- 11
ZipCoinRedJavaServer/src/main/java/com/zipcoin/model/Transaction.java Visa fil

@@ -12,29 +12,83 @@ public class Transaction {
12 12
 
13 13
     @Id
14 14
     @GeneratedValue(strategy = GenerationType.AUTO)
15
-    private Long transactionId;
16
-    private String sender;
17
-    private String recipient;
18
-    private float amount;
15
+    // private String transactionId;
16
+    private Wallet sender;
17
+    private Wallet recipient;
18
+    private int transactionHash;
19
+    //    private String sender;
20
+//    private String recipient;
21
+    private Float amount;
19 22
     //@OneToMany
20 23
     //private List<Integer> coins;
21 24
     //public Signature signature;
22 25
 
23
-    public Transaction() {
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 34
 
25 35
     }
26 36
 
27
-    public Transaction(String from, String to, float amount/*,List<Integer> coins*/) {
28
-        this.sender = from;
29
-        this.recipient = to;
37
+    public Transaction(Wallet sender, Wallet recipient, Float amount){
38
+        this.sender = sender;
39
+        this.recipient = recipient;
30 40
         this.amount = amount;
31
-        //this.coins=coins;
41
+        this.transactionHash = (sender.toString() + recipient.toString() + amount.toString()).hashCode();
42
+
32 43
     }
33 44
 
34
-    private String calculateHash() {
35
-        return DigestUtils.sha256Hex(sender + recipient + Float.toString(amount));
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);
36 50
     }
37 51
 
52
+
53
+
54
+
55
+
56
+
57
+
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));
88
+//    }
89
+
90
+    //Above commented out by Ken
91
+
38 92
 //    public void generateSignature(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException {
39 93
 //        String data = StringUtil.getStringFromKey(sender) + StringUtil.getStringFromKey(reciepient) + Float.toString(value)    ;
40 94
 //        signature = StringUtil.applyECDSASig(privateKey,data);

+ 13
- 1
ZipCoinRedJavaServer/src/main/java/com/zipcoin/model/Wallet.java Visa fil

@@ -32,6 +32,18 @@ public class Wallet {
32 32
         this.amount=amount;
33 33
     }
34 34
 
35
+    public String getPublicKey(){
36
+        return publicKey;
37
+    }
38
+
39
+    public Double getAmount(){
40
+        return amount;
41
+    }
42
+
43
+    public void setAmount(Double x){
44
+        amount = amount + x;
45
+    }
46
+
35 47
     public void generateKeyPair() {
36 48
         Random random =new SecureRandom();
37 49
         Integer random10digit= random.nextInt(10);
@@ -56,4 +68,4 @@ public class Wallet {
56 68
 //        }
57 69
     }
58 70
 
59
-}
71
+}