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 : #include "wsv_restorer_impl.hpp"
19 :
20 : #include <vector>
21 :
22 : #include "ametsuchi/block_query.hpp"
23 : #include "ametsuchi/storage.hpp"
24 : #include "interfaces/iroha_internal/block.hpp"
25 :
26 : namespace iroha {
27 : namespace ametsuchi {
28 : expected::Result<void, std::string> WsvRestorerImpl::restoreWsv(
29 : Storage &storage) {
30 : // get all blocks starting from the genesis
31 : std::vector<std::shared_ptr<shared_model::interface::Block>> blocks=
32 246 : storage.getBlockQuery()->getBlocksFrom(1);
33 :
34 246 : storage.reset();
35 :
36 246 : if (not storage.insertBlocks(blocks))
37 0 : return expected::makeError("cannot insert blocks");
38 :
39 246 : return expected::Value<void>();
40 246 : }
41 : } // namespace ametsuchi
42 : } // namespace iroha
|