Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2018 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #ifndef IROHA_SHARED_MODEL_PROTO_PEER_HPP
19 : #define IROHA_SHARED_MODEL_PROTO_PEER_HPP
20 :
21 : #include "interfaces/common_objects/peer.hpp"
22 :
23 : #include "backend/protobuf/common_objects/trivial_proto.hpp"
24 : #include "backend/protobuf/util.hpp"
25 : #include "cryptography/public_key.hpp"
26 : #include "primitive.pb.h"
27 : #include "utils/lazy_initializer.hpp"
28 :
29 : namespace shared_model {
30 : namespace proto {
31 : class Peer final
32 : : public CopyableProto<interface::Peer, iroha::protocol::Peer, Peer> {
33 : public:
34 : template <typename PeerType>
35 : explicit Peer(PeerType &&peer)
36 5038 : : CopyableProto(std::forward<PeerType>(peer)) {}
37 :
38 : Peer(const Peer &o) : Peer(o.proto_) {}
39 :
40 : Peer(Peer &&o) noexcept : Peer(std::move(o.proto_)) {}
41 :
42 : const interface::types::AddressType &address() const override {
43 11415 : return proto_->address();
44 : }
45 :
46 : const interface::types::PubkeyType &pubkey() const override {
47 5053 : return *public_key_;
48 : }
49 :
50 : private:
51 : // lazy
52 : template <typename T>
53 : using Lazy = detail::LazyInitializer<T>;
54 :
55 5038 : const Lazy<interface::types::PubkeyType> public_key_{
56 : [this] { return interface::types::PubkeyType(proto_->peer_key()); }};
57 : };
58 :
59 : } // namespace proto
60 : } // namespace shared_model
61 : #endif // IROHA_SHARED_MODEL_PROTO_PEER_HPP
|