Compare commits
32 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a2fc218e1d | ||
![]() |
2fbfb9e218 | ||
![]() |
457c245fe5 | ||
![]() |
1ca0ea5069 | ||
![]() |
05b1827450 | ||
![]() |
c663dd5050 | ||
![]() |
2ede4c231c | ||
![]() |
584349e931 | ||
![]() |
5b66b6723c | ||
![]() |
6f88238309 | ||
![]() |
23e8ef5b1f | ||
![]() |
8bee24167c | ||
![]() |
199d122038 | ||
![]() |
4c7a65816d | ||
![]() |
f51df72704 | ||
![]() |
4f794b5bca | ||
![]() |
a50e07535c | ||
![]() |
618fa237d0 | ||
![]() |
75ba178cee | ||
![]() |
cdaf81b99d | ||
![]() |
80328999bc | ||
![]() |
2c5ef6ce29 | ||
![]() |
097d6f2d4e | ||
![]() |
18f679ff6e | ||
![]() |
501b0e4760 | ||
![]() |
f8308dff09 | ||
![]() |
217e70403b | ||
![]() |
c604474acf | ||
![]() |
2d51032d0f | ||
![]() |
04ee63a569 | ||
![]() |
82e362cacd | ||
![]() |
08d9db12aa |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -81,3 +81,4 @@ fabric.properties
|
|||
|
||||
|
||||
# End of https://www.gitignore.io/api/intellij
|
||||
target/
|
||||
|
|
124
.idea/uiDesigner.xml
Normal file
124
.idea/uiDesigner.xml
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
1064
.idea/workspace.xml
Normal file
1064
.idea/workspace.xml
Normal file
File diff suppressed because it is too large
Load diff
2
cmd.txt
2
cmd.txt
|
@ -1 +1 @@
|
|||
mvn package && java -jar target/java-api-1.0.jar
|
||||
mvn package && java -jar target/java-api-0.1.jar
|
Binary file not shown.
Binary file not shown.
30
pom.xml
30
pom.xml
|
@ -8,6 +8,8 @@
|
|||
<artifactId>java-api</artifactId>
|
||||
<version>0.1</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
|
@ -34,6 +36,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-crypto</artifactId>
|
||||
</dependency>
|
||||
<!-- ***** -->
|
||||
|
||||
<!-- LOGGER AND TEST DEPENDENCIES -->
|
||||
|
@ -56,8 +62,29 @@
|
|||
<version>1.60</version>
|
||||
</dependency>
|
||||
<!-- ***** -->
|
||||
|
||||
<!-- ORMLITE - POSTGRE -->
|
||||
<dependency>
|
||||
<groupId>com.j256.ormlite</groupId>
|
||||
<artifactId>ormlite-core</artifactId>
|
||||
<version>5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.j256.ormlite</groupId>
|
||||
<artifactId>ormlite-jdbc</artifactId>
|
||||
<version>5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.5</version>
|
||||
</dependency>
|
||||
<!-- ***** -->
|
||||
</dependencies>
|
||||
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
@ -67,6 +94,9 @@
|
|||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<executable>true</executable>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
387
postman/JAVA-API.postman_collection.json
Normal file
387
postman/JAVA-API.postman_collection.json
Normal file
|
@ -0,0 +1,387 @@
|
|||
{
|
||||
"info": {
|
||||
"_postman_id": "6f868823-1ce1-4139-ba21-60eca129d008",
|
||||
"name": "JAVA-API",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "Transaction",
|
||||
"item": [
|
||||
{
|
||||
"name": "getTransaction",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/transaction/get?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG&transactionHash=TESTGFJDOOJI3285941981FDSDSFSSDGxxdsfz",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"get"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
},
|
||||
{
|
||||
"key": "transactionHash",
|
||||
"value": "TESTGFJDOOJI3285941981FDSDSFSSDGxxdsfz"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "getLatestTransaction",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/transaction/getLatest?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"getLatest"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "getAllTransaction",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/transaction/getAll?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"getAll"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "saveTransaction",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n\t\"transactionFrom\":\"$2a$10$jviPGl4mc1nGOp4hZUyOmeFqFWlQB7mvFToWPGUiq8W5Z1LZP3e4C\",\r\n\t\"transactionTo\":\"$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG\",\r\n\t\"transactionHash\":\"TESTGFJDOOJI3285941981FDSDSFSSDGxxdsfz\",\r\n\t\"transactionAmount\":1.50,\r\n\t\"transactionUnit\":\"Gonettes\"\r\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/transaction/save",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"save"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "sentTransactions",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/transaction/sent?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"sent"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "receivedTransaction",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/transaction/received?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"received"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Server",
|
||||
"item": [
|
||||
{
|
||||
"name": "get sent transactions",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://37.187.101.44:10053/api/rest/transaction/sent?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"37",
|
||||
"187",
|
||||
"101",
|
||||
"44"
|
||||
],
|
||||
"port": "10053",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"transaction",
|
||||
"sent"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "FirstTest",
|
||||
"item": [
|
||||
{
|
||||
"name": "getBalance",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:10053/api/rest/query/balance?userHash=$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "10053",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"query",
|
||||
"balance"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "userHash",
|
||||
"value": "$2a$10$tEogSW32MJQGqt1qO8MZB.rONrEDjKD9u8szelMpZSAUzlt7rEYOG"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Login",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n\t\"email\":\"thomas.marshal@gmal.com\",\n\t\"password\":\"newPassword\"\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:10053/api/rest/user/login",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "10053",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"user",
|
||||
"login"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Register",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n\t\"name\":\"Clara\",\n\t\"firstname\":\"Sophie\",\n\t\"email\":\"sophie.clara@gmail.com\",\n\t\"password\":\"sophieClara\"\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/user/save",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"user",
|
||||
"save"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "getUser",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n\t\"email\":\"thomas.marshal@gmail.com\",\n\t\"password\":\"newPassword\"\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "http://localhost:8083/api/rest/user/get",
|
||||
"protocol": "http",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8083",
|
||||
"path": [
|
||||
"api",
|
||||
"rest",
|
||||
"user",
|
||||
"get"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package Application;
|
||||
package application;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -13,7 +13,7 @@ import java.util.Collections;
|
|||
public class App {
|
||||
public static void main(String [ ] args){
|
||||
SpringApplication app = new SpringApplication(App.class);
|
||||
app.setDefaultProperties(Collections.singletonMap("server.port","8083"));
|
||||
app.setDefaultProperties(Collections.singletonMap("server.port","10053"));
|
||||
app.run(args);
|
||||
}
|
||||
|
|
@ -56,7 +56,9 @@ public class ChannelClientWrapper {
|
|||
|
||||
channel = channelClientWrapper.getChannel();
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://93.30.148.59:7051");
|
||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps592802.ovh.net:7053");
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package blockchain.configuration;
|
||||
|
||||
public class Config {
|
||||
//TEST
|
||||
public static final String u2 = "woEXRrZdwXiu";
|
||||
|
||||
//ORGANIZATION
|
||||
public static final String ORG1_MSP = "Org1MSP";
|
||||
|
||||
public static final String ORG1 = "org1";
|
||||
public static final String ORG1 = "Org1";
|
||||
|
||||
//ADMIN
|
||||
public static final String ADMIN = "admin";
|
||||
|
@ -13,25 +15,38 @@ public class Config {
|
|||
public static final String ADMIN_PASSWORD = "adminpw";
|
||||
|
||||
//USER
|
||||
public static final String UserPWD = "ZIidLJHQbLcC";
|
||||
//public static final String UserPWD = "ZIidLJHQbLcC";
|
||||
public static final String UserPWD = "OelXVCdHnYPe";
|
||||
|
||||
|
||||
|
||||
//CA
|
||||
public static final String CA_ORG1_URL = "http://vps577432.ovh.net:7054";
|
||||
//public static final String CA_ORG1_URL = "http://vps577432.ovh.net:7054";
|
||||
public static final String CA_ORG1_URL = "http://93.30.148.59:7054";
|
||||
//public static final String CA_ORG1_URL = "http://vps592802.ovh.net:7054";
|
||||
|
||||
//ORDERER
|
||||
public static final String ORDERER_URL = "grpc://vps577432.ovh.net:7050";
|
||||
//public static final String ORDERER_URL = "grpc://vps577432.ovh.net:7050";
|
||||
public static final String ORDERER_URL = "grpc://93.30.148.59:7050";
|
||||
//public static final String ORDERER_URL = "grpc://vps592802.ovh.net:7050";
|
||||
|
||||
public static final String ORDERER_NAME = "orderer.example.com";
|
||||
|
||||
//CHANNEL - CHAINCODE
|
||||
public static final String CHANNEL_NAME = "mychannel";
|
||||
|
||||
public static final String CHAINCODE_NAME = "mycc";
|
||||
//public static final String CHAINCODE_NAME = "mycc";
|
||||
public static final String CHAINCODE_NAME = "monnethic";
|
||||
//public static final String CHAINCODE_NAME = "monnethic-dev-4";
|
||||
|
||||
//PEER 0
|
||||
public static final String ORG1_PEER_0 = "peer0.org1.example.com";
|
||||
|
||||
public static final String ORG1_PEER_0_URL = "grpc://vps577432.ovh.net:8051";
|
||||
//public static final String ORG1_PEER_0_URL = "grpc://vps577432.ovh.net:8051";
|
||||
public static final String ORG1_PEER_0_URL = "grpc://93.30.148.59:7051";
|
||||
//public static final String ORG1_PEER_0_URL = "grpc://93.30.148.59:8051";
|
||||
//ublic static final String ORG1_PEER_0_URL = "grpc://vps592802.ovh.net:7051";
|
||||
|
||||
|
||||
//PEER 1
|
||||
public static final String ORG_PEER = "peer1.org1.example.com";
|
||||
|
|
|
@ -29,6 +29,7 @@ public class TransactionWrapper {
|
|||
tpr.setArgs(new String[]{from,to,amount});
|
||||
|
||||
Collection<ProposalResponse> responses = channelClientWrapper.sendTransactionProposal(tpr);
|
||||
System.out.println("VERIFY HERE, TRY TO SEND TRANSACTION");
|
||||
BlockEvent.TransactionEvent event = channelClientWrapper.sendTransaction(responses);
|
||||
|
||||
return event.getTransactionID();
|
||||
|
|
20
src/main/java/database/DatabaseHelper.java
Normal file
20
src/main/java/database/DatabaseHelper.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package database;
|
||||
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
|
||||
public class DatabaseHelper {
|
||||
private static final String DATABASE_NAME = "monnethic";
|
||||
private static final String DATABASE_USER = "postgres";
|
||||
private static final String DATABASE_PWD = "L-*q~Ytaha{;u+7yJ8";
|
||||
private final static String DATABASE_URL = "jdbc:postgresql://37.187.101.44:5432/"+DATABASE_NAME;
|
||||
|
||||
public ConnectionSource setupDatabaseConnection(){
|
||||
try{
|
||||
return new JdbcConnectionSource(DATABASE_URL, DATABASE_USER, DATABASE_PWD);
|
||||
}catch (Exception e){
|
||||
System.out.print("\n"+e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
38
src/main/java/database/DatabaseTest.java
Normal file
38
src/main/java/database/DatabaseTest.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package database;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "T_TEST")
|
||||
public class DatabaseTest {
|
||||
private static final String NAME_FIELD_NAME = "name";
|
||||
private static final String ID_FIELD_NAME = "id";
|
||||
|
||||
@DatabaseField(columnName = ID_FIELD_NAME, id = true)
|
||||
private int id;
|
||||
@DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false)
|
||||
private String name;
|
||||
|
||||
public DatabaseTest(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DatabaseTest() { }
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
106
src/main/java/database/transaction/Transaction.java
Normal file
106
src/main/java/database/transaction/Transaction.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package database.transaction;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "T_TRANSACTION")
|
||||
public class Transaction {
|
||||
@DatabaseField(generatedId = true)
|
||||
private int transactionId;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long transactionDate;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionFrom;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionTo;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionHash;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private Double transactionAmount;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionUnit;
|
||||
|
||||
public Transaction() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Transaction(long transactionDate, String transactionFrom, String transactionTo, String transactionHash, Double transactionAmount, String transactionUnit) {
|
||||
super();
|
||||
this.transactionDate = transactionDate;
|
||||
this.transactionFrom = transactionFrom;
|
||||
this.transactionTo = transactionTo;
|
||||
this.transactionHash = transactionHash;
|
||||
this.transactionAmount = transactionAmount;
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
|
||||
public String getTransactionFrom() {
|
||||
return transactionFrom;
|
||||
}
|
||||
|
||||
public void setTransactionFrom(String transactionFrom) {
|
||||
this.transactionFrom = transactionFrom;
|
||||
}
|
||||
|
||||
public String getTransactionTo() {
|
||||
return transactionTo;
|
||||
}
|
||||
|
||||
public void setTransactionTo(String transactionTo) {
|
||||
this.transactionTo = transactionTo;
|
||||
}
|
||||
|
||||
public String getTransactionHash() {
|
||||
return transactionHash;
|
||||
}
|
||||
|
||||
public void setTransactionHash(String transactionHash) {
|
||||
this.transactionHash = transactionHash;
|
||||
}
|
||||
|
||||
public Double getTransactionAmount() {
|
||||
return transactionAmount;
|
||||
}
|
||||
|
||||
public void setTransactionAmount(Double transactionAmount) {
|
||||
this.transactionAmount = transactionAmount;
|
||||
}
|
||||
|
||||
public int getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public void setTransactionId(int id) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
|
||||
public long getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
public void setTransactionDate(long transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public String getTransactionUnit() {
|
||||
return transactionUnit;
|
||||
}
|
||||
|
||||
public void setTransactionUnit(String transactionUnit) {
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Transaction{" +
|
||||
"transactionId=" + transactionId +
|
||||
", transactionDate=" + transactionDate +
|
||||
", transactionFrom='" + transactionFrom + '\'' +
|
||||
", transactionTo='" + transactionTo + '\'' +
|
||||
", transactionHash='" + transactionHash + '\'' +
|
||||
", transactionAmount=" + transactionAmount +
|
||||
", transactionUnit='" + transactionUnit + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
75
src/main/java/database/transaction/TransactionDao.java
Normal file
75
src/main/java/database/transaction/TransactionDao.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package database.transaction;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import database.DatabaseHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TransactionDao {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
private Dao<Transaction, String> transactionDao;
|
||||
|
||||
private Dao createTransactionDaoConnection(){
|
||||
try {
|
||||
return DaoManager.createDao(dbh.setupDatabaseConnection(),Transaction.class);
|
||||
}catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addTransaction(Transaction transaction)throws Exception{
|
||||
transactionDao = createTransactionDaoConnection();
|
||||
transactionDao.create(transaction);
|
||||
}
|
||||
|
||||
public List<Transaction> getUserTransactions(String userHash)throws Exception{
|
||||
transactionDao = createTransactionDaoConnection();
|
||||
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
|
||||
queryBuilder.where().eq("transactionFrom",userHash).or().eq("transactionTo",userHash);
|
||||
queryBuilder.orderBy("transactionDate",false);
|
||||
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
|
||||
return transactionDao.query(preparedQuery);
|
||||
}
|
||||
|
||||
public List<Transaction> getTenLastUserTransactions(String userHash)throws Exception{
|
||||
transactionDao = createTransactionDaoConnection();
|
||||
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
|
||||
queryBuilder.where().eq("transactionFrom",userHash).or().eq("transactionTo",userHash);
|
||||
queryBuilder.limit(new Long(10));
|
||||
queryBuilder.orderBy("transactionDate",false);
|
||||
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
|
||||
return transactionDao.query(preparedQuery);
|
||||
}
|
||||
|
||||
public Transaction getTransaction(String userHash, String transactionHash)throws Exception{
|
||||
transactionDao = createTransactionDaoConnection();
|
||||
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
|
||||
queryBuilder.where().eq("transactionTo",userHash).or().eq("transactionFrom",userHash).and().eq("transactionHash",transactionHash);
|
||||
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
|
||||
return transactionDao.queryForFirst(preparedQuery);
|
||||
}
|
||||
|
||||
public List<Transaction> getUserSentTransaction(String userHash)throws Exception{
|
||||
transactionDao = createTransactionDaoConnection();
|
||||
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
|
||||
queryBuilder.where().eq("transactionFrom",userHash);
|
||||
queryBuilder.orderBy("transactionDate",false);
|
||||
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
|
||||
return transactionDao.query(preparedQuery);
|
||||
}
|
||||
|
||||
public List<Transaction> getUserReceivedTransaction(String userHash)throws Exception{
|
||||
transactionDao = createTransactionDaoConnection();
|
||||
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
|
||||
queryBuilder.where().eq("transactionTo",userHash);
|
||||
queryBuilder.orderBy("transactionDate",false);
|
||||
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
|
||||
return transactionDao.query(preparedQuery);
|
||||
}
|
||||
|
||||
|
||||
}
|
145
src/main/java/database/user/User.java
Normal file
145
src/main/java/database/user/User.java
Normal file
|
@ -0,0 +1,145 @@
|
|||
package database.user;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
//Class User which represent an User in the postgresDB
|
||||
@DatabaseTable(tableName = "T_USER")
|
||||
public class User {
|
||||
@DatabaseField(generatedId = true)
|
||||
private int userId;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String name;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String firstname;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String email;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String password;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long creation_date;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long modification_date;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private boolean verified;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private boolean approved;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String user_hash;
|
||||
|
||||
//Constructors
|
||||
//Default constructor for ORMLite
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String name, String firstname, String email, String password) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, boolean verified, boolean approved) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.user_hash = user_hash;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.creation_date = creation_date;
|
||||
this.modification_date = modification_date;
|
||||
this.verified = verified;
|
||||
this.approved = approved;
|
||||
}
|
||||
|
||||
|
||||
//Getters and Setters
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {this.userId = userId;}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setUser_hash(String user_hash){this.user_hash = user_hash;}
|
||||
|
||||
public String getUser_hash(){return user_hash;}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public long getCreation_date() {
|
||||
return creation_date;
|
||||
}
|
||||
|
||||
public void setCreation_date(long creation_date) {
|
||||
this.creation_date = creation_date;
|
||||
}
|
||||
|
||||
public long getModification_date() {
|
||||
return modification_date;
|
||||
}
|
||||
|
||||
public void setModification_date(long modification_date) {
|
||||
this.modification_date = modification_date;
|
||||
}
|
||||
|
||||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
||||
public void setVerified(boolean verified) {
|
||||
this.verified = verified;
|
||||
}
|
||||
|
||||
public boolean isApproved() {
|
||||
return approved;
|
||||
}
|
||||
|
||||
public void setApproved(boolean approved) {
|
||||
this.approved = approved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"userId=" + userId +
|
||||
", name='" + name + '\'' +
|
||||
", firstname='" + firstname + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", creation_date=" + creation_date +
|
||||
", modification_date=" + modification_date +
|
||||
", verified=" + verified +
|
||||
", approved=" + approved +
|
||||
", user_hash='" + user_hash + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
120
src/main/java/database/user/UserDao.java
Normal file
120
src/main/java/database/user/UserDao.java
Normal file
|
@ -0,0 +1,120 @@
|
|||
package database.user;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.UpdateBuilder;
|
||||
import database.DatabaseHelper;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
//Class to communicate with database with ORMLite
|
||||
public class UserDao {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
private Dao<User, String> userDao;
|
||||
|
||||
private Dao createUserDaoConnection(){
|
||||
try {
|
||||
return DaoManager.createDao(dbh.setupDatabaseConnection(),User.class);
|
||||
}catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addUser(User user)throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
userDao.create(user);
|
||||
}
|
||||
|
||||
public boolean checkApprovedUser(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
return user.isApproved();
|
||||
}
|
||||
|
||||
public boolean checkVerifiedUser(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
return user.isVerified();
|
||||
}
|
||||
|
||||
public boolean updateUserPassword(String email, String password) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("password",password);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("email",email);
|
||||
updateBuilder.update();
|
||||
|
||||
if(checkUserPassword(email, password)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean verifyUserExist(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
User user = userDao.queryForFirst(preparedQuery);
|
||||
|
||||
if(user==null){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkUserPassword(String email, String password) throws Exception {
|
||||
User user = getUser(email);
|
||||
if(password.equals(user.getPassword())){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public User getUser(String email) throws Exception {
|
||||
if(!verifyUserExist(email)){
|
||||
return null;
|
||||
}else{
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
PreparedQuery<User> preparedQuery = queryBuilder.prepare();
|
||||
return userDao.queryForFirst(preparedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void approveUser (String email) throws Exception{
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("approved",true);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("email",email);
|
||||
updateBuilder.update();
|
||||
}
|
||||
|
||||
public void verifyUser (String email) throws Exception{
|
||||
userDao = createUserDaoConnection();
|
||||
UpdateBuilder<User, String> updateBuilder = userDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("verified",true);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("email",email);
|
||||
updateBuilder.update();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package restImplementation;
|
||||
|
||||
import blockchain.query.QueryWrapper;
|
||||
|
||||
public class BlockchainQueryImplementation {
|
||||
|
||||
public Double getUserBalance(String userHash){
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String result = queryWrapper.getUserBalance(userHash);
|
||||
Double balance = Double.parseDouble(result);
|
||||
return balance;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package restImplementation;
|
||||
|
||||
import database.transaction.Transaction;
|
||||
import database.transaction.TransactionDao;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
public class DatabaseTransactionImplementation {
|
||||
|
||||
public void saveTransaction(Transaction transaction) throws Exception{
|
||||
TransactionDao transactionDao = new TransactionDao();
|
||||
long now = Instant.now().toEpochMilli();
|
||||
transaction.setTransactionDate(now);
|
||||
transactionDao.addTransaction(transaction);
|
||||
}
|
||||
|
||||
public Transaction getUserTransaction(String userHash, String transactionHash)throws Exception{
|
||||
TransactionDao transactionDao = new TransactionDao();
|
||||
Transaction tx = transactionDao.getTransaction(userHash,transactionHash);
|
||||
if(tx != null){
|
||||
return tx;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Transaction> getAllUserTransactions(String userHash)throws Exception{
|
||||
TransactionDao transactionDao = new TransactionDao();
|
||||
return transactionDao.getUserTransactions(userHash);
|
||||
}
|
||||
|
||||
public List<Transaction> getLastTenTransactions(String userHash)throws Exception{
|
||||
TransactionDao transactionDao = new TransactionDao();
|
||||
return transactionDao.getTenLastUserTransactions(userHash);
|
||||
}
|
||||
|
||||
public List<Transaction> getSentTransaction(String userHash)throws Exception{
|
||||
TransactionDao transactionDao = new TransactionDao();
|
||||
return transactionDao.getUserSentTransaction(userHash);
|
||||
}
|
||||
|
||||
public List<Transaction> getReceivedTransaction(String userHash)throws Exception{
|
||||
TransactionDao transactionDao = new TransactionDao();
|
||||
return transactionDao.getUserReceivedTransaction(userHash);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package restImplementation;
|
||||
|
||||
import database.user.User;
|
||||
import database.user.UserDao;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DatabaseUserImplementation {
|
||||
|
||||
public Map<String,String> saveUser(User user) throws Exception {
|
||||
UserDao userDao = new UserDao();
|
||||
Map<String,String> response = new HashMap<String, String>();
|
||||
|
||||
User dbUser = userDao.getUser(user.getEmail());
|
||||
if(dbUser != null){
|
||||
response.put("response","false");
|
||||
return response;
|
||||
}else {
|
||||
user.setPassword(hashPassword(user.getPassword()));
|
||||
long now = Instant.now().toEpochMilli();
|
||||
user.setCreation_date(now);
|
||||
user.setModification_date(now);
|
||||
user.setVerified(true);
|
||||
user.setApproved(true);
|
||||
|
||||
//TEMPORARY USER HASH IS
|
||||
//name+email+password
|
||||
user.setUser_hash(hashPassword(user.getName()+user.getEmail()+user.getPassword()));
|
||||
userDao.addUser(user);
|
||||
response.put("userHash",user.getUser_hash());
|
||||
response.put("response","true");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public User getUser(String email, String password) throws Exception{
|
||||
UserDao userDao = new UserDao();
|
||||
User user1 = userDao.getUser(email);
|
||||
if(user1 != null){
|
||||
String hash = user1.getPassword();
|
||||
if(BCrypt.checkpw(password, hash)){
|
||||
return user1;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> userLogger(User user) throws Exception {
|
||||
UserDao userDao = new UserDao();
|
||||
Map<String,String> response = new HashMap<String, String>();
|
||||
|
||||
User user1 = userDao.getUser(user.getEmail());
|
||||
if(user1 != null){
|
||||
String hash = user1.getPassword();
|
||||
|
||||
if(!BCrypt.checkpw(user.getPassword(), hash)){
|
||||
response.put("response","Not Allowed");
|
||||
}else{
|
||||
response.put("response","Ok");
|
||||
response.put("userHash",user1.getUser_hash());
|
||||
}
|
||||
} else {
|
||||
response.put("response","Not Exist");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private String hashPassword(String plainTextPassword){
|
||||
return BCrypt.hashpw(plainTextPassword,BCrypt.gensalt());
|
||||
}
|
||||
}
|
28
src/main/java/restService/BlockchainQueryResource.java
Normal file
28
src/main/java/restService/BlockchainQueryResource.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package restService;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import restImplementation.BlockchainQueryImplementation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/rest/query")
|
||||
public class BlockchainQueryResource {
|
||||
|
||||
@RequestMapping(value = "/balance", method = RequestMethod.GET ,params = {"userHash"},produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> getUserBalance(@RequestParam(value = "userHash") String userHash){
|
||||
try{
|
||||
BlockchainQueryImplementation blockchainQueryImplementation = new BlockchainQueryImplementation();
|
||||
Double result = blockchainQueryImplementation.getUserBalance(userHash);
|
||||
StringResponse response = new StringResponse("Ok",result);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||
}catch (Exception e){
|
||||
StringResponse response = new StringResponse("Error");
|
||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
110
src/main/java/restService/DatabaseTransactionResource.java
Normal file
110
src/main/java/restService/DatabaseTransactionResource.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package restService;
|
||||
|
||||
import database.transaction.Transaction;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import restImplementation.DatabaseTransactionImplementation;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/rest/transaction")
|
||||
public class DatabaseTransactionResource {
|
||||
|
||||
@PostMapping("/save")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public ResponseEntity<String> saveTransaction(@Valid @RequestBody Transaction transaction){
|
||||
try{
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
databaseTransactionImplementation.saveTransaction(transaction);
|
||||
return ResponseEntity.status(HttpStatus.OK).body("");
|
||||
}catch (Exception e){
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/get", method = RequestMethod.GET, params = {"userHash","transactionHash"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<Transaction> getTransaction(@RequestParam(value = "userHash") String userHash, @RequestParam(value = "transactionHash") String transactionHash){
|
||||
try{
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
Transaction tx = databaseTransactionImplementation.getUserTransaction(userHash,transactionHash);
|
||||
if(tx != null){
|
||||
return ResponseEntity.status(HttpStatus.OK).body(tx);
|
||||
}else {
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getLatest", method = RequestMethod.GET, params = {"userHash"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<List<Transaction>> getLatestTransactions(@RequestParam(value = "userHash") String userHash){
|
||||
try{
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
List<Transaction> transactionList = databaseTransactionImplementation.getLastTenTransactions(userHash);
|
||||
if(!transactionList.isEmpty()){
|
||||
return ResponseEntity.status(HttpStatus.OK).body(transactionList);
|
||||
}else {
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/getAll", method = RequestMethod.GET, params = {"userHash"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<List<Transaction>> getAllTransactions(@RequestParam(value = "userHash") String userHash){
|
||||
try{
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
List<Transaction> transactionList = databaseTransactionImplementation.getAllUserTransactions(userHash);
|
||||
if(!transactionList.isEmpty()){
|
||||
return ResponseEntity.status(HttpStatus.OK).body(transactionList);
|
||||
}else {
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sent", method = RequestMethod.GET, params = {"userHash"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<List<Transaction>> getSentTransactions(@RequestParam(value = "userHash") String userHash){
|
||||
try {
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
List<Transaction> transactionList = databaseTransactionImplementation.getSentTransaction(userHash);
|
||||
if(!transactionList.isEmpty()){
|
||||
return ResponseEntity.status(HttpStatus.OK).body(transactionList);
|
||||
}else {
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/received", method = RequestMethod.GET, params = {"userHash"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<List<Transaction>> getReceivedTransactions(@RequestParam(value = "userHash") String userHash){
|
||||
try {
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
List<Transaction> transactionList = databaseTransactionImplementation.getReceivedTransaction(userHash);
|
||||
if(!transactionList.isEmpty()){
|
||||
return ResponseEntity.status(HttpStatus.OK).body(transactionList);
|
||||
}else {
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
97
src/main/java/restService/DatabaseUserResource.java
Normal file
97
src/main/java/restService/DatabaseUserResource.java
Normal file
|
@ -0,0 +1,97 @@
|
|||
package restService;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import database.user.User;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import restImplementation.DatabaseUserImplementation;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/rest/user")
|
||||
public class DatabaseUserResource {
|
||||
|
||||
@RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public ResponseEntity<StringResponse> saveUser(@Valid @RequestBody User user){
|
||||
try{
|
||||
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
||||
Map<String,String> response = databaseUserImplementation.saveUser(user);
|
||||
if(Boolean.parseBoolean(response.get("response"))){
|
||||
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
||||
}else {
|
||||
StringResponse responseS = new StringResponse("User already exist");
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(responseS);
|
||||
}
|
||||
}catch (Exception e){
|
||||
StringResponse responseS = new StringResponse(e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST,produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){
|
||||
try{
|
||||
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
||||
Map<String,String> response = databaseUserImplementation.userLogger(user);
|
||||
switch (response.get("response")){
|
||||
case "Not Exist" : {
|
||||
StringResponse responseS = new StringResponse("User Not Found");
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseS);
|
||||
}
|
||||
case "Not Allowed" :{
|
||||
StringResponse responseS = new StringResponse("Wrong Password!");
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(responseS);
|
||||
}
|
||||
case "" :{
|
||||
StringResponse responseS = new StringResponse("Error");
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
||||
}
|
||||
case "Ok":{
|
||||
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
||||
}
|
||||
default:{
|
||||
StringResponse responseS = new StringResponse("Error");
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
StringResponse responseS = new StringResponse(e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/get", produces = "application/json")
|
||||
@ResponseBody
|
||||
public ResponseEntity<User> getUser(@RequestBody User user){
|
||||
try{
|
||||
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
||||
User response = databaseUserImplementation.getUser(user.getEmail(), user.getPassword());
|
||||
if(response != null){
|
||||
User userResponse = new User();
|
||||
userResponse.setUser_hash(response.getUser_hash());
|
||||
userResponse.setUserId(response.getUserId());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(userResponse);
|
||||
}else{
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity updateUser(@RequestBody User user){
|
||||
return new ResponseEntity(null, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
41
src/main/java/restService/StringResponse.java
Normal file
41
src/main/java/restService/StringResponse.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package restService;
|
||||
|
||||
public class StringResponse {
|
||||
private String response;
|
||||
private String userHash;
|
||||
private Double userBalance;
|
||||
|
||||
public StringResponse(String response){
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public StringResponse(String response, Double userBalance){
|
||||
this.response=response;
|
||||
this.userBalance=userBalance;
|
||||
}
|
||||
|
||||
public StringResponse(String response, String userHash){
|
||||
this.response=response;
|
||||
this.userHash=userHash;
|
||||
}
|
||||
|
||||
public String getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(String response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public String getUserHash() {
|
||||
return userHash;
|
||||
}
|
||||
|
||||
public void setUserHash(String userHash) {
|
||||
this.userHash = userHash;
|
||||
}
|
||||
|
||||
public Double getUserBalance(){return userBalance;}
|
||||
|
||||
public void setUserBalance(Double userBalance){this.userBalance=userBalance;}
|
||||
}
|
|
@ -4,9 +4,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class WelcomeController {
|
||||
public class WelcomeResource {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index(){return "Welcome to monnethic ! ";}
|
||||
public String index(){return "Welcome from Monnethic !";}
|
||||
|
||||
}
|
||||
}
|
44
src/test/java/blockchain/client/TestEnrollAdmin.java
Normal file
44
src/test/java/blockchain/client/TestEnrollAdmin.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package blockchain.client;
|
||||
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import org.hyperledger.fabric.sdk.Enrollment;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
//Test to enroll Admin
|
||||
@Ignore
|
||||
public class TestEnrollAdmin {
|
||||
@Test
|
||||
public void TestAEnrollAdmin(){
|
||||
String caUrl = Config.CA_ORG1_URL;
|
||||
try {
|
||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
||||
|
||||
UserContext adminContext = new UserContext();
|
||||
adminContext.setName(Config.ADMIN);
|
||||
adminContext.setAffiliation(Config.ORG1);
|
||||
adminContext.setMspId(Config.ORG1_MSP);
|
||||
|
||||
caClientWrapper.setAdminContext(adminContext);
|
||||
|
||||
UserContext verifyUser = caClientWrapper.getAdminContext();
|
||||
assertEquals(Config.ADMIN, verifyUser.getName());
|
||||
assertEquals(Config.ORG1, verifyUser.getAffiliation());
|
||||
assertEquals(Config.ORG1_MSP, verifyUser.getMspId());
|
||||
|
||||
//ENROLL AND WRITE ADMIN
|
||||
adminContext = caClientWrapper.enrollAdmin(adminContext.getName(),Config.ADMIN_PASSWORD,adminContext.getAffiliation());
|
||||
|
||||
//Check Admin Enrollement
|
||||
Enrollment enrollment = adminContext.getEnrollment();
|
||||
System.out.println("admin cert : "+enrollment.getCert());
|
||||
System.out.println("admin keys : "+enrollment.getKey());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
39
src/test/java/blockchain/client/TestRegisterEnrollUser.java
Normal file
39
src/test/java/blockchain/client/TestRegisterEnrollUser.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package blockchain.client;
|
||||
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
//Test to register and enroll user
|
||||
@Ignore
|
||||
public class TestRegisterEnrollUser {
|
||||
private static Logger logger = Logger.getLogger(TestRegisterEnrollUser.class);
|
||||
//Success
|
||||
@Test
|
||||
public void RegisterEnrollUser(){
|
||||
String caUrl = Config.CA_ORG1_URL;
|
||||
try{
|
||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
||||
UserContext admin = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
caClientWrapper.setAdminContext(admin);
|
||||
UserContext userContext = new UserContext();
|
||||
|
||||
userContext.setName("User-org1");
|
||||
userContext.setAffiliation(Config.ORG1);
|
||||
userContext.setMspId(Config.ORG1_MSP);
|
||||
String userSecret = caClientWrapper.registerUser(userContext.getName(),userContext.getAffiliation());
|
||||
logger.info("uSecret : "+userSecret);
|
||||
userContext = caClientWrapper.enrollUser(userContext,userSecret);
|
||||
logger.info("userContext enrollement : "+userContext.getEnrollment());
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
78
src/test/java/blockchain/query/ChaincodeTransactionTest.java
Normal file
78
src/test/java/blockchain/query/ChaincodeTransactionTest.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
package blockchain.query;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
//Test for transaction
|
||||
@Ignore
|
||||
public class ChaincodeTransactionTest {
|
||||
private static Logger logger = Logger.getLogger(ChaincodeTransactionTest.class);
|
||||
@Test
|
||||
public void TestATransaction(){
|
||||
BasicConfigurator.configure();
|
||||
|
||||
//UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
|
||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
|
||||
try{
|
||||
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
Channel channel = channelClientWrapper.getChannel();
|
||||
//OLD PEER
|
||||
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
||||
//Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
channel.addOrderer(orderer);
|
||||
channel.initialize();
|
||||
|
||||
|
||||
|
||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
tpr.setChaincodeID(cid);
|
||||
tpr.setFcn("invoke");
|
||||
tpr.setArgs(new String[]{"b","a","25"}); //send 20 from a to b
|
||||
|
||||
Collection<ProposalResponse> responses = channel.sendTransactionProposal(tpr);
|
||||
List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
|
||||
|
||||
if (!invalid.isEmpty()) {
|
||||
invalid.forEach(response -> {
|
||||
logger.error(response.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
logger.info("SEND TRANSACTION");
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
64
src/test/java/blockchain/query/CreateChaincodeUserTest.java
Normal file
64
src/test/java/blockchain/query/CreateChaincodeUserTest.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package blockchain.query;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
//Test to create user on chaincode -> don't work, can't use function "Init"
|
||||
@Ignore
|
||||
public class CreateChaincodeUserTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestCreateUser(){
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
Channel channel = channelClientWrapper.getChannel();
|
||||
//OLD
|
||||
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
||||
//Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
channel.addOrderer(orderer);
|
||||
channel.initialize();
|
||||
|
||||
String[] args = {"user1","200","user2","180"};
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"init",args);
|
||||
for(ProposalResponse pres : responseQuery){
|
||||
ChaincodeResponse.Status status = pres.getStatus();
|
||||
if(status.getStatus()!=200){
|
||||
throw new Exception(pres.getMessage());
|
||||
}
|
||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
||||
logger.info("RESPONSE : "+stringResponse);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
36
src/test/java/blockchain/query/QueryChannelTest.java
Normal file
36
src/test/java/blockchain/query/QueryChannelTest.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package blockchain.query;
|
||||
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.Peer;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
//Test to show channels on a node
|
||||
@Ignore
|
||||
public class QueryChannelTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void testQ(){
|
||||
BasicConfigurator.configure();
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
||||
Set<String> channels = fabricClientWrapper.queryForChannels();
|
||||
|
||||
logger.info("CHANNELS : "+channels);
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
53
src/test/java/blockchain/query/QueryTest.java
Normal file
53
src/test/java/blockchain/query/QueryTest.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package blockchain.query;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
//Test to get balance of a User
|
||||
@Ignore
|
||||
public class QueryTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestAQuery() {
|
||||
BasicConfigurator.configure();
|
||||
|
||||
//UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
//String[] args1 = {"a"};
|
||||
String[] args1 = {"chef"};
|
||||
//String[] args1 = {"bitman"};
|
||||
//String[] args1 = {"user_test"};
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args1);
|
||||
for(ProposalResponse pres : responseQuery){
|
||||
ChaincodeResponse.Status status = pres.getStatus();
|
||||
if(status.getStatus()!=200){
|
||||
throw new Exception(pres.getMessage());
|
||||
}
|
||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
||||
logger.info("RESPONSE : "+stringResponse);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
53
src/test/java/blockchain/query/User/ReadUserTest.java
Normal file
53
src/test/java/blockchain/query/User/ReadUserTest.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package blockchain.query.User;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.query.QueryTest;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Ignore
|
||||
public class ReadUserTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryReadUser() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
//String[] args1 = {"chef"};
|
||||
String[] args1 = {"user_test"};
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
||||
logger.info("RESPONSE : "+responseQuery);
|
||||
logger.info("RESPONSE : "+responseQuery.size());
|
||||
for(ProposalResponse pres : responseQuery){
|
||||
ChaincodeResponse.Status status = pres.getStatus();
|
||||
if(status.getStatus()!=200){
|
||||
throw new Exception(pres.getMessage());
|
||||
}
|
||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
||||
logger.info("RESPONSE : "+stringResponse);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
67
src/test/java/blockchain/query/User/RegisterUserTest.java
Normal file
67
src/test/java/blockchain/query/User/RegisterUserTest.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
package blockchain.query.User;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
//Test to get balance of a User
|
||||
@Ignore
|
||||
public class RegisterUserTest {
|
||||
private static Logger logger = Logger.getLogger(RegisterUserTest.class);
|
||||
|
||||
@Test
|
||||
public void TestARegisterUser() {
|
||||
BasicConfigurator.configure();
|
||||
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
try{
|
||||
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
Channel channel = channelClientWrapper.getChannel();
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://93.30.148.59:7051");
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
channel.addOrderer(orderer);
|
||||
channel.initialize();
|
||||
|
||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
tpr.setChaincodeID(cid);
|
||||
tpr.setFcn("register");
|
||||
tpr.setArgs(new String[]{"user_test","100"}); //register user_test with 100
|
||||
|
||||
Collection<ProposalResponse> responses = channel.sendTransactionProposal(tpr);
|
||||
List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
|
||||
|
||||
if (!invalid.isEmpty()) {
|
||||
invalid.forEach(response -> {
|
||||
logger.error(response.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
logger.info("SEND REQUEST");
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
||||
logger.info("Event id : "+event.getTransactionID()); //print transaction id
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package blockchain.query.Wallet;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.query.QueryTest;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Ignore
|
||||
public class QueryWalletByOwnerTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWallet() {
|
||||
BasicConfigurator.configure();
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
String[] args1 = {"chef"};
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByOwner",args1);
|
||||
|
||||
for(ProposalResponse pres : responseQuery){
|
||||
ChaincodeResponse.Status status = pres.getStatus();
|
||||
if(status.getStatus()!=200){
|
||||
throw new Exception(pres.getMessage());
|
||||
}
|
||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
||||
logger.info("RESPONSE : "+stringResponse);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package blockchain.query.Wallet;
|
||||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.query.QueryTest;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Ignore
|
||||
public class QueryWalletByOwnerTrTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void TestQueryWallet() {
|
||||
BasicConfigurator.configure();
|
||||
|
||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
try{
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
Channel channel = channelClientWrapper.getChannel();
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://93.30.148.59:87051");
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
channel.addOrderer(orderer);
|
||||
channel.initialize();
|
||||
|
||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
tpr.setChaincodeID(cid);
|
||||
tpr.setFcn("queryWalletsByOwner");
|
||||
tpr.setArgs(new String[]{"chef"});
|
||||
|
||||
Collection<ProposalResponse> responses = channel.sendTransactionProposal(tpr);
|
||||
List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
|
||||
|
||||
if (!invalid.isEmpty()) {
|
||||
invalid.forEach(response -> {
|
||||
logger.error(response.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
logger.info("SEND TRANSACTION");
|
||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
||||
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
20
src/test/java/blockchain/queryWrapper/QueryWrapperTest.java
Normal file
20
src/test/java/blockchain/queryWrapper/QueryWrapperTest.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package blockchain.queryWrapper;
|
||||
|
||||
import blockchain.query.QueryWrapper;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
public class QueryWrapperTest {
|
||||
private static Logger logger = Logger.getLogger(QueryWrapperTest.class);
|
||||
@Test
|
||||
public void TestGerUserBalance() {
|
||||
BasicConfigurator.configure();
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
String response = queryWrapper.getUserBalance("a");
|
||||
logger.info(response);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package blockchain.queryWrapper;
|
||||
|
||||
import blockchain.query.QueryWrapper;
|
||||
import blockchain.query.TransactionWrapper;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
public class TransactionWrapperTest {
|
||||
private static Logger logger = Logger.getLogger(TransactionWrapperTest.class);
|
||||
|
||||
@Test
|
||||
public void TestTransaction() {
|
||||
BasicConfigurator.configure();
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||
String responseTransaction = transactionWrapper.sendTransaction("b","a","150"); //do transaction
|
||||
logger.info("TRANSACTION ID : "+responseTransaction);
|
||||
|
||||
String responseUserB = queryWrapper.getUserBalance("b"); //check new balance of user b
|
||||
logger.info("BALANCE USER B : "+responseUserB);
|
||||
|
||||
String responseUserA = queryWrapper.getUserBalance("a"); //check new balance of user a
|
||||
logger.info("BALANCE USER A :"+responseUserA);
|
||||
}
|
||||
}
|
23
src/test/java/blockchain/user/UserContextTest.java
Normal file
23
src/test/java/blockchain/user/UserContextTest.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package blockchain.user;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
//Test to create a User
|
||||
@Ignore
|
||||
public class UserContextTest {
|
||||
@Test
|
||||
public void TestACreateUser(){
|
||||
UserContext userContext = new UserContext();
|
||||
userContext.setName("admin");
|
||||
userContext.setAffiliation("org1");
|
||||
userContext.setMspId("MspidOrg1");
|
||||
userContext.setEnrollment(null);
|
||||
|
||||
assertEquals("org1",userContext.getAffiliation());
|
||||
assertEquals("admin",userContext.getName());
|
||||
assertEquals(null,userContext.getEnrollment());
|
||||
}
|
||||
}
|
24
src/test/java/blockchain/utility/ReadUserTest.java
Normal file
24
src/test/java/blockchain/utility/ReadUserTest.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package blockchain.utility;
|
||||
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
//Test to Read User
|
||||
@Ignore
|
||||
public class ReadUserTest {
|
||||
@Test
|
||||
public void testReadUserOrg1(){
|
||||
try{
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1, "User2-org1");
|
||||
System.out.println(userContext.getAffiliation());
|
||||
System.out.println(userContext.getMspId());
|
||||
System.out.println(userContext.getEnrollment().getCert());
|
||||
System.out.println(userContext.getEnrollment().getKey());
|
||||
System.out.println(userContext.getName());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
57
src/test/java/blockchain/utility/UtilTest.java
Normal file
57
src/test/java/blockchain/utility/UtilTest.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package blockchain.utility;
|
||||
|
||||
import blockchain.user.UserContext;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
//Test to Read and Write user from files
|
||||
@Ignore
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class UtilTest {
|
||||
private static Logger logger = Logger.getLogger(UtilTest.class);
|
||||
|
||||
@Test
|
||||
public void TestAReadNullUser(){
|
||||
BasicConfigurator.configure();
|
||||
|
||||
logger.info("----- START TEST READ NULL USER ----");
|
||||
UserContext uc = Util.readUserContext("tata","abdel");
|
||||
if(uc!=null){
|
||||
logger.info("UserContext is : "+uc.toString());
|
||||
}else{
|
||||
logger.info("UserContext doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestBWriteUser(){
|
||||
BasicConfigurator.configure();
|
||||
logger.info("----- START TEST WRITE NULL USER ----");
|
||||
UserContext user = new UserContext();
|
||||
user.setName("abdel");
|
||||
user.setAffiliation("toto");
|
||||
user.setEnrollment(null);
|
||||
user.setMspId("test");
|
||||
|
||||
Util.writeUserContext(user);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCReadCreatedUser(){
|
||||
BasicConfigurator.configure();
|
||||
logger.info("----- START TEST READ CREATED USER ----");
|
||||
UserContext uc = Util.readUserContext("toto","abdel");
|
||||
if(uc!=null){
|
||||
logger.info("UserContext is : "+uc.toString());
|
||||
}else{
|
||||
logger.info("UserContext doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
src/test/java/crypto/CryptoTest.java
Normal file
23
src/test/java/crypto/CryptoTest.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package crypto;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
|
||||
import java.time.Instant;
|
||||
@Ignore
|
||||
public class CryptoTest {
|
||||
|
||||
@Test
|
||||
public void testHash(){
|
||||
String password = "newPassword";
|
||||
System.out.println(hashPassword(password));
|
||||
|
||||
long now = Instant.now().toEpochMilli();
|
||||
System.out.println(now);
|
||||
}
|
||||
|
||||
private String hashPassword(String plainTextPassword) {
|
||||
return BCrypt.hashpw(plainTextPassword, BCrypt.gensalt());
|
||||
}
|
||||
}
|
28
src/test/java/database/DatabaseHelperTest.java
Normal file
28
src/test/java/database/DatabaseHelperTest.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package database;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
//Testing class for postgresql connection
|
||||
@Ignore
|
||||
public class DatabaseHelperTest {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
|
||||
//Test connection by getting existing data in T_TEST
|
||||
@Test
|
||||
public void TestConnection(){
|
||||
Dao<DatabaseTest, Integer> testDao;
|
||||
try{
|
||||
testDao = DaoManager.createDao(dbh.setupDatabaseConnection(),DatabaseTest.class);
|
||||
DatabaseTest dbt = testDao.queryForId(1);
|
||||
System.out.println(dbt.getName());
|
||||
assert dbt != null;
|
||||
assert "thomas".equals(dbt.getName());
|
||||
}catch (Exception e){
|
||||
System.out.println("\n"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
src/test/java/database/DatabaseUserImplementationTest.java
Normal file
23
src/test/java/database/DatabaseUserImplementationTest.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package database;
|
||||
|
||||
import database.user.User;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import restImplementation.DatabaseUserImplementation;
|
||||
|
||||
@Ignore
|
||||
public class DatabaseUserImplementationTest {
|
||||
@Test
|
||||
public void TestUser(){
|
||||
try {
|
||||
//String email = "null";
|
||||
String email = "thomas.marshal@gmail.com";
|
||||
String password = "null";
|
||||
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
||||
User response = databaseUserImplementation.getUser(email, password);
|
||||
System.out.println(response);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
25
src/test/java/restImplementation/UserLoggerTest.java
Normal file
25
src/test/java/restImplementation/UserLoggerTest.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package restImplementation;
|
||||
|
||||
import database.user.User;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Ignore
|
||||
public class UserLoggerTest {
|
||||
@Test
|
||||
public void testLoggerUser(){
|
||||
try{
|
||||
User user = new User();
|
||||
user.setPassword("newPassword");
|
||||
user.setEmail("thomas.marshal@gmail.com");
|
||||
|
||||
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
||||
Map<String, String> res = databaseUserImplementation.userLogger(user);
|
||||
System.out.println(res);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue