Beispiel #1
0
 async def append(
         self,
         transactions: Union[List[Transaction], List[dict]],
         txn_time: Union[str, int] = None) -> (int, int, List[Transaction]):
     transactions_to_append = []
     for txn in transactions:
         if isinstance(txn, Transaction):
             transactions_to_append.append(txn)
         elif isinstance(txn, dict):
             transactions_to_append.append(Transaction.create(txn))
         else:
             raise RuntimeError('Unexpected transaction type')
     transactions_with_meta = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/append_txns_metadata',
         params={
             'name': self.name,
             'txns': transactions_to_append,
             'txn_time': txn_time
         })
     self.__state, start, end, appended_txns = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/append_txns',
         params={
             'name': self.name,
             'txns': transactions_with_meta,
         })
     return start, end, Transaction.from_value(appended_txns)
Beispiel #2
0
 async def get_uncommitted_transactions(self) -> List[Transaction]:
     txns = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/get_uncommitted_txns',
         params={'name': self.name})
     txns = Transaction.from_value(txns)
     assert isinstance(txns, list)
     return txns
Beispiel #3
0
 async def get_last_committed_transaction(self) -> Transaction:
     txn = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/get_last_committed_txn',
         params={'name': self.name})
     txn = Transaction.from_value(txn)
     assert isinstance(txn, Transaction)
     return txn
Beispiel #4
0
 async def commit(self, count: int) -> (int, int, List[Transaction]):
     self.__state, start, end, committed_txns = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/commit_txns',
         params={
             'name': self.name,
             'count': count,
         })
     return start, end, Transaction.from_value(committed_txns)
Beispiel #5
0
 async def init(self, genesis: List[Transaction]) -> List[Transaction]:
     self.__state, txns = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/initialize',
         params={
             'name': self.name,
             'genesis_txns': genesis
         })
     txns = [Transaction.from_value(txn) for txn in txns]
     return txns
Beispiel #6
0
 async def get_transaction(self, seq_no: int) -> Transaction:
     txn = await self.__api.remote_call(
         msg_type=
         'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/microledgers/1.0/get_by_seq_no',
         params={
             'name': self.name,
             'seqNo': seq_no
         })
     txn = Transaction.from_value(txn)
     assert isinstance(txn, Transaction)
     return txn
Beispiel #7
0
 async def append(
         self, transactions: Union[List[Transaction], List[dict]], txn_time: Union[str, int] = None
 ) -> (int, int, List[Transaction]):
     txns = []
     for i, txn in enumerate(Transaction.from_value(transactions)):
         metadata = txn.get('txnMetadata', {})
         if 'seq_no' not in metadata:
             metadata['seq_no'] = self.seq_no + 1 + i
         if 'time' not in metadata:
             metadata['time'] = txn_time or str(datetime.datetime.utcnow())
         txn['txnMetadata'] = metadata
         txns.append(txn)
     start = self.seq_no + 1
     end = start + len(txns) - 1
     self.__uncommitted.extend(txns)
     return start, end, txns