LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf/queries/impl - proto_query.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 36 40 90.0 %
Date: 2018-12-05 17:11:35 Functions: 26 29 89.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/queries/proto_query.hpp"
       7             : 
       8             : #include "backend/protobuf/common_objects/signature.hpp"
       9             : #include "backend/protobuf/queries/proto_get_account.hpp"
      10             : #include "backend/protobuf/queries/proto_get_account_asset_transactions.hpp"
      11             : #include "backend/protobuf/queries/proto_get_account_assets.hpp"
      12             : #include "backend/protobuf/queries/proto_get_account_detail.hpp"
      13             : #include "backend/protobuf/queries/proto_get_account_transactions.hpp"
      14             : #include "backend/protobuf/queries/proto_get_asset_info.hpp"
      15             : #include "backend/protobuf/queries/proto_get_pending_transactions.hpp"
      16             : #include "backend/protobuf/queries/proto_get_role_permissions.hpp"
      17             : #include "backend/protobuf/queries/proto_get_roles.hpp"
      18             : #include "backend/protobuf/queries/proto_get_signatories.hpp"
      19             : #include "backend/protobuf/queries/proto_get_transactions.hpp"
      20             : #include "backend/protobuf/util.hpp"
      21             : #include "utils/variant_deserializer.hpp"
      22             : 
      23             : namespace {
      24             :   /// type of proto variant
      25             :   using ProtoQueryVariantType =
      26             :       boost::variant<shared_model::proto::GetAccount,
      27             :                      shared_model::proto::GetSignatories,
      28             :                      shared_model::proto::GetAccountTransactions,
      29             :                      shared_model::proto::GetAccountAssetTransactions,
      30             :                      shared_model::proto::GetTransactions,
      31             :                      shared_model::proto::GetAccountAssets,
      32             :                      shared_model::proto::GetAccountDetail,
      33             :                      shared_model::proto::GetRoles,
      34             :                      shared_model::proto::GetRolePermissions,
      35             :                      shared_model::proto::GetAssetInfo,
      36             :                      shared_model::proto::GetPendingTransactions>;
      37             : 
      38             :   /// list of types in proto variant
      39             :   using ProtoQueryListType = ProtoQueryVariantType::types;
      40             : }  // namespace
      41             : 
      42             : namespace shared_model {
      43             :   namespace proto {
      44             : 
      45             :     struct Query::Impl {
      46             :       explicit Impl(TransportType &&ref) : proto_{std::move(ref)} {}
      47             :       explicit Impl(const TransportType &ref) : proto_{ref} {}
      48             : 
      49             :       detail::ReferenceHolder<TransportType> proto_;
      50             : 
      51             :       ProtoQueryVariantType variant_{[this] {
      52         439 :         auto &&ar = *proto_;
      53         439 :         int which = ar.payload()
      54         439 :                         .GetDescriptor()
      55         439 :                         ->FindFieldByNumber(ar.payload().query_case())
      56         439 :                         ->index_in_oneof();
      57         439 :         return shared_model::detail::variant_impl<ProtoQueryListType>::
      58         439 :             template load<ProtoQueryVariantType>(std::forward<decltype(ar)>(ar),
      59         439 :                                                  which);
      60             :       }()};
      61             : 
      62         417 :       QueryVariantType ivariant_{variant_};
      63             : 
      64         416 :       interface::types::BlobType blob_{makeBlob(*proto_)};
      65             : 
      66         418 :       interface::types::BlobType payload_{makeBlob(proto_->payload())};
      67             : 
      68             :       SignatureSetType<proto::Signature> signatures_{[this] {
      69         439 :         SignatureSetType<proto::Signature> set;
      70         439 :         if (proto_->has_signature()) {
      71         170 :           set.emplace(proto_->signature());
      72         170 :         }
      73         439 :         return set;
      74         439 :       }()};
      75             :     };
      76             : 
      77             :     Query::Query(const Query &o) : Query(*o.impl_->proto_) {}
      78             :     Query::Query(Query &&o) noexcept = default;
      79             : 
      80             :     Query::Query(const TransportType &ref) {
      81          21 :       impl_ = std::make_unique<Impl>(ref);
      82          21 :     }
      83             :     Query::Query(TransportType &&ref) {
      84         418 :       impl_ = std::make_unique<Impl>(std::move(ref));
      85         418 :     }
      86             : 
      87             :     Query::~Query() = default;
      88             : 
      89             :     const Query::QueryVariantType &Query::get() const {
      90         543 :       return impl_->ivariant_;
      91             :     }
      92             : 
      93             :     const interface::types::AccountIdType &Query::creatorAccountId() const {
      94         672 :       return impl_->proto_->payload().meta().creator_account_id();
      95             :     }
      96             : 
      97             :     interface::types::CounterType Query::queryCounter() const {
      98         361 :       return impl_->proto_->payload().meta().query_counter();
      99             :     }
     100             : 
     101             :     const interface::types::BlobType &Query::blob() const {
     102           0 :       return impl_->blob_;
     103             :     }
     104             : 
     105             :     const interface::types::BlobType &Query::payload() const {
     106         557 :       return impl_->payload_;
     107             :     }
     108             : 
     109             :     interface::types::SignatureRangeType Query::signatures() const {
     110         641 :       return impl_->signatures_;
     111             :     }
     112             : 
     113             :     bool Query::addSignature(const crypto::Signed &signed_blob,
     114             :                              const crypto::PublicKey &public_key) {
     115         178 :       if (impl_->proto_->has_signature()) {
     116           0 :         return false;
     117             :       }
     118             : 
     119         177 :       auto sig = impl_->proto_->mutable_signature();
     120         177 :       sig->set_signature(crypto::toBinaryString(signed_blob));
     121         177 :       sig->set_public_key(crypto::toBinaryString(public_key));
     122             : 
     123         178 :       impl_->signatures_ =
     124         177 :           SignatureSetType<proto::Signature>{proto::Signature{*sig}};
     125             : 
     126         178 :       return true;
     127         177 :     }
     128             : 
     129             :     interface::types::TimestampType Query::createdTime() const {
     130         360 :       return impl_->proto_->payload().meta().created_time();
     131             :     }
     132             : 
     133             :     const Query::TransportType &Query::getTransport() const {
     134         177 :       return *impl_->proto_;
     135             :     }
     136             : 
     137             :     Query *Query::clone() const {
     138           0 :       return new Query(*impl_->proto_);
     139           0 :     }
     140             : 
     141             :   }  // namespace proto
     142             : }  // namespace shared_model

Generated by: LCOV version 1.13