Beispiel #1
0
 def __init__(self, transactions: List[Transaction] = None, state: Optional[MicroLedgerState] = None, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if transactions is not None:
         for txn in transactions:
             txn = Transaction(txn)
             if not txn.has_metadata():
                 raise SiriusContextError('Transaction must have processed by Ledger engine and has metadata')
         self['transactions'] = transactions
     if state:
         state = MicroLedgerState(state)
         self['state'] = state
         self['hash'] = state.hash
Beispiel #2
0
 def __init__(
         self, transactions: List[Transaction] = None,
         states: List[Union[MicroLedgerState, dict]] = None, *args, **kwargs
 ):
     super().__init__(*args, **kwargs)
     if transactions is not None:
         for txn in transactions:
             txn = Transaction(txn)
             if not txn.has_metadata():
                 raise SiriusContextError('Transaction must have metadata for specific Ledger')
         self['transactions'] = transactions
     if states:
         # Fix states as hash
         states = [MicroLedgerState(state) for state in states]
         # sort by ledger name, assume ledger name is unique in system
         # to make available to calc accumulated hash predictable
         states = list(sorted(states, key=lambda s: s.name))
         accum = hashlib.sha256()
         for state in states:
             accum.update(state.hash.encode())
         self['hash'] = accum.hexdigest()