def commit_batch(self, three_pc_batch, prev_handler_result=None):
     committed_txns = prev_handler_result
     token_state_root, token_txn_root, _ = self.token_tracker.commit_batch()
     committed_seq_nos_with_fees = [
         get_seq_no(t) for t in committed_txns
         if self._fees_tracker.has_deducted_fees(get_type(t), get_seq_no(t))
     ]
     if len(committed_seq_nos_with_fees) > 0:
         # This is a fake txn only for commit to token ledger
         token_fake_three_pc_batch = ThreePcBatch(
             ledger_id=TOKEN_LEDGER_ID,
             inst_id=three_pc_batch.inst_id,
             view_no=three_pc_batch.view_no,
             pp_seq_no=three_pc_batch.pp_seq_no,
             pp_time=three_pc_batch.pp_time,
             state_root=token_state_root,
             txn_root=txn_root_serializer.serialize(token_txn_root),
             primaries=three_pc_batch.primaries,
             valid_digests=[
                 i for i in range(len(committed_seq_nos_with_fees))
             ])
         committed_token_txns = super()._commit(self.token_ledger,
                                                self.token_state,
                                                token_fake_three_pc_batch)
         TokenStaticHelper.commit_to_utxo_cache(self.utxo_cache,
                                                token_state_root)
         i = 0
         # We are adding fees txn to the reply, so that client could get information about token transition
         for txn in committed_txns:
             if get_seq_no(txn) in committed_seq_nos_with_fees:
                 txn[FEES] = committed_token_txns[i]
                 i += 1
         self._fees_tracker.fees_in_current_batch = 0
     return committed_txns
Example #2
0
def test_token_req_handler_commit_batch_different_state_root(xfer_handler_a):
    utxo_cache = xfer_handler_a.database_manager.get_store(UTXO_CACHE_LABEL)
    with pytest.raises(TokenValueError):
        TokenStaticHelper.commit_to_utxo_cache(utxo_cache, 1)
 def commit_batch(self, three_pc_batch, prev_handler_result=None):
     TokenStaticHelper.commit_to_utxo_cache(self.utxo_cache,
                                            three_pc_batch.state_root)