LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf/impl - proto_tx_status_factory.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 27 38 71.1 %
Date: 2018-12-05 17:11:35 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "backend/protobuf/proto_tx_status_factory.hpp"
       7             : 
       8             : #include "cryptography/hash.hpp"
       9             : #include "interfaces/common_objects/types.hpp"
      10             : 
      11             : using namespace shared_model::proto;
      12             : 
      13             : // -------------------------------| Private API |-------------------------------
      14             : 
      15             : namespace {
      16             :   /**
      17             :    * Fills common fields for all statuses
      18             :    */
      19             :   iroha::protocol::ToriiResponse fillCommon(
      20             :       ProtoTxStatusFactory::TransactionHashType hash,
      21             :       ProtoTxStatusFactory::TransactionError tx_error,
      22             :       iroha::protocol::TxStatus status) {
      23        3010 :     iroha::protocol::ToriiResponse response;
      24        3010 :     response.set_tx_hash(shared_model::crypto::toBinaryString(hash));
      25        3010 :     response.set_err_or_cmd_name(tx_error.cmd_name_);
      26        3010 :     response.set_failed_cmd_index(tx_error.cmd_index_);
      27        3010 :     response.set_error_code(tx_error.error_code_);
      28        3010 :     response.set_tx_status(status);
      29        3010 :     return response;
      30        3010 :   }
      31             : 
      32             :   /**
      33             :    * Wraps status with model object
      34             :    */
      35             :   ProtoTxStatusFactory::FactoryReturnType wrap(
      36             :       iroha::protocol::ToriiResponse &&value) {
      37        3010 :     return std::make_unique<shared_model::proto::TransactionResponse>(
      38        3010 :         std::move(value));
      39             :   }
      40             : }  // namespace
      41             : 
      42             : // ---------------------------| Stateless statuses |----------------------------
      43             : 
      44             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeStatelessFail(
      45             :     TransactionHashType hash, TransactionError tx_error) {
      46          60 :   return wrap(fillCommon(
      47          60 :       hash, tx_error, iroha::protocol::TxStatus::STATELESS_VALIDATION_FAILED));
      48           0 : }
      49             : 
      50             : ProtoTxStatusFactory::FactoryReturnType
      51             : ProtoTxStatusFactory::makeStatelessValid(TransactionHashType hash,
      52             :                                          TransactionError tx_error) {
      53         744 :   return wrap(fillCommon(
      54         744 :       hash, tx_error, iroha::protocol::TxStatus::STATELESS_VALIDATION_SUCCESS));
      55           0 : }
      56             : 
      57             : // ---------------------------| Stateful statuses |-----------------------------
      58             : 
      59             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeStatefulFail(
      60             :     TransactionHashType hash, TransactionError tx_error) {
      61          60 :   return wrap(fillCommon(
      62          60 :       hash, tx_error, iroha::protocol::TxStatus::STATEFUL_VALIDATION_FAILED));
      63           0 : }
      64             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeStatefulValid(
      65             :     TransactionHashType hash, TransactionError tx_error) {
      66         682 :   return wrap(fillCommon(
      67         682 :       hash, tx_error, iroha::protocol::TxStatus::STATEFUL_VALIDATION_SUCCESS));
      68           0 : }
      69             : 
      70             : // -----------------------------| Final statuses |------------------------------
      71             : 
      72             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeCommitted(
      73             :     TransactionHashType hash, TransactionError tx_error) {
      74         678 :   return wrap(fillCommon(hash, tx_error, iroha::protocol::TxStatus::COMMITTED));
      75           0 : }
      76             : 
      77             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeRejected(
      78             :     TransactionHashType hash, TransactionError tx_error) {
      79           0 :   return wrap(fillCommon(hash, tx_error, iroha::protocol::TxStatus::REJECTED));
      80           0 : }
      81             : 
      82             : // -----------------------------| Rest statuses |-------------------------------
      83             : 
      84             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeMstExpired(
      85             :     TransactionHashType hash, TransactionError tx_error) {
      86           3 :   return wrap(
      87           3 :       fillCommon(hash, tx_error, iroha::protocol::TxStatus::MST_EXPIRED));
      88           0 : }
      89             : 
      90             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeMstPending(
      91             :     TransactionHashType hash, TransactionError tx_error) {
      92           8 :   return wrap(
      93           8 :       fillCommon(hash, tx_error, iroha::protocol::TxStatus::MST_PENDING));
      94           0 : }
      95             : 
      96             : ProtoTxStatusFactory::FactoryReturnType ProtoTxStatusFactory::makeNotReceived(
      97             :     TransactionHashType hash, TransactionError tx_error) {
      98          18 :   return wrap(
      99          18 :       fillCommon(hash, tx_error, iroha::protocol::TxStatus::NOT_RECEIVED));
     100           0 : }
     101             : 
     102             : ProtoTxStatusFactory::FactoryReturnType
     103             : ProtoTxStatusFactory::makeEnoughSignaturesCollected(TransactionHashType hash,
     104             :                                                     TransactionError tx_error) {
     105         757 :   return wrap(fillCommon(
     106         757 :       hash, tx_error, iroha::protocol::TxStatus::ENOUGH_SIGNATURES_COLLECTED));
     107           0 : }

Generated by: LCOV version 1.13