14 Commity

Autor SHA1 Wiadomość Data
  Vincent Sima ecd32bcf14 merge dev 6 lat temu
  Vincent Sima 7168e91b1f transaction is working now 6 lat temu
  Vincent Sima 54bbf15ae0 some sort of bean issue 6 lat temu
  Tennessee Gibbs 35d08b5cf0 trying to merge 6 lat temu
  yauhenip 1a598701f8 merged transaction classes 6 lat temu
  yauhenip e32e775029 transaction class completed 6 lat temu
  Vincent Sima d53f0713a8 merge dev 6 lat temu
  Vincent Sima 64ad552d75 wtf 2 6 lat temu
  Vincent Sima 2486e71d6d wtf 6 lat temu
  Vincent Sima beba9feb77 connected to outside db 6 lat temu
  yauhenip fa98d8da16 added signature methods in transaction class 6 lat temu
  yauhenip 30f5b96216 added signature methods 6 lat temu
  yauhenip 65e687ca92 added rough transaction class 6 lat temu
  yauhenip 6ee3a101fe added wallet publicKey, privateKey, generateKeyPair 6 lat temu
44 zmienionych plików z 2962 dodań i 379 usunięć
  1. 13
    0
      .idea/libraries/Maven__bouncycastle_bcprov_jdk15_136.xml
  2. 13
    0
      .idea/libraries/Maven__org_ow2_util_bundles_bouncycastle_java5_136_1_0_0.xml
  3. 13
    0
      .idea/libraries/Maven__org_springframework_spring_context_5_0_7_RELEASE2.xml
  4. 13
    0
      .idea/libraries/Maven__org_springframework_spring_core_5_0_7_RELEASE2.xml
  5. 13
    0
      .idea/libraries/Maven__org_springframework_spring_jdbc_5_0_7_RELEASE2.xml
  6. 13
    0
      .idea/misc 2.xml
  7. 8
    0
      .idea/modules 2.xml
  8. 6
    0
      .idea/vcs 2.xml
  9. 514
    253
      .idea/workspace.xml
  10. 2
    0
      0.1.iml
  11. 1833
    0
      application.log
  12. 5
    0
      pom.xml
  13. 4
    15
      src/main/java/com/buecoin01/ProcessLoader.java
  14. 2
    1
      src/main/java/com/buecoin01/Repositories/TransactionRepository.java
  15. 57
    57
      src/main/java/com/buecoin01/controller/TransactionController.java
  16. 16
    20
      src/main/java/com/buecoin01/controller/WalletController.java
  17. 28
    7
      src/main/java/com/buecoin01/model/Block.java
  18. 38
    2
      src/main/java/com/buecoin01/model/BlockchainVerification.java
  19. 0
    4
      src/main/java/com/buecoin01/model/Transaction.java
  20. 145
    0
      src/main/java/com/buecoin01/model/Transactions.java
  21. 86
    2
      src/main/java/com/buecoin01/model/Wallet.java
  22. 38
    0
      src/main/java/com/buecoin01/utility/Encryption.java
  23. 30
    0
      src/main/java/com/buecoin01/utility/TransactionInput.java
  24. 54
    0
      src/main/java/com/buecoin01/utility/TransactionOutput.java
  25. 9
    9
      src/main/resources/application.properties
  26. 9
    9
      target/classes/application.properties
  27. BIN
      target/classes/com/buecoin01/ProcessLoader.class
  28. BIN
      target/classes/com/buecoin01/Repositories/CoinRepository.class
  29. BIN
      target/classes/com/buecoin01/Repositories/TransactionRepository.class
  30. BIN
      target/classes/com/buecoin01/Repositories/WalletRepository.class
  31. BIN
      target/classes/com/buecoin01/controller/BlockController$UserController.class
  32. BIN
      target/classes/com/buecoin01/controller/BlockController.class
  33. BIN
      target/classes/com/buecoin01/controller/TransactionController$UserController.class
  34. BIN
      target/classes/com/buecoin01/controller/TransactionController.class
  35. BIN
      target/classes/com/buecoin01/controller/WalletController.class
  36. BIN
      target/classes/com/buecoin01/model/Block.class
  37. BIN
      target/classes/com/buecoin01/model/Blockchain.class
  38. BIN
      target/classes/com/buecoin01/model/BlockchainVerification.class
  39. BIN
      target/classes/com/buecoin01/model/Coin.class
  40. BIN
      target/classes/com/buecoin01/model/Transactions.class
  41. BIN
      target/classes/com/buecoin01/model/Wallet.class
  42. BIN
      target/classes/com/buecoin01/utility/Encryption.class
  43. BIN
      target/classes/com/buecoin01/utility/TransactionInput.class
  44. BIN
      target/classes/com/buecoin01/utility/TransactionOutput.class

+ 13
- 0
.idea/libraries/Maven__bouncycastle_bcprov_jdk15_136.xml Wyświetl plik

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: bouncycastle:bcprov-jdk15:136">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/bouncycastle/bcprov-jdk15/136/bcprov-jdk15-136.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/bouncycastle/bcprov-jdk15/136/bcprov-jdk15-136-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/bouncycastle/bcprov-jdk15/136/bcprov-jdk15-136-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_ow2_util_bundles_bouncycastle_java5_136_1_0_0.xml Wyświetl plik

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.ow2.util.bundles:bouncycastle-java5-136:1.0.0">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/ow2/util/bundles/bouncycastle-java5-136/1.0.0/bouncycastle-java5-136-1.0.0.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/ow2/util/bundles/bouncycastle-java5-136/1.0.0/bouncycastle-java5-136-1.0.0-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/ow2/util/bundles/bouncycastle-java5-136/1.0.0/bouncycastle-java5-136-1.0.0-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_springframework_spring_context_5_0_7_RELEASE2.xml Wyświetl plik

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.springframework:spring-context:5.0.7.RELEASE">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.7.RELEASE/spring-context-5.0.7.RELEASE.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.7.RELEASE/spring-context-5.0.7.RELEASE-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.7.RELEASE/spring-context-5.0.7.RELEASE-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_springframework_spring_core_5_0_7_RELEASE2.xml Wyświetl plik

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.springframework:spring-core:5.0.7.RELEASE">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.7.RELEASE/spring-core-5.0.7.RELEASE.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.7.RELEASE/spring-core-5.0.7.RELEASE-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.7.RELEASE/spring-core-5.0.7.RELEASE-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_springframework_spring_jdbc_5_0_7_RELEASE2.xml Wyświetl plik

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.springframework:spring-jdbc:5.0.7.RELEASE">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jdbc/5.0.7.RELEASE/spring-jdbc-5.0.7.RELEASE.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jdbc/5.0.7.RELEASE/spring-jdbc-5.0.7.RELEASE-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jdbc/5.0.7.RELEASE/spring-jdbc-5.0.7.RELEASE-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/misc 2.xml Wyświetl plik

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="MavenProjectsManager">
4
+    <option name="originalFiles">
5
+      <list>
6
+        <option value="$PROJECT_DIR$/pom.xml" />
7
+      </list>
8
+    </option>
9
+  </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
12
+  </component>
13
+</project>

+ 8
- 0
.idea/modules 2.xml Wyświetl plik

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/0.1.iml" filepath="$PROJECT_DIR$/0.1.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs 2.xml Wyświetl plik

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 514
- 253
.idea/workspace.xml
Plik diff jest za duży
Wyświetl plik


+ 2
- 0
0.1.iml Wyświetl plik

@@ -105,5 +105,7 @@
105 105
     <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.7.RELEASE" level="project" />
106 106
     <orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.0.7.RELEASE" level="project" />
107 107
     <orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.5.1" level="project" />
108
+    <orderEntry type="library" name="Maven: org.ow2.util.bundles:bouncycastle-java5-136:1.0.0" level="project" />
109
+    <orderEntry type="library" name="Maven: bouncycastle:bcprov-jdk15:136" level="project" />
108 110
   </component>
109 111
 </module>

+ 1833
- 0
application.log
Plik diff jest za duży
Wyświetl plik


+ 5
- 0
pom.xml Wyświetl plik

@@ -59,6 +59,11 @@
59 59
 			<artifactId>spring-boot-starter-test</artifactId>
60 60
 			<scope>test</scope>
61 61
 		</dependency>
62
+        <dependency>
63
+            <groupId>org.ow2.util.bundles</groupId>
64
+            <artifactId>bouncycastle-java5-136</artifactId>
65
+            <version>1.0.0</version>
66
+        </dependency>
62 67
 	</dependencies>
63 68
 
64 69
 	<build>

+ 4
- 15
src/main/java/com/buecoin01/ProcessLoader.java Wyświetl plik

@@ -2,16 +2,18 @@ package com.buecoin01;
2 2
 
3 3
 import com.buecoin01.Repositories.BlockRepository;
4 4
 import com.buecoin01.Repositories.WalletRepository;
5
+
5 6
 import org.springframework.beans.factory.annotation.Autowired;
6 7
 import org.springframework.boot.ApplicationArguments;
7 8
 import org.springframework.boot.ApplicationRunner;
8 9
 import org.springframework.stereotype.Component;
9 10
 
11
+import java.security.Security;
12
+import java.time.LocalDateTime;
13
+
10 14
 @Component
11 15
 public class ProcessLoader implements ApplicationRunner {
12 16
 
13
-    @Autowired
14
-    CoinRepository repo;
15 17
 
16 18
     @Autowired
17 19
     WalletRepository repo1;
@@ -22,19 +24,6 @@ public class ProcessLoader implements ApplicationRunner {
22 24
 
23 25
     @Override
24 26
     public void run(ApplicationArguments args) {
25
-        //CREATES COINS TO LOCALHOST DB, PROBABLY NOT GOING TO USE THIS
26
-//        for (int i = 0; i <= 100000; i++) {
27
-//            Coin b = new Coin("6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b");
28
-//            repo.save(b);
29
-//        }
30
-//
31
-        //CREATES 37 EMPTY WALLETS
32
-//        for(int i = 0; i <=37; i++){
33
-//            Wallet n = new Wallet(Encryption.applySha256(Integer.toString(i)), 0);
34
-//        }
35
-//
36
-
37
-
38 27
 
39 28
     }
40 29
 }

+ 2
- 1
src/main/java/com/buecoin01/Repositories/TransactionRepository.java Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 package com.buecoin01.Repositories;
2 2
 
3
+import com.buecoin01.model.Transactions;
3 4
 import org.springframework.data.jpa.repository.JpaRepository;
4 5
 import org.springframework.stereotype.Repository;
5 6
 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -9,5 +10,5 @@ import javax.transaction.Transaction;
9 10
 
10 11
 @CrossOrigin(origins = {"http://localhost:8100","http://localhost:8080"})
11 12
 @Repository
12
-public interface TransactionRepository extends JpaRepository<Transaction, Long> {
13
+public interface TransactionRepository extends JpaRepository<Transactions, Long> {
13 14
 }

+ 57
- 57
src/main/java/com/buecoin01/controller/TransactionController.java Wyświetl plik

@@ -1,57 +1,57 @@
1
-//package com.buecoin01.controller;
2
-//
3
-//import com.buecoin01.Repositories.TransactionRepository;
4
-//import com.buecoin01.model.Transaction;
5
-//import org.springframework.beans.factory.annotation.Autowired;
6
-//import org.springframework.http.HttpStatus;
7
-//import org.springframework.http.ResponseEntity;
8
-//import org.springframework.web.bind.annotation.*;
9
-//import java.util.Optional;
10
-//
11
-//public class TransactionController {
12
-//
13
-//    @CrossOrigin(origins = {"http://localhost:8100", "http://localhost:8080"})
14
-//    @RestController
15
-//    @RequestMapping(path = "/transaction")
16
-//
17
-//    public class UserController {
18
-//
19
-//
20
-//        @Autowired
21
-//        private TransactionRepository transactionRepository;
22
-//
23
-//        @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
24
-//        public ResponseEntity get(@PathVariable Long id) {
25
-//            Optional<Transaction> transaction = transactionRepository.findById(id);
26
-//            return new ResponseEntity <>(transaction, HttpStatus.OK );
27
-//
28
-//        }
29
-//
30
-//        @RequestMapping(value = "/users", method = RequestMethod.GET)
31
-//        public ResponseEntity <Iterable <Transaction>> getAllUsers() {
32
-//            Iterable <Transaction> allTransactions = transactionRepository.findAll();
33
-//            return new ResponseEntity <>( allTransactions, HttpStatus.OK );
34
-//
35
-//        }
36
-//
37
-//        @RequestMapping(path = "/add", method = RequestMethod.POST)
38
-//        public ResponseEntity <?> create(@RequestBody Transaction transaction) {
39
-//            transactionRepository.save(transaction);
40
-//            return new ResponseEntity <>( transaction, HttpStatus.CREATED );
41
-//        }
42
-//
43
-//        @RequestMapping(path = "/delete", method = RequestMethod.DELETE)
44
-//        public ResponseEntity <Transaction> deleteUser(@RequestBody Transaction transaction) {
45
-//            transactionRepository.delete(transaction);
46
-//            return new ResponseEntity <>( HttpStatus.OK );
47
-//        }
48
-//
49
-//        @RequestMapping(path = "/updateUser", method = RequestMethod.PUT)
50
-//        public ResponseEntity <Transaction> updateUser(@RequestBody Transaction transaction) {
51
-//            transactionRepository.save(transaction);
52
-//            return new ResponseEntity <>( HttpStatus.OK );
53
-//        }
54
-//
55
-//
56
-//    }
57
-//}
1
+package com.buecoin01.controller;
2
+
3
+import com.buecoin01.Repositories.TransactionRepository;
4
+import com.buecoin01.model.Transactions;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
9
+import java.util.Optional;
10
+
11
+public class TransactionController {
12
+
13
+    @CrossOrigin(origins = {"http://localhost:8100", "http://localhost:8080"})
14
+    @RestController
15
+    @RequestMapping(path = "/transaction")
16
+
17
+    public class UserController {
18
+
19
+
20
+        @Autowired
21
+        private TransactionRepository transactionRepository;
22
+
23
+        @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
24
+        public ResponseEntity get(@PathVariable Long id) {
25
+            Optional<Transactions> transaction = transactionRepository.findById(id);
26
+            return new ResponseEntity <>(transaction, HttpStatus.OK );
27
+
28
+        }
29
+
30
+        @RequestMapping(value = "/users", method = RequestMethod.GET)
31
+        public ResponseEntity <Iterable <Transactions>> getAllUsers() {
32
+            Iterable <Transactions> allTransactions = transactionRepository.findAll();
33
+            return new ResponseEntity <>( allTransactions, HttpStatus.OK );
34
+
35
+        }
36
+
37
+        @RequestMapping(path = "/add", method = RequestMethod.POST)
38
+        public ResponseEntity <?> create(@RequestBody Transactions transactions) {
39
+            transactionRepository.save(transactions);
40
+            return new ResponseEntity <>(transactions, HttpStatus.CREATED );
41
+        }
42
+
43
+        @RequestMapping(path = "/delete", method = RequestMethod.DELETE)
44
+        public ResponseEntity <Transactions> deleteUser(@RequestBody Transactions transactions) {
45
+            transactionRepository.delete(transactions);
46
+            return new ResponseEntity <>( HttpStatus.OK );
47
+        }
48
+
49
+        @RequestMapping(path = "/updateUser", method = RequestMethod.PUT)
50
+        public ResponseEntity <Transactions> updateUser(@RequestBody Transactions transactions) {
51
+            transactionRepository.save(transactions);
52
+            return new ResponseEntity <>( HttpStatus.OK );
53
+        }
54
+
55
+
56
+    }
57
+}

+ 16
- 20
src/main/java/com/buecoin01/controller/WalletController.java Wyświetl plik

@@ -6,55 +6,51 @@ import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8 8
 import org.springframework.web.bind.annotation.*;
9
-
10 9
 import java.util.Optional;
11 10
 
12
-public class WalletController {
13
-    @CrossOrigin(origins = {"http://localhost:8100", "http://localhost:8080"})
14
-    @RestController
15
-
16 11
 
17
-    public class UserController {
12
+@RestController
13
+@CrossOrigin(origins = {"http://localhost:8100", "http://localhost:8080"})
14
+public class WalletController {
18 15
 
19 16
 
20 17
         @Autowired
21 18
         private WalletRepository walletRepository;
22 19
 
23
-
24 20
         @RequestMapping(value = "/wallet/{id}", method = RequestMethod.GET)
25 21
         public ResponseEntity get(@PathVariable Long id) {
26
-            Optional <Wallet> wallet = walletRepository.findById( id );
27
-            return new ResponseEntity <>( wallet, HttpStatus.OK );
22
+            Optional<Wallet> wallet = walletRepository.findById(id);
23
+            return new ResponseEntity<>(wallet, HttpStatus.OK);
28 24
 
29 25
         }
30 26
 
31 27
         @RequestMapping(value = "/wallets", method = RequestMethod.GET)
32
-        public ResponseEntity <Iterable <Wallet>> getAllUsers() {
33
-            Iterable <Wallet> allWallets = walletRepository.findAll();
34
-            return new ResponseEntity <>( allWallets, HttpStatus.OK );
28
+        public ResponseEntity<Iterable<Wallet>> getAllUsers() {
29
+            Iterable<Wallet> allWallets = walletRepository.findAll();
30
+            return new ResponseEntity<>(allWallets, HttpStatus.OK);
35 31
 
36 32
         }
37 33
 
38 34
         @RequestMapping(path = "/addWallet", method = RequestMethod.POST)
39
-        public ResponseEntity <?> create(@RequestBody Wallet wallet) {
35
+        public ResponseEntity<?> create(@RequestBody Wallet wallet) {
40 36
             walletRepository.save(wallet);
41
-            return new ResponseEntity <>( wallet, HttpStatus.CREATED );
37
+            return new ResponseEntity<>(wallet, HttpStatus.CREATED);
42 38
         }
43 39
 
44 40
         @RequestMapping(path = "/deleteWallet", method = RequestMethod.DELETE)
45
-        public ResponseEntity <Wallet> deleteWallet(@RequestBody Wallet wallet) {
46
-            walletRepository.delete(wallet );
47
-            return new ResponseEntity <>( HttpStatus.OK );
41
+        public ResponseEntity<Wallet> deleteWallet(@RequestBody Wallet wallet) {
42
+            walletRepository.delete(wallet);
43
+            return new ResponseEntity<>(HttpStatus.OK);
48 44
         }
49 45
 
50 46
         @RequestMapping(path = "/updateWallet", method = RequestMethod.PUT)
51
-        public ResponseEntity <Wallet> updateWallet(@RequestBody Wallet wallet) {
47
+        public ResponseEntity<Wallet> updateWallet(@RequestBody Wallet wallet) {
52 48
             walletRepository.save(wallet);
53
-            return new ResponseEntity <>( HttpStatus.OK );
49
+            return new ResponseEntity<>(HttpStatus.OK);
54 50
         }
55 51
 
56 52
 
57 53
     }
58 54
 
59 55
 
60
-}
56
+

+ 28
- 7
src/main/java/com/buecoin01/model/Block.java Wyświetl plik

@@ -5,6 +5,7 @@ import com.buecoin01.utility.Encryption;
5 5
 
6 6
 import javax.persistence.*;
7 7
 import java.time.LocalDateTime;
8
+import java.util.ArrayList;
8 9
 
9 10
 
10 11
 @Entity
@@ -20,13 +21,19 @@ public class Block {
20 21
     @Column
21 22
     private String hash;
22 23
     private String previousHash;
23
-    private String data;
24
+    //private String data;
25
+    public String merkleRoot;
26
+    public ArrayList<Transactions> transactionList = new ArrayList<>();
24 27
     private LocalDateTime timeStamp;
25 28
     private int nonce;
26 29
 
27
-    public Block(String previousHash, LocalDateTime time) {
30
+    public Block() {
31
+    }
32
+
33
+    public Block(String previousHash, LocalDateTime time, int nonce) {
28 34
         this.timeStamp = time;
29 35
         this.previousHash = previousHash;
36
+        this.hash = calculateHash();
30 37
     }
31 38
 
32 39
     public String getHash() {
@@ -37,9 +44,9 @@ public class Block {
37 44
         return previousHash;
38 45
     }
39 46
 
40
-    public String getData() {
41
-        return data;
42
-    }
47
+//    public String getData() {
48
+//        return data;
49
+//    }
43 50
 
44 51
     public LocalDateTime getTimeStamp() {
45 52
         return timeStamp;
@@ -50,7 +57,7 @@ public class Block {
50 57
                   previousHash +
51 58
                         timeStamp.toString() +
52 59
                         Integer.toString(nonce) +
53
-                        data);
60
+                        merkleRoot);
54 61
     }
55 62
 
56 63
     public long getId() {
@@ -70,6 +77,20 @@ public class Block {
70 77
         }
71 78
         System.out.println("Block Mined " + hash);
72 79
         System.out.println("You have been awarded 1 Zip!");
73
-        Coin coin = new Coin(minerID);
80
+    }
81
+
82
+    //add transactions to this block
83
+    public boolean addTransaction(Transactions transactions){
84
+        //process transaction and check if valid, unless block is genesis block then ignore
85
+        if (transactions == null) return false;
86
+        if (previousHash != "0"){
87
+            if (!(transactions.processTransaction())){
88
+                System.out.println("Transaction failed to process. Discarded.");
89
+                return false;
90
+            }
91
+        }
92
+        transactionList.add(transactions);
93
+        System.out.println("Transaction Successfully added to the Block!");
94
+        return true;
74 95
     }
75 96
 }

+ 38
- 2
src/main/java/com/buecoin01/model/BlockchainVerification.java Wyświetl plik

@@ -2,14 +2,42 @@ package com.buecoin01.model;
2 2
 
3 3
 import com.buecoin01.model.Block;
4 4
 import com.buecoin01.utility.Encryption;
5
+import com.buecoin01.utility.TransactionOutput;
5 6
 import com.google.gson.GsonBuilder;
6 7
 
7
-import java.util.ArrayList;
8
-import java.util.List;
8
+import java.security.Security;
9
+import java.util.*;
9 10
 
10 11
 public class  BlockchainVerification {
11 12
     private static List<Block> blockchain = new ArrayList<>();
13
+    private static Map<String, TransactionOutput> UTXOs = new HashMap<>();
14
+    public static float minimumTransaction = 0.1f;
12 15
     private static int difficulty = 5;
16
+    public static Wallet walletA;
17
+    public static Wallet walletB;
18
+    //public static Transaction genesisTransaction;
19
+
20
+//    public static void main(String[] args) {
21
+//        //Setup Bouncey castle as a Security Provider
22
+//        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
23
+//
24
+//        //Create the new wallets
25
+//        walletA = new Wallet();
26
+//        walletB = new Wallet();
27
+//
28
+//        //Test public and private keys
29
+//        System.out.println("Private and public keys:");
30
+//        System.out.println(Encryption.getStringFromKey(walletA.getPrivateKey()));
31
+//        System.out.println(Encryption.getStringFromKey(walletA.getPublicKey()));
32
+//        //Create a test transaction from WalletA to walletB
33
+//        Transaction transaction = new Transaction(walletA.getPublicKey(), walletB.getPublicKey(), 5, null);
34
+//        transaction.generateSignature(walletA.getPrivateKey());
35
+//
36
+//        //Verify the signature works and verify it from the public key
37
+//        System.out.println("Is signature verified");
38
+//        System.out.println(transaction.verifySignature());
39
+
40
+ //   }
13 41
 
14 42
     public String chainToJson() {
15 43
         return new GsonBuilder()
@@ -18,6 +46,14 @@ public class  BlockchainVerification {
18 46
                 .toJson(blockchain);
19 47
     }
20 48
 
49
+    public static Map<String, TransactionOutput> getUTXOs() {
50
+        return UTXOs;
51
+    }
52
+
53
+    public static void setUTXOs(Map<String, TransactionOutput> UTXOs) {
54
+        BlockchainVerification.UTXOs = UTXOs;
55
+    }
56
+
21 57
     public static List<Block> getBlockchain() {
22 58
         return blockchain;
23 59
     }

+ 0
- 4
src/main/java/com/buecoin01/model/Transaction.java Wyświetl plik

@@ -1,4 +0,0 @@
1
-package com.buecoin01.model;
2
-
3
-public class Transaction {
4
-}

+ 145
- 0
src/main/java/com/buecoin01/model/Transactions.java Wyświetl plik

@@ -0,0 +1,145 @@
1
+package com.buecoin01.model;
2
+
3
+import com.buecoin01.utility.Encryption;
4
+import com.buecoin01.utility.TransactionInput;
5
+import com.buecoin01.utility.TransactionOutput;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.context.annotation.Bean;
8
+import org.springframework.stereotype.Component;
9
+
10
+import javax.persistence.*;
11
+import java.security.PrivateKey;
12
+import java.security.PublicKey;
13
+import java.util.ArrayList;
14
+import java.util.List;
15
+
16
+@Component
17
+@Entity
18
+public class Transactions {
19
+    @Transient
20
+    private static int sequence = 0; //how many transactions have been generated
21
+    @Transient
22
+    private List <TransactionInput> inputs = new ArrayList <>();
23
+    @Transient
24
+    private List <TransactionOutput> outputs = new ArrayList <>();
25
+    @Transient
26
+    private byte[] signature;
27
+
28
+    @Id
29
+    @Column(name = "id")
30
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
31
+    private long id;
32
+
33
+    @Column
34
+    private String transactionId; //hash of the transaction
35
+
36
+    private PublicKey sender;
37
+    private PublicKey reciepient;
38
+    private String senderName;
39
+    private String reciepientName;
40
+    private float value;
41
+    private String signature2;
42
+
43
+
44
+public Transactions(){}
45
+
46
+    public Transactions( PublicKey from, PublicKey to, float value, ArrayList <TransactionInput> inputs) {
47
+        this.sender = from;
48
+        this.reciepient = to;
49
+        this.value = value;
50
+        this.inputs = inputs;
51
+    }
52
+
53
+    //generating transactionId
54
+    private String calculateHash() {
55
+        sequence++; //increasing tho avoid identical hash codes
56
+        return Encryption.applySha256(
57
+                Encryption.getStringFromKey( sender ) +
58
+                        Encryption.getStringFromKey( reciepient ) +
59
+                        Float.toString( value ) + sequence
60
+        );
61
+    }
62
+
63
+
64
+    //WRITE METHOD TO TURN SIGNATURE DEOM BYTE ARRAY TO STRING
65
+
66
+
67
+    //Sign all the data that should not be tempered
68
+    public void generateSignature(PrivateKey privateKey) {
69
+        String data = Encryption.getStringFromKey( sender ) + Encryption.getStringFromKey( reciepient ) + Float.toString( value );
70
+        signature = Encryption.applyECDSASig( privateKey, data );
71
+    }
72
+
73
+    //Verify the data we signed hasn't been tampered with
74
+    public boolean verifySignature() {
75
+        String data = Encryption.getStringFromKey( sender ) + Encryption.getStringFromKey( reciepient ) + Float.toString( value );
76
+        return Encryption.verifyECDSASig( sender, data, signature );
77
+    }
78
+
79
+    //Check if transaction can be created
80
+    public boolean processTransaction() {
81
+        if ( !verifySignature() ) {
82
+            System.out.println( "Transaction Signature failed to verify" );
83
+            return false;
84
+        }
85
+
86
+        //gather transaction inputs to make sure they're unspent
87
+        for (TransactionInput i : inputs) {
88
+            i.setUTXO( BlockchainVerification.getUTXOs().get( i.getTransactionOutputId() ) );
89
+
90
+        }
91
+        //check if transaction is valid
92
+        if ( getInputsValue() <  BlockchainVerification.minimumTransaction ) {
93
+            System.out.println( "Transaction Input to small: " + getInputsValue() );
94
+            return false;
95
+        }
96
+        //add outputs to Unspent list
97
+        for (TransactionOutput o : outputs) {
98
+            BlockchainVerification.getUTXOs().put( o.getId(), o );
99
+        }
100
+        //remove transaction inputs from UXTO lists as spent
101
+        for (TransactionInput i : inputs) {
102
+            if ( i.getUTXO() == null ) continue; // if Transaction cant be found, skip
103
+            BlockchainVerification.getUTXOs().remove( i.getUTXO().getId() );
104
+        }
105
+        return true;
106
+    }
107
+
108
+    // returns sum of inputs(UXTOs) values
109
+    public float getInputsValue() {
110
+        float total = 0;
111
+        for (TransactionInput i : inputs) {
112
+            if ( i.getUTXO() == null ) continue; // if Transaction cant be found, skip
113
+            total = total + i.getUTXO().getValue();
114
+        }
115
+        return total;
116
+    }
117
+
118
+    public float getOutPutsValue() {
119
+        float total = 0;
120
+        for (TransactionOutput o : outputs) {
121
+            total = total + o.getValue();
122
+        }
123
+        return total;
124
+    }
125
+
126
+    // tacks in array of transactions and returns a merkle root
127
+    public static String getMerkleRoot(ArrayList <Transactions> transactions) {
128
+        int count = transactions.size();
129
+        ArrayList <String> previousTreeLayer = new ArrayList <>();
130
+        for (Transactions transaction : transactions) {
131
+            previousTreeLayer.add( transaction.transactionId );
132
+        }
133
+        ArrayList <String> treeLayer = previousTreeLayer;
134
+        while (count > 1) {
135
+            treeLayer = new ArrayList <>();
136
+            for (int i = 1; i < previousTreeLayer.size(); i++) {
137
+                treeLayer.add( Encryption.applySha256( previousTreeLayer.get( i - 1 ) ) + previousTreeLayer.get( i ) );
138
+            }
139
+            count = treeLayer.size();
140
+            previousTreeLayer = treeLayer;
141
+        }
142
+        String merkleRoot = ( treeLayer.size() == 1 ) ? treeLayer.get( 0 ) : "";
143
+        return merkleRoot;
144
+    }
145
+}

+ 86
- 2
src/main/java/com/buecoin01/model/Wallet.java Wyświetl plik

@@ -1,28 +1,58 @@
1 1
 package com.buecoin01.model;
2 2
 
3
+import com.buecoin01.utility.TransactionInput;
4
+import com.buecoin01.utility.TransactionOutput;
5
+
3 6
 import javax.persistence.*;
7
+import java.security.*;
8
+import java.util.ArrayList;
9
+import java.util.HashMap;
10
+import java.util.Map;
4 11
 
5 12
 @Entity
6 13
 public class Wallet {
14
+
15
+    private PrivateKey privateKey;
16
+    private PublicKey publicKey;
17
+    public HashMap<String, TransactionOutput> UTXOs = new HashMap<>(); // only UTXOs owned by this wallet
7 18
     @Id
8 19
     @Column(name = "id")
9 20
     @GeneratedValue(strategy = GenerationType.IDENTITY)
10 21
     private long id;
11
-
12 22
     @Column(name = "pubicId")
13 23
     private String publicId;
14 24
     @Column(name = "amount")
15 25
     private long amount;
26
+    @Column(name = "name")
27
+    private String name;
16 28
 
17 29
 
18
-    public Wallet(String publicId, long amount) {
30
+    public Wallet(String publicId, long amount, String name) {
19 31
         this.publicId = publicId;
20 32
         this.amount = amount;
33
+        this.name = name;
34
+    }
35
+
36
+    public String getName() {
37
+        return name;
38
+    }
39
+
40
+    public void setName(String name) {
41
+        this.name = name;
21 42
     }
22 43
 
23 44
     public Wallet() {
45
+        //generateKeyPair();
46
+    }
47
+
48
+    public PrivateKey getPrivateKey() {
49
+        return privateKey;
50
+    }
24 51
 
52
+    public PublicKey getPublicKey() {
53
+        return publicKey;
25 54
     }
55
+
26 56
     public long getAmount() {
27 57
         return amount;
28 58
     }
@@ -48,4 +78,58 @@ public class Wallet {
48 78
     public void setId(long id) {
49 79
         this.id = id;
50 80
     }
81
+
82
+//    public void generateKeyPair() {
83
+//        try {
84
+//            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA","BC");
85
+//            SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
86
+//            ECGenParameterSpec ecSpec = new ECGenParameterSpec("prime192v1");
87
+//
88
+//            keyGen.initialize(ecSpec, random);
89
+//            KeyPair keyPair = keyGen.generateKeyPair();
90
+//            privateKey = keyPair.getPrivate();
91
+//            publicKey = keyPair.getPublic();
92
+//        } catch(Exception e) {
93
+//            throw new RuntimeException(e);
94
+//        }
95
+//    }
96
+    //returns balance and store the UTXO's owned by this wallet in this.UXTOs
97
+    public float getBalance(){
98
+        float total = 0;
99
+        for (Map.Entry<String, TransactionOutput> item: BlockchainVerification.getUTXOs().entrySet()){
100
+            TransactionOutput UTXO = item.getValue();
101
+            if (UTXO.isMine(publicKey)){ //if output belongs to me (if coins belong to me)
102
+                UTXOs.put(UTXO.getId(), UTXO);   // add it to our list of unspent transaction
103
+                total = total + UTXO.getValue();
104
+
105
+            }
106
+        }
107
+        return total;
108
+    }
109
+
110
+    //generates and returns a new transaction from this wallet
111
+
112
+
113
+    public Transactions sendFunds(PublicKey _recipient, float value){
114
+        if(getBalance() < value) {  //gather balance and check funds
115
+            System.out.println("Not Enough Funds. Transaction Discarded.");
116
+            return null;
117
+       }
118
+
119
+       // create arraylist of inputs
120
+        ArrayList<TransactionInput> inputs = new ArrayList<>();
121
+        float total = 0;
122
+        for(Map.Entry<String, TransactionOutput> item: UTXOs.entrySet()){
123
+            TransactionOutput UTXO = item.getValue();
124
+            total= total + UTXO.getValue();
125
+            inputs.add(new TransactionInput(UTXO.getId()));
126
+            if (total > value) break;
127
+        }
128
+        Transactions newTransactions = new Transactions(publicKey, _recipient,value, inputs);
129
+        newTransactions.generateSignature(privateKey);
130
+        for (TransactionInput input : inputs){
131
+            UTXOs.remove(input.getTransactionOutputId());
132
+        }
133
+        return newTransactions;
134
+    }
51 135
 }

+ 38
- 0
src/main/java/com/buecoin01/utility/Encryption.java Wyświetl plik

@@ -3,6 +3,11 @@ package com.buecoin01.utility;
3 3
 import com.google.common.hash.Hashing;
4 4
 
5 5
 import java.nio.charset.StandardCharsets;
6
+import java.security.Key;
7
+import java.security.PrivateKey;
8
+import java.security.PublicKey;
9
+import java.security.Signature;
10
+import java.util.Base64;
6 11
 
7 12
 public class Encryption {
8 13
     public static String applySha256(String input) {
@@ -14,4 +19,37 @@ public class Encryption {
14 19
     public static String createTarget(int difficulty) {
15 20
         return new String(new char[difficulty]).replace('\0', '0');
16 21
     }
22
+
23
+    //Apply ECDSA Signature and return result as bytes
24
+    public static byte[] applyECDSASig(PrivateKey privateKey, String input) {
25
+        Signature dsa;
26
+        byte[] realSig;
27
+        try {
28
+            dsa = Signature.getInstance("ECDSA","BC");
29
+            dsa.initSign(privateKey);
30
+            byte[] strByte = input.getBytes();
31
+            dsa.update(strByte);
32
+            realSig = dsa.sign();
33
+        } catch (Exception e) {
34
+            throw new RuntimeException(e);
35
+        }
36
+        return realSig;
37
+    }
38
+
39
+    //Verify a String Signature
40
+    public static boolean verifyECDSASig(PublicKey publicKey, String data, byte[] signature) {
41
+        try {
42
+            Signature ecdsaVerify = Signature.getInstance("ECDSA", "BC");
43
+            ecdsaVerify.initVerify(publicKey);
44
+            ecdsaVerify.update(data.getBytes());
45
+            return  ecdsaVerify.verify(signature);
46
+        } catch (Exception e) {
47
+            throw new RuntimeException(e);
48
+        }
49
+    }
50
+
51
+    //Return encoded string from a key
52
+    public static String getStringFromKey(Key key) {
53
+        return Base64.getEncoder().encodeToString(key.getEncoded());
54
+    }
17 55
 }

+ 30
- 0
src/main/java/com/buecoin01/utility/TransactionInput.java Wyświetl plik

@@ -0,0 +1,30 @@
1
+package com.buecoin01.utility;
2
+
3
+
4
+//This class will be used to reference TransactionOutputs that have not yet been spent.
5
+//The transactionOutputId will be used to find the relevant TransactionOutput, allowing miners to check your ownership.
6
+public class TransactionInput {
7
+    private String transactionOutputId;
8
+   // private TransactionOutput UTXO; // UTXO means Unspent Transaction Outputs
9
+   private TransactionOutput UTXO;
10
+
11
+    public TransactionInput(String transactionOutputId) {
12
+        this.transactionOutputId = transactionOutputId;
13
+    }
14
+
15
+    public String getTransactionOutputId() {
16
+        return transactionOutputId;
17
+    }
18
+
19
+    public void setTransactionOutputId(String transactionOutputId) {
20
+        this.transactionOutputId = transactionOutputId;
21
+    }
22
+
23
+    public TransactionOutput getUTXO() {
24
+        return UTXO;
25
+    }
26
+
27
+    public void setUTXO(TransactionOutput UTXO) {
28
+        this.UTXO = UTXO;
29
+    }
30
+}

+ 54
- 0
src/main/java/com/buecoin01/utility/TransactionOutput.java Wyświetl plik

@@ -0,0 +1,54 @@
1
+package com.buecoin01.utility;
2
+
3
+import java.security.PublicKey;
4
+
5
+public class TransactionOutput {
6
+    private String id;
7
+    private PublicKey reciepient; //new owner of the coins
8
+    private float value; //the amount of coins they own
9
+    private String parentTransactionId;
10
+
11
+    public TransactionOutput(PublicKey reciepient, float value, String parentTransactionId) {
12
+        this.reciepient = reciepient;
13
+        this.value = value;
14
+        this.parentTransactionId = parentTransactionId;
15
+        this.id = Encryption.applySha256(Encryption.getStringFromKey(reciepient)+Float.toString(value)+parentTransactionId);
16
+    }
17
+
18
+    public String getId() {
19
+        return id;
20
+    }
21
+
22
+    public void setId(String id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public PublicKey getReciepient() {
27
+        return reciepient;
28
+    }
29
+
30
+    public void setReciepient(PublicKey reciepient) {
31
+        this.reciepient = reciepient;
32
+    }
33
+
34
+    public float getValue() {
35
+        return value;
36
+    }
37
+
38
+    public void setValue(float value) {
39
+        this.value = value;
40
+    }
41
+
42
+    public String getParentTransactionId() {
43
+        return parentTransactionId;
44
+    }
45
+
46
+    public void setParentTransactionId(String parentTransactionId) {
47
+        this.parentTransactionId = parentTransactionId;
48
+    }
49
+
50
+    //Check if coin belongs to publicKey
51
+    public boolean isMine(PublicKey publicKey) {
52
+        return publicKey == reciepient;
53
+    }
54
+}

+ 9
- 9
src/main/resources/application.properties Wyświetl plik

@@ -1,11 +1,11 @@
1 1
 spring.jpa.hibernate.ddl-auto=update
2
-spring.datasource.url=jdbc:mysql://localhost:3306/bluecoin?useSSL=false
2
+spring.datasource.url=jdbc:mysql://167.99.50.8:3306/bitcoin?useSSL=false
3 3
 spring.datasource.username=root
4
-spring.datasource.password=
5
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
6
-spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
7
-spring.datasource.testWhileIdle = true
8
-spring.datasource.validationQuery = SELECT 1
9
-
10
-
11
-logging.file= ./application.log
4
+spring.datasource.password=098poilkj
5
+#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
6
+#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
7
+#spring.datasource.testWhileIdle = true
8
+#spring.datasource.validationQuery = SELECT 1
9
+#
10
+#
11
+#logging.file= ./application.log

+ 9
- 9
target/classes/application.properties Wyświetl plik

@@ -1,11 +1,11 @@
1 1
 spring.jpa.hibernate.ddl-auto=update
2
-spring.datasource.url=jdbc:mysql://localhost:3306/bluecoin?useSSL=false
2
+spring.datasource.url=jdbc:mysql://167.99.50.8:3306/bitcoin?useSSL=false
3 3
 spring.datasource.username=root
4
-spring.datasource.password=
5
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
6
-spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
7
-spring.datasource.testWhileIdle = true
8
-spring.datasource.validationQuery = SELECT 1
9
-
10
-
11
-logging.file= ./application.log
4
+spring.datasource.password=098poilkj
5
+#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
6
+#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
7
+#spring.datasource.testWhileIdle = true
8
+#spring.datasource.validationQuery = SELECT 1
9
+#
10
+#
11
+#logging.file= ./application.log

BIN
target/classes/com/buecoin01/ProcessLoader.class Wyświetl plik


BIN
target/classes/com/buecoin01/Repositories/CoinRepository.class Wyświetl plik


BIN
target/classes/com/buecoin01/Repositories/TransactionRepository.class Wyświetl plik


BIN
target/classes/com/buecoin01/Repositories/WalletRepository.class Wyświetl plik


BIN
target/classes/com/buecoin01/controller/BlockController$UserController.class Wyświetl plik


BIN
target/classes/com/buecoin01/controller/BlockController.class Wyświetl plik


BIN
target/classes/com/buecoin01/controller/TransactionController$UserController.class Wyświetl plik


BIN
target/classes/com/buecoin01/controller/TransactionController.class Wyświetl plik


BIN
target/classes/com/buecoin01/controller/WalletController.class Wyświetl plik


BIN
target/classes/com/buecoin01/model/Block.class Wyświetl plik


BIN
target/classes/com/buecoin01/model/Blockchain.class Wyświetl plik


BIN
target/classes/com/buecoin01/model/BlockchainVerification.class Wyświetl plik


BIN
target/classes/com/buecoin01/model/Coin.class Wyświetl plik


BIN
target/classes/com/buecoin01/model/Transactions.class Wyświetl plik


BIN
target/classes/com/buecoin01/model/Wallet.class Wyświetl plik


BIN
target/classes/com/buecoin01/utility/Encryption.class Wyświetl plik


BIN
target/classes/com/buecoin01/utility/TransactionInput.class Wyświetl plik


BIN
target/classes/com/buecoin01/utility/TransactionOutput.class Wyświetl plik