LCOV - code coverage report
Current view: top level - irohad/model/converters/impl - pb_transaction_factory.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 32 32 100.0 %
Date: 2019-03-07 14:46:43 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "model/converters/pb_transaction_factory.hpp"
       7             : #include "model/commands/add_asset_quantity.hpp"
       8             : #include "model/converters/pb_command_factory.hpp"
       9             : 
      10             : namespace iroha {
      11             :   namespace model {
      12             :     namespace converters {
      13             : 
      14             :       protocol::Transaction PbTransactionFactory::serialize(
      15             :           const model::Transaction &tx) {
      16          13 :         model::converters::PbCommandFactory factory;
      17          13 :         protocol::Transaction pbtx;
      18             : 
      19          13 :         auto pl = pbtx.mutable_payload()->mutable_reduced_payload();
      20          13 :         pl->set_created_time(tx.created_ts);
      21          13 :         pl->set_creator_account_id(tx.creator_account_id);
      22          13 :         pl->set_quorum(tx.quorum);
      23             : 
      24          39 :         for (const auto &command : tx.commands) {
      25          26 :           auto cmd = pl->add_commands();
      26          26 :           new (cmd)
      27          26 :               protocol::Command(factory.serializeAbstractCommand(*command));
      28             :         }
      29             : 
      30          20 :         for (const auto &sig_obj : tx.signatures) {
      31           7 :           auto proto_signature = pbtx.add_signatures();
      32           7 :           proto_signature->set_public_key(sig_obj.pubkey.to_hexstring());
      33           7 :           proto_signature->set_signature(sig_obj.signature.to_hexstring());
      34             :         }
      35          13 :         return pbtx;
      36          13 :       }
      37             : 
      38             :       std::shared_ptr<model::Transaction> PbTransactionFactory::deserialize(
      39             :           const protocol::Transaction &pb_tx) {
      40           2 :         model::converters::PbCommandFactory commandFactory;
      41           2 :         model::Transaction tx;
      42             : 
      43           2 :         const auto &pl = pb_tx.payload().reduced_payload();
      44           2 :         tx.creator_account_id = pl.creator_account_id();
      45           2 :         tx.created_ts = pl.created_time();
      46           2 :         tx.quorum = static_cast<uint8_t>(pl.quorum());
      47             : 
      48           4 :         for (const auto &pb_sig : pb_tx.signatures()) {
      49           2 :           model::Signature sig{};
      50           2 :           sig.pubkey = pubkey_t::from_hexstring(pb_sig.public_key());
      51           2 :           sig.signature = sig_t::from_hexstring(pb_sig.signature());
      52           2 :           tx.signatures.push_back(sig);
      53             :         }
      54             : 
      55           6 :         for (const auto &pb_command : pl.commands()) {
      56           4 :           tx.commands.push_back(
      57           4 :               commandFactory.deserializeAbstractCommand(pb_command));
      58             :         }
      59           2 :         return std::make_shared<model::Transaction>(tx);
      60           2 :       }
      61             : 
      62             :     }  // namespace converters
      63             :   }    // namespace model
      64             : }  // namespace iroha

Generated by: LCOV version 1.13