ledger-core
BitcoinLikeWritableInputApi.h
1 /*
2  *
3  * BitcoinLikeWritableInputApi.h
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 10/04/2018.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2017 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 
32 #ifndef LEDGER_CORE_BITCOINLIKEWRITABLEINPUTAPI_H
33 #define LEDGER_CORE_BITCOINLIKEWRITABLEINPUTAPI_H
34 
35 #include <api/BitcoinLikeInput.hpp>
36 #include <wallet/bitcoin/BitcoinLikeAccount.hpp>
37 #include <wallet/common/api_impl/DerivationPathApi.h>
38 #include <wallet/bitcoin/scripts/BitcoinLikeScript.h>
39 
40 
41 namespace ledger {
42  namespace core {
44  public:
46  const std::shared_ptr<ledger::core::BitcoinLikeBlockchainExplorer>& explorer,
47  const std::shared_ptr<api::ExecutionContext>& context,
48  uint32_t sequence,
49  const std::vector<std::vector<uint8_t> >& pubKeys,
50  const std::vector<std::shared_ptr<api::DerivationPath>>& paths,
51  const std::string& address,
52  const std::shared_ptr<api::Amount>& amount,
53  const std::string& previousTxHash,
54  int32_t index,
55  const std::vector<uint8_t>& scriptSig,
56  const std::shared_ptr<api::BitcoinLikeOutput>& previousOutput,
57  const std::string &keychainEngine = ""
58  );
60  std::vector<std::vector<uint8_t>> getPublicKeys() override;
61  std::shared_ptr<api::Amount> getValue() override;
62 
63  std::vector<std::shared_ptr<api::DerivationPath> > getDerivationPath() override;
64 
65  bool isCoinbase() override;
69  std::shared_ptr<api::BitcoinLikeOutput> getPreviousOuput() override;
70  std::vector<uint8_t> getScriptSig() override;
71  std::shared_ptr<api::BitcoinLikeScript> parseScriptSig() override;
72  void setScriptSig(const std::vector<uint8_t> &scriptSig) override;
73  void pushToScriptSig(const std::vector<uint8_t> &data) override;
74  void setSequence(int32_t sequence) override;
75  int64_t getSequence() override;
76  void getPreviousTransaction(const std::shared_ptr<api::BinaryCallback> &callback) override;
77  Future<std::vector<uint8_t>> getPreviousTransaction();
78  void setP2PKHSigScript(const std::vector<uint8_t> &signature) override;
79 
80 
81 
82  private:
83  std::shared_ptr<ledger::core::BitcoinLikeBlockchainExplorer> _explorer;
84  std::shared_ptr<ledger::core::api::ExecutionContext> _context;
85  uint32_t _sequence;
86  std::vector<std::vector<uint8_t> > _pubKeys;
87  std::vector<std::shared_ptr<api::DerivationPath>> _paths;
88  std::string _address;
89  std::shared_ptr<api::Amount> _amount;
90  std::string _previousHash;
91  int32_t _index;
92  BitcoinLikeScript _scriptSig;
93  std::shared_ptr<api::BitcoinLikeOutput> _previousScript;
94  };
95  }
96 }
97 
98 
99 #endif //LEDGER_CORE_BITCOINLIKEWRITABLEINPUTAPI_H
std::vector< std::shared_ptr< api::DerivationPath > > getDerivationPath() override
Definition: BitcoinLikeWritableInputApi.cpp:72
void setScriptSig(const std::vector< uint8_t > &scriptSig) override
Definition: BitcoinLikeWritableInputApi.cpp:108
bool isCoinbase() override
Definition: BitcoinLikeWritableInputApi.cpp:80
Definition: Deffered.hpp:49
optional< int32_t > getPreviousOutputIndex() override
Definition: BitcoinLikeWritableInputApi.cpp:92
std::vector< std::vector< uint8_t > > getPublicKeys() override
Definition: BitcoinLikeWritableInputApi.cpp:68
optional< std::string > getAddress() override
Definition: BitcoinLikeWritableInputApi.cpp:64
optional< std::string > getPreviousTxHash() override
Definition: BitcoinLikeWritableInputApi.cpp:88
std::shared_ptr< api::BitcoinLikeOutput > getPreviousOuput() override
Definition: BitcoinLikeWritableInputApi.cpp:96
void setSequence(int32_t sequence) override
Definition: BitcoinLikeWritableInputApi.cpp:116
std::shared_ptr< api::BitcoinLikeScript > parseScriptSig() override
Definition: BitcoinLikeWritableInputApi.cpp:104
Definition: BitcoinLikeInput.hpp:29
optional< std::string > getCoinbase() override
Definition: BitcoinLikeWritableInputApi.cpp:84
Definition: BitcoinLikeScript.h:94
Definition: Account.cpp:8
void setP2PKHSigScript(const std::vector< uint8_t > &signature) override
Definition: BitcoinLikeWritableInputApi.cpp:124
Definition: BitcoinLikeWritableInputApi.h:43
std::vector< uint8_t > getScriptSig() override
Definition: BitcoinLikeWritableInputApi.cpp:100
int64_t getSequence() override
Definition: BitcoinLikeWritableInputApi.cpp:120
void pushToScriptSig(const std::vector< uint8_t > &data) override
Definition: BitcoinLikeWritableInputApi.cpp:112
Definition: optional.hpp:177
std::shared_ptr< api::Amount > getValue() override
Definition: BitcoinLikeWritableInputApi.cpp:76