Skip to content

Commit

Permalink
Merge pull request hyperledger-iroha#384 from hyperledger/feature/ame…
Browse files Browse the repository at this point in the history
…tsuchi-api

Ametsuchi API
  • Loading branch information
lebdron authored Jun 26, 2017
2 parents a77c963 + 5e1d77a commit 0caa9bd
Show file tree
Hide file tree
Showing 17 changed files with 602 additions and 222 deletions.
14 changes: 6 additions & 8 deletions irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# here will be the code, which is responsible for connection to ametsuchi
message(STATUS "Ametsuchi")

add_subdirectory(block_store)
add_subdirectory(index)
add_subdirectory(wsv)
#add_subdirectory(block_store)
#add_subdirectory(index)
#add_subdirectory(wsv)

add_library(storage
impl/ametsuchi.cpp
index_mediator.cpp
# impl/ametsuchi_impl.cpp
# index_mediator.cpp
)

target_link_libraries(storage PUBLIC
Expand All @@ -18,4 +15,5 @@ target_link_libraries(storage PUBLIC
block_store
index
wsv
rxcpp
)
66 changes: 66 additions & 0 deletions irohad/ametsuchi/ametsuchi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* 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_AMETSUCHI_H
#define IROHA_AMETSUCHI_H

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

namespace iroha {

namespace ametsuchi {

/**
* Storage interface, which allows queries on current committed state, and
* creation of state which can be mutated with blocks and transactions
*/
class Ametsuchi : public StateQuery, public BlockQuery {
public:

/**
* Creates a temporary world state view from the current state.
* Temporary state will be not committed and will be erased on destructor
* call.
* Temporary state might be used for transaction validation.
* @return Created temporary wsv
*/
virtual std::unique_ptr<TemporaryWsv> createTemporaryWsv() = 0;

/**
* Creates a mutable storage from the current state.
* Mutable storage is the only way to commit the block to the ledger.
* @return Created mutable storage
*/
virtual std::unique_ptr<MutableStorage> createMutableStorage() = 0;

/**
* Commit mutable storage to Ametsuchi.
* This transforms Ametsuchi to the new state consistent with
* MutableStorage.
* @param mutableStorage
*/
virtual void commit(std::unique_ptr<MutableStorage>& mutableStorage) = 0;
};

} // namespace ametsuchi

} // namespace iroha

#endif // IROHA_AMETSUCHI_H
58 changes: 58 additions & 0 deletions irohad/ametsuchi/block_query.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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 {
/**
* Public interface for queries on blocks and transactions
*/
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
43 changes: 43 additions & 0 deletions irohad/ametsuchi/command_executor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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

#include <dao/command.hpp>

namespace iroha {

namespace ametsuchi {
/**
* Applies command to the world state view
*/
class CommandExecutor {
/**
* Executes a command in a temporary state
* @see TemporaryWsv, MutableStorage
* @param command Command to execute
* @return True if the command is successfully executed, false otherwise
*/
virtual bool execute(dao::Command command) = 0;
};

} // namespace ametsuchi

}// namespace iroha

#endif //IROHA_COMMANDEXECUTOR_HPP
54 changes: 54 additions & 0 deletions irohad/ametsuchi/mutable_storage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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 {
/**
* Mutable storage is used apply blocks to the storage.
* Allows to query the world state view, transactions, and blocks.
*/
class MutableStorage : public WsvQuery, public BlockQuery {
/**
* Applies a block to current mutable state
* using logic specified in function
* @param block Block to be applied
* @param function Function that specifies the logic used to apply the
* block
* Function parameters:
* - Block @see block
* - CommandExecutor
* - WsvQuery
* Function returns true if the block is successfully applied, false
* otherwise.
* @return True if block was successfully applied, false otherwise.
*
*/
virtual bool apply(
dao::Block block,
std::function<bool(dao::Block, CommandExecutor, WsvQuery)>
function) = 0;
};

} // namespace ametsuchi
} // namespace iroha

#endif // IROHA_MUTABLESTORAGE_HPP
80 changes: 0 additions & 80 deletions irohad/ametsuchi/storage.hpp

This file was deleted.

61 changes: 61 additions & 0 deletions irohad/ametsuchi/temporary_wsv.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* 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_TEMPORARYWSV_HPP
#define IROHA_TEMPORARYWSV_HPP

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

namespace iroha {

namespace ametsuchi {

/**
* Temporary world state view
* Allows to query the temporal world state view
*/
class TemporaryWsv : public WsvQuery {
public:
/**
* Applies a transaction to current state
* using logic specified in function
* @param transaction Transaction to be applied
* @param function Function that specifies the logic used to apply the
* transaction
* Function parameters:
* - Transaction @see transaction
* - CommandExecutor
* - WSVQuery
* Function returns true if the transaction is successfully applied, false
* otherwise.
* @return True if transaction was successfully applied, false otherwise
*
*/
virtual bool apply(
dao::Transaction transaction,
std::function<bool(dao::Transaction&, CommandExecutor&, WsvQuery&)>
function) = 0;
};

} // namespace ametsuchi

} // namespace iroha

#endif // IROHA_TEMPORARYWSV_HPP
Loading

0 comments on commit 0caa9bd

Please sign in to comment.