iota.lib.cpp
IOTA C++ Library
extended.hpp
1 //
2 // MIT License
3 //
4 // Copyright (c) 2017-2018 Thibault Martinez and Simon Ninon
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //
24 //
25 
26 #pragma once
27 
28 #include <iota/api/core.hpp>
29 #include <iota/models/fwd.hpp>
30 #include <iota/utils/stop_watch.hpp>
31 
32 namespace IOTA {
33 
34 namespace API {
35 
41 class Extended : public Core {
42 public:
51  Extended(const std::string& host, const uint16_t& port, bool localPow = true, int timeout = 60);
55  virtual ~Extended() = default;
56 
57 public:
70  Responses::GetBalancesAndFormat getInputs(const Models::Seed& seed, const int32_t& start = 0,
71  const int32_t& end = 0,
72  const int64_t& threshold = 0) const;
73 
85  const std::vector<Models::Address>& addresses, const int64_t& threshold = 0) const;
86 
101  Responses::GetNewAddresses getNewAddresses(const Models::Seed& seed, const uint32_t& index = 0,
102  const int32_t& total = 0,
103  bool returnAll = false) const;
104 
114  Models::Bundle traverseBundle(const Types::Trytes& trunkTx) const;
115 
125  std::vector<Models::Bundle> traverseBundles(const std::vector<Types::Trytes>& trunkTrxs,
126  bool throwOnFail = true) const;
127 
135  static void verifyBundle(const Models::Bundle& bundle);
136 
145  std::vector<Models::Bundle> bundlesFromAddresses(const std::vector<Models::Address>& addresses,
146  bool withInclusionStates = false) const;
147 
155  std::vector<Models::Transaction> findTransactionObjects(
156  const std::vector<Models::Address>& addresses) const;
157 
166  std::vector<Models::Transaction> getTransactionsObjects(
167  const std::vector<IOTA::Types::Trytes>& trx_hashes) const;
168 
176  std::vector<Models::Transaction> findTransactionObjectsByBundle(
177  const std::vector<IOTA::Types::Trytes>& input) const;
178 
186  Responses::GetInclusionStates getLatestInclusion(const std::vector<Types::Trytes>& hashes) const;
187 
202  std::vector<Types::Trytes> prepareTransfers(const Models::Seed& seed,
203  const std::vector<Models::Transfer>& transfers,
204  const Models::Address& remainder = {},
205  const std::vector<Models::Address>& inputs = {},
206  bool validateInputs = true) const;
207 
218  Responses::GetBundle getBundle(const Types::Trytes& transaction) const;
219 
232  Responses::GetTransfers getTransfers(const Models::Seed& seed, int start = 0, int end = 0,
233  bool inclusionStates = false) const;
234 
252  Responses::SendTransfer sendTransfer(const Models::Seed& seed, int depth, int minWeightMagnitude,
253  std::vector<Models::Transfer>& transfers,
254  const std::vector<Models::Address>& inputs = {},
255  const Models::Address& remainder = {},
256  const Types::Trytes& reference = "") const;
257 
269  std::vector<Models::Transaction> sendTrytes(const std::vector<Types::Trytes>& trytes,
270  const unsigned int& depth,
271  const unsigned int& minWeightMagnitude,
272  const Types::Trytes& reference = "") const;
273 
281  Responses::Base broadcastAndStore(const std::vector<Types::Trytes>& trytes) const;
282 
291  const std::vector<Models::Address>& addresses) const;
292 
300  Responses::FindTransactions findTransactionsByTags(const std::vector<Models::Tag>& tags) const;
301 
310  const std::vector<Types::Trytes>& approvees) const;
311 
320  const std::vector<Types::Trytes>& bundles) const;
321 
334  Responses::GetAccountData getAccountData(const Models::Seed& seed, int start = 0, int end = 0,
335  bool inclusionStates = true, long threshold = 0) const;
336 
350  std::vector<Types::Trytes> addRemainder(
351  const Models::Seed& seed, const std::vector<Models::Address>& inputs, Models::Bundle& bundle,
352  const Models::Tag& tag, int64_t totalValue, const Models::Address& remainderAddress,
353  const std::vector<Types::Trytes>& signatureFragments = {}) const;
354 
364  Responses::ReplayBundle replayBundle(const Types::Trytes& transaction, int depth,
365  int minWeightMagnitude) const;
366 
378  std::vector<Models::Transaction> initiateTransfer(
379  const Models::Address& inputAddress, const Models::Address& remainderAddress,
380  const std::vector<Models::Transfer>& transfers) const;
381 
389  bool isPromotable(const Types::Trytes& tail) const;
390 
405  Responses::SendTransfer promoteTransaction(const Types::Trytes& tail, int depth,
406  int minWeightMagnitude,
407  std::vector<Models::Transfer>& transfers, int delay,
408  const std::function<bool()>& interrupt) const;
409 
417  std::vector<bool> isReattachable(const std::vector<Models::Address>& addresses);
418 
419 private:
420  void traverseBundles(const std::vector<Types::Trytes>& trxs,
421  const std::vector<std::reference_wrapper<Models::Bundle>>& bundles,
422  bool throwOnFail) const;
423 
427  static bool isTransfersCollectionValid(const std::vector<Models::Transfer>& transfers);
428 };
429 
430 } // namespace API
431 
432 } // namespace IOTA
std::vector< Models::Transaction > getTransactionsObjects(const std::vector< IOTA::Types::Trytes > &trx_hashes) const
Definition: get_bundle.hpp:44
Definition: extended.hpp:41
Definition: send_transfer.hpp:42
Definition: get_account_data.hpp:45
Responses::GetBalancesAndFormat getBalancesAndFormat(const std::vector< Models::Address > &addresses, const int64_t &threshold=0) const
Definition: tag.hpp:40
Definition: get_new_addresses.hpp:44
Responses::GetBalancesAndFormat getInputs(const Models::Seed &seed, const int32_t &start=0, const int32_t &end=0, const int64_t &threshold=0) const
std::vector< Models::Transaction > sendTrytes(const std::vector< Types::Trytes > &trytes, const unsigned int &depth, const unsigned int &minWeightMagnitude, const Types::Trytes &reference="") const
Definition: address.hpp:43
Responses::ReplayBundle replayBundle(const Types::Trytes &transaction, int depth, int minWeightMagnitude) const
Responses::SendTransfer sendTransfer(const Models::Seed &seed, int depth, int minWeightMagnitude, std::vector< Models::Transfer > &transfers, const std::vector< Models::Address > &inputs={}, const Models::Address &remainder={}, const Types::Trytes &reference="") const
Definition: find_transactions.hpp:47
Models::Bundle traverseBundle(const Types::Trytes &trunkTx) const
Definition: get_balances_and_format.hpp:47
Responses::FindTransactions findTransactionsByApprovees(const std::vector< Types::Trytes > &approvees) const
Definition: replay_bundle.hpp:41
bool isPromotable(const Types::Trytes &tail) const
std::vector< Models::Transaction > findTransactionObjectsByBundle(const std::vector< IOTA::Types::Trytes > &input) const
Responses::GetBundle getBundle(const Types::Trytes &transaction) const
Responses::Base broadcastAndStore(const std::vector< Types::Trytes > &trytes) const
std::vector< Types::Trytes > prepareTransfers(const Models::Seed &seed, const std::vector< Models::Transfer > &transfers, const Models::Address &remainder={}, const std::vector< Models::Address > &inputs={}, bool validateInputs=true) const
virtual ~Extended()=default
std::vector< Models::Bundle > traverseBundles(const std::vector< Types::Trytes > &trunkTrxs, bool throwOnFail=true) const
Definition: get_transfers.hpp:43
Extended(const std::string &host, const uint16_t &port, bool localPow=true, int timeout=60)
Definition: core.hpp:43
Definition: bundle.hpp:42
Definition: base.hpp:43
std::vector< Models::Transaction > findTransactionObjects(const std::vector< Models::Address > &addresses) const
Responses::FindTransactions findTransactionsByTags(const std::vector< Models::Tag > &tags) const
std::vector< Types::Trytes > addRemainder(const Models::Seed &seed, const std::vector< Models::Address > &inputs, Models::Bundle &bundle, const Models::Tag &tag, int64_t totalValue, const Models::Address &remainderAddress, const std::vector< Types::Trytes > &signatureFragments={}) const
Responses::FindTransactions findTransactionsByAddresses(const std::vector< Models::Address > &addresses) const
Responses::GetAccountData getAccountData(const Models::Seed &seed, int start=0, int end=0, bool inclusionStates=true, long threshold=0) const
static void verifyBundle(const Models::Bundle &bundle)
Responses::SendTransfer promoteTransaction(const Types::Trytes &tail, int depth, int minWeightMagnitude, std::vector< Models::Transfer > &transfers, int delay, const std::function< bool()> &interrupt) const
std::vector< bool > isReattachable(const std::vector< Models::Address > &addresses)
Responses::GetTransfers getTransfers(const Models::Seed &seed, int start=0, int end=0, bool inclusionStates=false) const
Responses::GetInclusionStates getLatestInclusion(const std::vector< Types::Trytes > &hashes) const
std::vector< Models::Bundle > bundlesFromAddresses(const std::vector< Models::Address > &addresses, bool withInclusionStates=false) const
std::vector< Models::Transaction > initiateTransfer(const Models::Address &inputAddress, const Models::Address &remainderAddress, const std::vector< Models::Transfer > &transfers) const
Definition: seed.hpp:40
Definition: get_inclusion_states.hpp:48
Definition: core.hpp:33
Responses::GetNewAddresses getNewAddresses(const Models::Seed &seed, const uint32_t &index=0, const int32_t &total=0, bool returnAll=false) const
Responses::FindTransactions findTransactionsByBundles(const std::vector< Types::Trytes > &bundles) const