Skip to content

Commit

Permalink
Separate MutableState to TemporaryWSV and MutableStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
lebdron committed Jun 23, 2017
1 parent 254997b commit d555f55
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 86 deletions.
18 changes: 9 additions & 9 deletions irohad/ametsuchi/ametsuchi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#ifndef IROHA_AMETSUCHI_H
#define IROHA_AMETSUCHI_H

#include <ametsuchi/mutable_state.hpp>
#include <ametsuchi/query_api.hpp>
#include <ametsuchi/block_query.hpp>
#include <ametsuchi/mutable_storage.hpp>
#include <ametsuchi/state_query.hpp>
#include <ametsuchi/temporary_wsv.hpp>

namespace iroha {

Expand All @@ -29,19 +31,17 @@ namespace iroha {
* Storage class, which allows queries on current committed state, and
* creation of state which can be mutated with blocks and transactions
*/
class Ametsuchi : public QueryApi {
class Ametsuchi : public StateQuery, public BlockQuery {
public:
/**
* Creates a mutable state from the current state
* @return Created mutable state
*/
virtual std::unique_ptr<MutableState> createMutableState() = 0;
virtual TemporaryWSV* createTemporaryWSV() = 0;

/**
* Permanently applies the mutable state to storage
* @param state Mutated state to be applied
*/
virtual void applyMutableState(MutableState&& state) = 0;
virtual MutableStorage* createMutableStorage() = 0;

virtual void commit(MutableStorage* mutableStorage) = 0;
};

} // namespace ametsuchi
Expand Down
56 changes: 56 additions & 0 deletions irohad/ametsuchi/block_query.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 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_BLOCK_QUERY_HPP
#define IROHA_BLOCK_QUERY_HPP

namespace iroha {

namespace ametsuchi {

class BlockQuery {
public:
/**
* Get all transactions of an account.
* @param pub_key - account's first public key
* @return observable of DAO Transaction
*/
virtual rxcpp::observable<iroha::dao::Transaction>
get_account_transactions(iroha::crypto::ed25519::pubkey_t pub_key) = 0;

/**
* Get all transactions with a certain asset
* @param asset_full_name - full name of an asset, i.e. name#domain
* @return observable of DAO Transaction
*/
virtual rxcpp::observable<iroha::dao::Transaction> get_asset_transactions(
std::string asset_full_name) = 0;

/**
* Get all transactions of a certain wallet
* @param wallet_id - unique wallet
* @return observable of DAO Transaction
*/
virtual rxcpp::observable<iroha::dao::Transaction>
get_wallet_transactions(std::string wallet_id) = 0;
};

} // namespace ametsuchi

} // namespace iroha

#endif // IROHA_BLOCK_QUERY_HPP
33 changes: 33 additions & 0 deletions irohad/ametsuchi/command_executor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 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_COMMANDEXECUTOR_HPP
#define IROHA_COMMANDEXECUTOR_HPP

namespace iroha {

namespace ametsuchi {

class CommandExecutor {
virtual void execute(dao::Command command) = 0;
};

} // namespace ametsuchi

}// namespace iroha

#endif //IROHA_COMMANDEXECUTOR_HPP
36 changes: 36 additions & 0 deletions irohad/ametsuchi/mutable_storage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 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_MUTABLESTORAGE_HPP
#define IROHA_MUTABLESTORAGE_HPP

#include <ametsuchi/command_executor.hpp>

namespace iroha {
namespace ametsuchi {

class MutableStorage : public WSVQuery, public BlockQuery {
virtual bool apply(
dao::Block block,
std::function<void(dao::Block, CommandExecutor, WSVQuery)>
function) = 0;
};

} // namespace ametsuchi
} // namespace iroha

#endif // IROHA_MUTABLESTORAGE_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
* limitations under the License.
*/

#ifndef IROHA_MUTABLESTATE_HPP
#define IROHA_MUTABLESTATE_HPP
#ifndef IROHA_TEMPORARYWSV_HPP
#define IROHA_TEMPORARYWSV_HPP

#include <ametsuchi/query_api.hpp>
#include <ametsuchi/command_executor.hpp>
#include <ametsuchi/wsv_query.hpp>
#include <dao/block.hpp>
#include <dao/transaction.hpp>

Expand All @@ -27,37 +28,11 @@ namespace iroha {
namespace ametsuchi {

/**
* Reflects a temporary state of storage
* Reflects a temporary state of world state view
* Allows queries on the temporary state
*/
class MutableState : public QueryApi {
class TemporaryWSV : public WSVQuery {
public:
/**
* Specifies the error during apply process in TransactionContext
*/
class StorageException;

/**
* The context used in @see apply transaction method
*/
class TransactionContext {
/**
* Attempts to apply a command to current mutable state
* Throws exception in case of internal error
* @tparam T Command type
* @param command Command to be applied
* @throws StorageException
*/
template <class T>
void try_apply(T command);
};

/**
* Applies a block to current mutable state
* @param block Block to be applied
*/
virtual void apply(dao::Block block) = 0;

/**
* Applies a transaction to current mutable state
* using logic specified in function
Expand All @@ -67,12 +42,12 @@ namespace iroha {
*/
virtual bool apply(
dao::Transaction transaction,
std::function<void(dao::Transaction, TransactionContext)>
std::function<void(dao::Transaction, CommandExecutor, WSVQuery)>
function) = 0;
};

} // namespace ametsuchi

} // namespace iroha

#endif // IROHA_MUTABLESTATE_HPP
#endif // IROHA_TEMPORARYWSV_HPP
65 changes: 21 additions & 44 deletions irohad/ametsuchi/query_api.hpp → irohad/ametsuchi/wsv_query.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/*
Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved.
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_QUERY_API_HPP
#define IROHA_QUERY_API_HPP
/**
* Copyright Soramitsu Co., Ltd. 2017 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_WSVQUERY_HPP
#define IROHA_WSVQUERY_HPP

#include <common.hpp>
#include <dao/dao.hpp>
Expand All @@ -27,7 +28,7 @@ namespace iroha {

namespace ametsuchi {

class QueryApi {
class WSVQuery {
public:
/**
* Get account by it's first public key.
Expand Down Expand Up @@ -73,34 +74,10 @@ namespace iroha {
*/
virtual std::vector<iroha::dao::Asset> get_domain_assets(
std::string domain_full_name) = 0;

/**
* Get all transactions of an account.
* @param pub_key - account's first public key
* @return observable of DAO Transaction
*/
virtual rxcpp::observable<iroha::dao::Transaction>
get_account_transactions(iroha::crypto::ed25519::pubkey_t pub_key) = 0;

/**
* Get all transactions with a certain asset
* @param asset_full_name - full name of an asset, i.e. name#domain
* @return observable of DAO Transaction
*/
virtual rxcpp::observable<iroha::dao::Transaction> get_asset_transactions(
std::string asset_full_name) = 0;

/**
* Get all transactions of a certain wallet
* @param wallet_id - unique wallet
* @return observable of DAO Transaction
*/
virtual rxcpp::observable<iroha::dao::Transaction>
get_wallet_transactions(std::string wallet_id) = 0;
};

} // namespace ametsuchi

} // namespace iroha

#endif // IROHA_QUERY_API_HPP
#endif // IROHA_WSVQUERY_HPP

0 comments on commit d555f55

Please sign in to comment.