diff --git a/irohad/torii/impl/command_service.cpp b/irohad/torii/impl/command_service.cpp index d2369c7d40..c12418d189 100644 --- a/irohad/torii/impl/command_service.cpp +++ b/irohad/torii/impl/command_service.cpp @@ -16,6 +16,7 @@ */ #include + #include "backend/protobuf/transaction_responses/proto_tx_response.hpp" #include "ametsuchi/block_query.hpp" @@ -24,6 +25,7 @@ #include "builders/protobuf/transport_builder.hpp" #include "common/byteutils.hpp" #include "common/types.hpp" +#include "cryptography/default_hash_provider.hpp" #include "endpoint.pb.h" #include "torii/command_service.hpp" #include "validators/default_validator.hpp" @@ -100,9 +102,8 @@ namespace torii { // getting hash from invalid transaction auto blobPayload = shared_model::proto::makeBlob(request.payload()); - tx_hash = - shared_model::proto::Transaction::HashProviderType::makeHash( - blobPayload); + tx_hash = shared_model::crypto::DefaultHashProvider::makeHash( + blobPayload); log_->warn("Stateless invalid tx: {}, hash: {}", error.error, tx_hash.hex()); diff --git a/irohad/torii/impl/query_service.cpp b/irohad/torii/impl/query_service.cpp index e67a7e6a58..6d3c0f9245 100644 --- a/irohad/torii/impl/query_service.cpp +++ b/irohad/torii/impl/query_service.cpp @@ -17,6 +17,7 @@ #include "torii/query_service.hpp" #include "backend/protobuf/query_responses/proto_query_response.hpp" +#include "cryptography/default_hash_provider.hpp" #include "validators/default_validator.hpp" namespace torii { @@ -41,7 +42,7 @@ namespace torii { iroha::protocol::QueryResponse &response) { shared_model::crypto::Hash hash; auto blobPayload = shared_model::proto::makeBlob(request.payload()); - hash = shared_model::proto::Query::HashProviderType::makeHash(blobPayload); + hash = shared_model::crypto::DefaultHashProvider::makeHash(blobPayload); if (cache_.findItem(hash)) { // Query was already processed @@ -70,8 +71,8 @@ namespace torii { cache_.addItem(hash, response); } }, - [&hash, &response]( - const iroha::expected::Error &error) { + [&hash, + &response](const iroha::expected::Error &error) { response.set_query_hash( shared_model::crypto::toBinaryString(hash)); response.mutable_error_response()->set_reason( diff --git a/shared_model/cryptography/default_hash_provider.hpp b/shared_model/cryptography/default_hash_provider.hpp new file mode 100644 index 0000000000..ce07b4b574 --- /dev/null +++ b/shared_model/cryptography/default_hash_provider.hpp @@ -0,0 +1,30 @@ +/** + * Copyright Soramitsu Co., Ltd. 2018 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_DEFAULT_HASH_PROVIDER_HPP +#define IROHA_DEFAULT_HASH_PROVIDER_HPP + +#include "cryptography/hash_providers/sha3_256.hpp" + +namespace shared_model { + namespace crypto { + // Default class that provides hashing functionality + using DefaultHashProvider = shared_model::crypto::Sha3_256; + } // namespace crypto +} // namespace shared_model + +#endif // IROHA_DEFAULT_HASH_PROVIDER_HPP diff --git a/shared_model/interfaces/base/signable.hpp b/shared_model/interfaces/base/signable.hpp index f65164f11a..4eda8dd900 100644 --- a/shared_model/interfaces/base/signable.hpp +++ b/shared_model/interfaces/base/signable.hpp @@ -20,7 +20,7 @@ #include -#include "cryptography/hash_providers/sha3_256.hpp" +#include "cryptography/default_hash_provider.hpp" #include "interfaces/common_objects/signable_hash.hpp" #include "interfaces/common_objects/signature.hpp" #include "interfaces/common_objects/types.hpp" @@ -48,16 +48,15 @@ namespace shared_model { #ifndef DISABLE_BACKWARD template + typename HashProvider = crypto::DefaultHashProvider> class Signable : public Primitive { #else template class Signable : public ModelPrimitive { #endif - public: - using HashProviderType = HashProvider; + public: /** * @return attached signatures */ @@ -105,7 +104,7 @@ namespace shared_model { const types::HashType &hash() const { if (hash_ == boost::none) { - hash_.emplace(HashProviderType::makeHash(payload())); + hash_.emplace(HashProvider::makeHash(payload())); } return *hash_; }