Pārlūkot izejas kodu

added rough transaction class

yauhenip 6 gadus atpakaļ
vecāks
revīzija
65e687ca92
2 mainītis faili ar 52 papildinājumiem un 16 dzēšanām
  1. 16
    16
      .idea/workspace.xml
  2. 36
    0
      src/main/java/com/buecoin01/model/Transaction.java

+ 16
- 16
.idea/workspace.xml Parādīt failu

@@ -2,7 +2,7 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="15cb9d44-2114-4e87-9e35-a3d14b1a4bbd" name="Default" comment="">
5
-      <change beforePath="$PROJECT_DIR$/0.1.iml" beforeDir="false" />
5
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6 6
       <change beforePath="$PROJECT_DIR$/src/main/java/com/buecoin01/model/Wallet.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/buecoin01/model/Wallet.java" afterDir="false" />
7 7
     </list>
8 8
     <ignored path="$PROJECT_DIR$/target/" />
@@ -15,11 +15,11 @@
15 15
   </component>
16 16
   <component name="FileEditorManager">
17 17
     <leaf>
18
-      <file leaf-file-name="Wallet.java" pinned="false" current-in-tab="false">
18
+      <file leaf-file-name="Wallet.java" pinned="false" current-in-tab="true">
19 19
         <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Wallet.java">
20 20
           <provider selected="true" editor-type-id="text-editor">
21
-            <state relative-caret-position="372">
22
-              <caret line="69" column="5" lean-forward="true" selection-start-line="69" selection-start-column="5" selection-end-line="69" selection-end-column="5" />
21
+            <state relative-caret-position="446">
22
+              <caret line="68" selection-start-line="68" selection-end-line="68" />
23 23
               <folding>
24 24
                 <element signature="imports" expanded="true" />
25 25
                 <element signature="e#549#550#0" expanded="true" />
@@ -29,7 +29,7 @@
29 29
           </provider>
30 30
         </entry>
31 31
       </file>
32
-      <file leaf-file-name="Blockchain.java" pinned="false" current-in-tab="true">
32
+      <file leaf-file-name="Blockchain.java" pinned="false" current-in-tab="false">
33 33
         <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Blockchain.java">
34 34
           <provider selected="true" editor-type-id="text-editor">
35 35
             <state relative-caret-position="55">
@@ -219,12 +219,12 @@
219 219
       <option name="number" value="Default" />
220 220
       <option name="presentableId" value="Default" />
221 221
       <updated>1532353115597</updated>
222
-      <workItem from="1532353121145" duration="1724000" />
222
+      <workItem from="1532353121145" duration="2380000" />
223 223
     </task>
224 224
     <servers />
225 225
   </component>
226 226
   <component name="TimeTrackingManager">
227
-    <option name="totallyTimeSpent" value="1724000" />
227
+    <option name="totallyTimeSpent" value="2380000" />
228 228
   </component>
229 229
   <component name="ToolWindowManager">
230 230
     <frame x="-57" y="-1047" width="1832" height="903" extended-state="0" />
@@ -290,10 +290,17 @@
290 290
         </state>
291 291
       </provider>
292 292
     </entry>
293
+    <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Blockchain.java">
294
+      <provider selected="true" editor-type-id="text-editor">
295
+        <state relative-caret-position="55">
296
+          <caret line="9" column="13" selection-start-line="9" selection-start-column="13" selection-end-line="9" selection-end-column="13" />
297
+        </state>
298
+      </provider>
299
+    </entry>
293 300
     <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Wallet.java">
294 301
       <provider selected="true" editor-type-id="text-editor">
295
-        <state relative-caret-position="372">
296
-          <caret line="69" column="5" lean-forward="true" selection-start-line="69" selection-start-column="5" selection-end-line="69" selection-end-column="5" />
302
+        <state relative-caret-position="446">
303
+          <caret line="68" selection-start-line="68" selection-end-line="68" />
297 304
           <folding>
298 305
             <element signature="imports" expanded="true" />
299 306
             <element signature="e#549#550#0" expanded="true" />
@@ -302,13 +309,6 @@
302 309
         </state>
303 310
       </provider>
304 311
     </entry>
305
-    <entry file="file://$PROJECT_DIR$/src/main/java/com/buecoin01/model/Blockchain.java">
306
-      <provider selected="true" editor-type-id="text-editor">
307
-        <state relative-caret-position="55">
308
-          <caret line="9" column="13" selection-start-line="9" selection-start-column="13" selection-end-line="9" selection-end-column="13" />
309
-        </state>
310
-      </provider>
311
-    </entry>
312 312
   </component>
313 313
   <component name="masterDetails">
314 314
     <states>

+ 36
- 0
src/main/java/com/buecoin01/model/Transaction.java Parādīt failu

@@ -0,0 +1,36 @@
1
+package com.buecoin01.model;
2
+
3
+import com.buecoin01.utility.Encryption;
4
+
5
+import java.security.PublicKey;
6
+import java.util.ArrayList;
7
+
8
+public class Transaction {
9
+    private String transactionId; //hash of the transaction
10
+    private PublicKey sender;
11
+    private PublicKey reciepient;
12
+    private float value;
13
+    private byte[] signature;
14
+
15
+    private List<TransactionInput> inputs = new ArrayList<>();
16
+    private List<TransactionOutput> outputs = new ArrayList<>();
17
+
18
+    private static int sequence = 0; //how many transactions have been generated
19
+
20
+    public Transaction(PublicKey from, PublicKey to, float value, ArrayList<TransactionInput> inputs) {
21
+        this.sender = from;
22
+        this.reciepient = to;
23
+        this.value = value;
24
+        this.inputs = inputs;
25
+    }
26
+
27
+    //generating transactionId
28
+    private String calculateHash() {
29
+        sequence++; //increasing tho avoid identical hash codes
30
+        return Encryption.applySha256(
31
+                Encryption.getStringFromKey(sender) +
32
+                       Encryption.getStringFromKey(reciepient) +
33
+                       Float.toString(value) + sequence
34
+                       );
35
+    }
36
+}