ledger-core
RippleLikeTransactionBuilder.h
1 /*
2  *
3  * RippleLikeTransactionBuilder
4  *
5  * Created by El Khalil Bellakrid on 06/01/2019.
6  *
7  * The MIT License (MIT)
8  *
9  * Copyright (c) 2019 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_RIPPLELIKETRANSACTIONBUILDER_H
33 #define LEDGER_CORE_RIPPLELIKETRANSACTIONBUILDER_H
34 
35 #include <api/RippleLikeTransactionBuilder.hpp>
36 #include <api/Currency.hpp>
37 #include <api/ExecutionContext.hpp>
38 #include <api/Amount.hpp>
39 
40 #include <wallet/common/Amount.h>
41 #include <wallet/ripple/explorers/RippleLikeBlockchainExplorer.h>
42 
43 #include <math/BigInt.h>
44 
45 #include <async/Future.hpp>
46 #include <spdlog/logger.h>
47 
48 namespace ledger {
49  namespace core {
50 
53  wipe = false;
54  };
55  std::string toAddress;
56  std::shared_ptr<BigInt> value;
57  std::shared_ptr<BigInt> fees;
58  BigInt sequence;
59  bool wipe;
60  std::vector<api::RippleLikeMemo> memos;
61  Option<int64_t> destinationTag;
62  };
63 
64  using RippleLikeTransactionBuildFunction = std::function<Future<std::shared_ptr<api::RippleLikeTransaction>>(
65  const RippleLikeTransactionBuildRequest &, const std::shared_ptr<RippleLikeBlockchainExplorer> &)>;
66 
69  public std::enable_shared_from_this<RippleLikeTransactionBuilder> {
70  public:
71 
72  explicit RippleLikeTransactionBuilder(const std::shared_ptr<api::ExecutionContext> &context,
73  const api::Currency &params,
74  const std::shared_ptr<RippleLikeBlockchainExplorer> &explorer,
75  const std::shared_ptr<spdlog::logger> &logger,
76  const RippleLikeTransactionBuildFunction &buildFunction);
77 
79 
80  std::shared_ptr<api::RippleLikeTransactionBuilder> sendToAddress(const std::shared_ptr<api::Amount> &amount,
81  const std::string &address) override;
82 
83  std::shared_ptr<api::RippleLikeTransactionBuilder> wipeToAddress(const std::string &address) override;
84 
85  std::shared_ptr<api::RippleLikeTransactionBuilder> setFees(const std::shared_ptr<api::Amount> & fees) override;
86 
87  std::shared_ptr<api::RippleLikeTransactionBuilder> addMemo(const api::RippleLikeMemo& memo) override;
88 
89  std::shared_ptr<api::RippleLikeTransactionBuilder> setDestinationTag(int64_t tag) override;
90 
91  void build(const std::shared_ptr<api::RippleLikeTransactionCallback> &callback) override;
92 
94 
95  std::shared_ptr<api::RippleLikeTransactionBuilder> clone() override;
96 
97  void reset() override;
98 
99  static std::shared_ptr<api::RippleLikeTransaction> parseRawTransaction(const api::Currency &currency,
100  const std::vector<uint8_t> &rawTransaction,
101  bool isSigned);
102 
103  private:
104  api::Currency _currency;
105  std::shared_ptr<RippleLikeBlockchainExplorer> _explorer;
106  RippleLikeTransactionBuildFunction _build;
107  RippleLikeTransactionBuildRequest _request;
108  std::shared_ptr<api::ExecutionContext> _context;
109  std::shared_ptr<spdlog::logger> _logger;
110 
111  };
112  }
113 }
114 
115 #endif //LEDGER_CORE_RIPPLELIKETRANSACTIONBUILDER_H
Definition: RippleLikeTransactionBuilder.h:51
Definition: RippleLikeTransactionBuilder.hpp:27
Definition: Deffered.hpp:49
Definition: RippleLikeTransactionBuilder.h:67
Definition: Currency.hpp:23
Definition: Account.cpp:8
Definition: RippleLikeMemo.hpp:18
Definition: BigInt.h:56
Definition: logger.hpp:44