diff --git a/core/node.py b/core/node.py index da9b4ff..0bab6f3 100644 --- a/core/node.py +++ b/core/node.py @@ -12,7 +12,7 @@ class Node: def __init__(self, Network, NodeID, Genesis, PoWDelay = 1): self.TipsSet = [Genesis] self.Ledger = [Genesis] - self.LedgerTranIDs = [] + self.LedgerTranIDs = [0] self.Neighbours = [] self.Network = Network self.Inbox = Inbox(self) @@ -137,13 +137,17 @@ def parse(self, Packet, Time): Not fully implemented yet Simply makes a copy of the transaction and then calls the solidifier """ - Packet.Data = Packet.Data.copy() self.solidify(Packet, Time) - + def solidify(self, Packet, Time): """ Not implemented yet, just calls the booker """ + Packet.Data = Packet.Data.copy(self) + Tran = Packet.Data + assert isinstance(Tran, Transaction) + Tran.solidify() + self.book(Packet, Time) def book(self, Packet, Time): diff --git a/core/transaction.py b/core/transaction.py index a83bcbe..afd2b28 100644 --- a/core/transaction.py +++ b/core/transaction.py @@ -18,6 +18,7 @@ def __init__(self, IssueTime, Parents, Node, Network, Work=0, Index=None, Visibl self.Work = Work self.AWeight = Work self.LastAWUpdate = self + self.Solid = True if Node: self.NodeID = Node.NodeID # signature of issuing node self.Eligible = False @@ -69,14 +70,39 @@ def updateAW(self, Node, updateTran=None, Work=None): if not p.Confirmed and p.LastAWUpdate != updateTran: p.updateAW(Node, updateTran, Work) - def copy(self): + def copy(self, Node): Tran = copy(self) - Tran.Children = [] + Tran.Solid = True + parentIDs = [p.Index for p in Tran.Parents] + parents = [] + for pID in parentIDs: + if pID in Node.LedgerTranIDs: + parents.append(Node.Ledger[Node.LedgerTranIDs.index(pID)]) + Tran.Parents = parents + childrenIDs = [c.Index for c in Tran.Children] + children = [] + for cID in childrenIDs: + if cID in Node.LedgerTranIDs: + children.append(Node.Ledger[Node.LedgerTranIDs.index(cID)]) + Tran.Children = children Tran.Eligible = False Tran.Confirmed = False - return Tran + def solidify(self): + solidParents = [p for p in self.Parents if p.Solid] + if len(solidParents)==1: + if self.Parents[0].Index==0: # if parent is genesis + self.Solid = True + if len(solidParents)==2: # if two solid parents + self.Solid = True + for c in self.Children: + assert isinstance(c, Transaction) + if self not in c.Parents: + c.Parents.append(self) + c.solidify() + + def is_ready(self): for p in self.Parents: if not p.Eligible: