This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 35
/
mongo_db_writer.hpp
66 lines (47 loc) · 1.65 KB
/
mongo_db_writer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <golos/protocol/block.hpp>
#include <golos/chain/database.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/stream/array.hpp>
#include <bsoncxx/builder/stream/value_context.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <map>
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
namespace golos {
namespace plugins {
namespace mongo_db {
using golos::protocol::signed_block;
class mongo_db_writer final {
public:
mongo_db_writer();
~mongo_db_writer() = default;
void initialize(const std::string& uri_str);
void on_block(const signed_block& block);
private:
void write_blocks();
void write_block(const signed_block& block, mongocxx::bulk_write& _bulk);
size_t processed_blocks = 0;
std::string db_name;
static const std::string blocks_table;
static const std::string trans_table;
// Key = Block num, Value = block
uint32_t last_irreversible_block_num;
std::map<uint32_t, signed_block> _blocks;
// Mongo connection members
mongocxx::instance mongo_inst;
mongocxx::uri uri;
mongocxx::client mongo_conn;
golos::chain::database &_db;
};
}}}