ledger-core
EthereumLikeWebSocketNotificationParser.h
1 /*
2  *
3  * EthereumLikeWebSocketNotificationParser
4  *
5  * Created by El Khalil Bellakrid on 29/11/2018.
6  *
7  * The MIT License (MIT)
8  *
9  * Copyright (c) 2018 Ledger
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in all
19  * copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  */
30 
31 
32 #ifndef LEDGER_CORE_ETHEREUMLIKEWEBSOCKETNOTIFICATIONPARSER_H
33 #define LEDGER_CORE_ETHEREUMLIKEWEBSOCKETNOTIFICATIONPARSER_H
34 
35 
36 #include <cstdio>
37 #include <cstdint>
38 #include <rapidjson/reader.h>
39 #include <stack>
40 #include <net/HttpClient.hpp>
41 #include <collections/collections.hpp>
42 #include "../EthereumLikeBlockchainExplorer.h"
43 #include "EthereumLikeBlockParser.hpp"
44 #include "EthereumLikeTransactionParser.hpp"
45 #include <wallet/common/explorers/api/AbstractWebSocketNotificationParser.h>
46 
47 namespace ledger {
48  namespace core {
49  class EthereumLikeWebSocketNotificationParser : public AbstractWebSocketNotificationParser<EthereumLikeBlockchainExplorerTransaction, EthereumLikeBlockchainExplorer::Block, EthereumLikeTransactionParser, EthereumLikeBlockParser> {
50  public:
51 
52 
53  explicit EthereumLikeWebSocketNotificationParser(std::string& lastKey) : _lastKey(lastKey),
54  _blockParser(lastKey),
55  _transactionParser(lastKey) {
56 
57  }
58 
59  bool Key(const rapidjson::Reader::Ch* str, rapidjson::SizeType length, bool copy) override {
60  _lastKey = std::string(str, length);
64  EthereumLikeBlockParser>::Key(str, length, copy);
65  }
66 
67  protected:
68 
69  EthereumLikeTransactionParser &getTransactionParser() override {
70  return _transactionParser;
71  };
72  EthereumLikeBlockParser &getBlockParser() override {
73  return _blockParser;
74  };
75  std::string &getLastKey() override {
76  return _lastKey;
77  };
78 
79  private:
80  std::string& _lastKey;
81  EthereumLikeBlockParser _blockParser;
82  EthereumLikeTransactionParser _transactionParser;
83  };
84  }
85 }
86 
87 
88 #endif //LEDGER_CORE_ETHEREUMLIKEWEBSOCKETNOTIFICATIONPARSER_H
Definition: EthereumLikeBlockchainExplorer.h:71
Definition: Account.cpp:8
Definition: AbstractWebSocketNotificationParser.h:46
Definition: EthereumLikeWebSocketNotificationParser.h:49
Definition: EthereumLikeBlockParser.hpp:37
Definition: EthereumLikeTransactionParser.hpp:45
Definition: Block.h:40