forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hyperledger-iroha#384 from hyperledger/feature/ame…
…tsuchi-api Ametsuchi API
- Loading branch information
Showing
17 changed files
with
602 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.