Browse Source

Transaction posting...

Arin Turpin 6 years ago
parent
commit
298aa7276b

+ 5
- 5
ZipCoinRedJavaServer/src/main/java/com/zipcoin/config/TransactionLoader.java View File

20
   @Override
20
   @Override
21
   public void run(ApplicationArguments applicationArguments){
21
   public void run(ApplicationArguments applicationArguments){
22
       Transaction[] transactions = new Transaction[]{
22
       Transaction[] transactions = new Transaction[]{
23
-              new Transaction("shivam", "khalil", 10),
24
-              new Transaction("eric", "shivam", 100),
25
-              new Transaction("khalil", "eric", (float)30.22),
26
-              new Transaction("aleena", "navya", (float)43.32),
27
-              new Transaction("shivam", "ken", 1)
23
+              new Transaction("shivam", "khalil", (double) 10f),
24
+              new Transaction("eric", "shivam", (double) 100.34f),
25
+              new Transaction("khalil", "eric", (double) 30.000),
26
+              new Transaction("aleena", "navya", (double) 43.32),
27
+              new Transaction("shivam", "ken", (double) 1f)
28
       };
28
       };
29
 
29
 
30
       for(Transaction t : transactions){
30
       for(Transaction t : transactions){

+ 2
- 2
ZipCoinRedJavaServer/src/main/java/com/zipcoin/config/WalletLoader.java View File

20
     @Override
20
     @Override
21
     public void run(ApplicationArguments applicationArguments) throws Exception {
21
     public void run(ApplicationArguments applicationArguments) throws Exception {
22
         Wallet[] wallets = new Wallet[]{
22
         Wallet[] wallets = new Wallet[]{
23
-                new Wallet("ann","34",80),
24
-                new Wallet("sen","3564",8)
23
+                new Wallet("ann","34",80.45),
24
+                new Wallet("sen","3564",8.8)
25
         };
25
         };
26
         for(Wallet wallet :wallets) {
26
         for(Wallet wallet :wallets) {
27
             this.walletRepository.save(wallet);
27
             this.walletRepository.save(wallet);

+ 12
- 17
ZipCoinRedJavaServer/src/main/java/com/zipcoin/model/Transaction.java View File

12
 
12
 
13
     @Id
13
     @Id
14
     @GeneratedValue(strategy = GenerationType.AUTO)
14
     @GeneratedValue(strategy = GenerationType.AUTO)
15
-    // private String transactionId;
15
+    private Long transactionId;
16
     private String senderPublicKey;
16
     private String senderPublicKey;
17
     private String recipientPublicKey;
17
     private String recipientPublicKey;
18
     private String transactionHash;
18
     private String transactionHash;
19
-    private Float amount;
19
+    private Double amount;
20
     //@OneToMany
20
     //@OneToMany
21
     //private List<Integer> coins;
21
     //private List<Integer> coins;
22
     //public Signature signature;
22
     //public Signature signature;
23
 
23
 
24
-    public Transaction(String senderPublicKey, String recipientPublicKey, Float amount){
24
+    public Transaction(){
25
+
26
+    }
27
+
28
+    public Transaction(String senderPublicKey, String recipientPublicKey, Double amount){
29
+        this.senderPublicKey = senderPublicKey;
30
+        this.recipientPublicKey = recipientPublicKey;
31
+        this.amount = amount;
25
 
32
 
26
     }
33
     }
27
 
34
 
33
         return recipientPublicKey;
40
         return recipientPublicKey;
34
     }
41
     }
35
 
42
 
36
-    public Float getAmount() {
43
+    public Double getAmount() {
37
         return amount;
44
         return amount;
38
     }
45
     }
39
 
46
 
40
-
41
-
42
     public void calculateAndSetHash() {
47
     public void calculateAndSetHash() {
43
-        String transactionHash = DigestUtils.sha256Hex(senderPublicKey + recipientPublicKey + Float.toString(amount));
48
+        String transactionHash = DigestUtils.sha256Hex(senderPublicKey + recipientPublicKey + Double.toString(amount));
44
         setTransactionHash(transactionHash);
49
         setTransactionHash(transactionHash);
45
     }
50
     }
46
 
51
 
48
         this.transactionHash = transactionHash;
53
         this.transactionHash = transactionHash;
49
     }
54
     }
50
 
55
 
51
-
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;
57
-//    }
58
-
59
-
60
-
61
 //    public void generateSignature(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException {
56
 //    public void generateSignature(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException {
62
 //        String data = StringUtil.getStringFromKey(sender) + StringUtil.getStringFromKey(reciepient) + Float.toString(value)    ;
57
 //        String data = StringUtil.getStringFromKey(sender) + StringUtil.getStringFromKey(reciepient) + Float.toString(value)    ;
63
 //        signature = StringUtil.applyECDSASig(privateKey,data);
58
 //        signature = StringUtil.applyECDSASig(privateKey,data);

+ 4
- 4
ZipCoinRedJavaServer/src/main/java/com/zipcoin/model/Wallet.java View File

20
     private int id;
20
     private int id;
21
     private String name;
21
     private String name;
22
     private String publicKey;
22
     private String publicKey;
23
-    private Float amount;
23
+    private Double amount;
24
 
24
 
25
     public Wallet() {
25
     public Wallet() {
26
         generateKeyPair();
26
         generateKeyPair();
27
     }
27
     }
28
 
28
 
29
-    public Wallet(String name, String publicKey, Float amount) {
29
+    public Wallet(String name, String publicKey, Double amount) {
30
         this.name=name;
30
         this.name=name;
31
         this.publicKey=publicKey;
31
         this.publicKey=publicKey;
32
         this.amount=amount;
32
         this.amount=amount;
36
         return publicKey;
36
         return publicKey;
37
     }
37
     }
38
 
38
 
39
-    public Float getAmount(){
39
+    public Double getAmount(){
40
         return amount;
40
         return amount;
41
     }
41
     }
42
 
42
 
43
-    public void setAmount(Float amount){
43
+    public void setAmount(Double amount){
44
         this.amount = amount;
44
         this.amount = amount;
45
     }
45
     }
46
 
46
 

+ 1
- 1
ZipCoinRedJavaServer/src/main/java/com/zipcoin/repository/TransactionRepository.java View File

16
 
16
 
17
 @Repository
17
 @Repository
18
 public interface TransactionRepository extends JpaRepository<Transaction, Long> {
18
 public interface TransactionRepository extends JpaRepository<Transaction, Long> {
19
-    Collection<Transaction> findTransactionBySenderOrRecipient(String sender, String recipient);
19
+    Collection<Transaction> findTransactionBySenderPublicKeyOrRecipientPublicKey(String senderPublicKey, String recipientPublicKey);
20
 }
20
 }

+ 1
- 2
ZipCoinRedJavaServer/src/main/java/com/zipcoin/service/TransactionService.java View File

33
 
33
 
34
         transaction.calculateAndSetHash();
34
         transaction.calculateAndSetHash();
35
         return transactionRepository.save(transaction);
35
         return transactionRepository.save(transaction);
36
-
37
     }
36
     }
38
 
37
 
39
     public Collection<Transaction> getAllTransactions(){
38
     public Collection<Transaction> getAllTransactions(){
41
     }
40
     }
42
 
41
 
43
     public Collection<Transaction> getTransactionsByPublicKey(String publicKey) {
42
     public Collection<Transaction> getTransactionsByPublicKey(String publicKey) {
44
-        return transactionRepository.findTransactionBySenderOrRecipient(publicKey, publicKey);
43
+        return transactionRepository.findTransactionBySenderPublicKeyOrRecipientPublicKey(publicKey, publicKey);
45
     }
44
     }
46
 
45
 
47
 
46