Pārlūkot izejas kodu

Fix hashed transaction submission

DebenOldert 4 gadi atpakaļ
vecāks
revīzija
77ba70f89e
3 mainītis faili ar 20 papildinājumiem un 4 dzēšanām
  1. 7 1
      gui/main.py
  2. 5 3
      lib/block.py
  3. 8 0
      lib/transaction.py

+ 7 - 1
gui/main.py

@@ -24,6 +24,12 @@ if __name__ == '__main__':
     # Add term to contract1
     contract1.add_term(term=term1)
 
-    conn.root.push_contract(contract1.serialize(out_json=True))
+    # Bind contract to transaction
+    transaction1 = Transaction()
+    transaction1.set_contract(contract=contract1)
+
+    hashed = transaction1.serialize(out_json=True)
+
+    conn.root.push_transaction(hashed)
 
     conn.close()

+ 5 - 3
lib/block.py

@@ -20,17 +20,19 @@ class Block:
             return CURRENT
 
     def __init__(self, previous=None):
-        self.proof = None
         self.previous_hash = previous.hash_value if previous is not None else None
         self.transactions = []
         self.hash_value = None
         self.locked = False
         self.timestamp = 0
         self.height = previous.height + 1 if previous is not None else 0
+        self.nonce = self.height
 
     def add_hashed_transaction(self, hashed: str):
-        self.transactions.append(hashed)
-        self.log(f'Transaction added: {hashed}')
+        trans = Transaction()
+        trans.from_serialized(hashed)
+        self.transactions.append(trans)
+        self.log(f'Hashed transaction added: {hashed}')
         return True
 
     def add_transaction(self, trans: Transaction):

+ 8 - 0
lib/transaction.py

@@ -16,6 +16,14 @@ class Transaction:
         self.sender = None
         self.receiver = None
 
+    def from_serialized(self, jsonobj: str):
+        obj = json.loads(jsonobj)
+        self.id = obj['id']
+        self.data = obj['data']
+        self.timestamp = obj['timestamp']
+        self.sender = obj['sender']
+        self.receiver = obj['receiver']
+
     def set_serialized_contract(self, serialized):
         if not self.locked:
             self.id = str(uuid.uuid1())