Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 6: [PATCH 06/17] feat(wallet): preserve Roots signing and spend controls on v31

src/interfaces/wallet.h

Before: src/interfaces/wallet.h · After: src/interfaces/wallet.h

File metadata
index bba9e058cc017ea72026751ddba7fca56e56bf0d..9a73dfae206fdc315e21e433d5f74dcad420e150 100644

Download original patch · Release notes

Diff rows 1–123 of 123. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

src/interfaces/wallet.h CHANGED
@@ -9,6 +9,7 @@
9
  #include <common/signmessage.h>
10
  #include <consensus/amount.h>
11
  #include <interfaces/chain.h>
 
12
  #include <primitives/transaction_identifier.h>
13
  #include <pubkey.h>
14
  #include <script/script.h>
@@ -17,6 +18,7 @@
17
  #include <util/result.h>
18
  #include <util/ui_change_type.h>
19
 
 
20
  #include <cstdint>
21
  #include <functional>
22
  #include <map>
@@ -27,7 +29,6 @@
27
  #include <utility>
28
  #include <vector>
29
 
30
- class CFeeRate;
31
  class CKey;
32
  enum class FeeReason;
33
  enum class OutputType;
@@ -58,6 +59,42 @@ struct WalletTxOut;
58
  struct WalletTxStatus;
59
  struct WalletMigrationResult;
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
62
  using WalletValueMap = std::map<std::string, std::string>;
63
 
@@ -107,6 +144,13 @@ public:
107
  //! Return whether wallet has private key.
108
  virtual bool isSpendable(const CTxDestination& dest) = 0;
109
 
 
 
 
 
 
 
 
110
  //! Add or update address.
111
  virtual bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::optional<wallet::AddressPurpose>& purpose) = 0;
112
 
@@ -239,7 +283,8 @@ public:
239
  virtual CoinsList listCoins() = 0;
240
 
241
  //! Return wallet transaction output information.
242
- virtual std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) = 0;
 
243
 
244
  //! Get required fee.
245
  virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0;
@@ -253,6 +298,9 @@ public:
253
  //! Get tx confirm target.
254
  virtual unsigned int getConfirmTarget() = 0;
255
 
 
 
 
256
  // Return whether HD enabled.
257
  virtual bool hdEnabled() = 0;
258
 
@@ -413,10 +461,29 @@ struct WalletTxStatus
413
  //! Wallet transaction output.
414
  struct WalletTxOut
415
  {
 
 
416
  CTxOut txout;
 
417
  int64_t time;
418
  int depth_in_main_chain = -1;
419
  bool is_spent = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  };
421
 
422
  //! Migrated wallet info
 
9
  #include <common/signmessage.h>
10
  #include <consensus/amount.h>
11
  #include <interfaces/chain.h>
12
+ #include <policy/feerate.h>
13
  #include <primitives/transaction_identifier.h>
14
  #include <pubkey.h>
15
  #include <script/script.h>
 
18
  #include <util/result.h>
19
  #include <util/ui_change_type.h>
20
 
21
+ #include <atomic>
22
  #include <cstdint>
23
  #include <functional>
24
  #include <map>
 
29
  #include <utility>
30
  #include <vector>
31
 
 
32
  class CKey;
33
  enum class FeeReason;
34
  enum class OutputType;
 
59
  struct WalletTxStatus;
60
  struct WalletMigrationResult;
61
 
62
+ //! Shared authorization for an asynchronous sweep. Cancellation and the final
63
+ //! transition into broadcast are mutually exclusive, so a successful cancel
64
+ //! guarantees that broadcast cannot start afterwards.
65
+ class SweepAuthorization
66
+ {
67
+ public:
68
+ bool Cancel()
69
+ {
70
+ State expected{State::ACTIVE};
71
+ if (m_state.compare_exchange_strong(expected, State::CANCELLED)) return true;
72
+ return expected == State::CANCELLED;
73
+ }
74
+ bool IsCancelled() const { return m_state.load() == State::CANCELLED; }
75
+ bool BeginBroadcast()
76
+ {
77
+ State expected{State::ACTIVE};
78
+ return m_state.compare_exchange_strong(expected, State::BROADCAST_STARTED);
79
+ }
80
+ bool BroadcastStarted() const { return m_state.load() == State::BROADCAST_STARTED; }
81
+
82
+ private:
83
+ enum class State : uint8_t { ACTIVE, CANCELLED, BROADCAST_STARTED };
84
+ std::atomic<State> m_state{State::ACTIVE};
85
+ };
86
+
87
+ //! Result of a transient-private-key sweep. The supplied key is never retained
88
+ //! by this interface or by the wallet.
89
+ struct WalletSweepResult {
90
+ CTransactionRef tx;
91
+ CAmount amount{0};
92
+ CAmount fee{0};
93
+ size_t inputs{0};
94
+ int64_t vsize{0};
95
+ bool broadcast{false};
96
+ };
97
+
98
  using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
99
  using WalletValueMap = std::map<std::string, std::string>;
100
 
 
144
  //! Return whether wallet has private key.
145
  virtual bool isSpendable(const CTxDestination& dest) = 0;
146
 
147
+ //! Sweep one transient private key to a destination controlled by this wallet.
148
+ virtual util::Result<WalletSweepResult> sweepPrivateKey(const SecureString& private_key,
149
+ const CTxDestination& destination,
150
+ bool broadcast,
151
+ const std::optional<Txid>& expected_txid,
152
+ const std::shared_ptr<SweepAuthorization>& authorization) = 0;
153
+
154
  //! Add or update address.
155
  virtual bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::optional<wallet::AddressPurpose>& purpose) = 0;
156
 
 
283
  virtual CoinsList listCoins() = 0;
284
 
285
  //! Return wallet transaction output information.
286
+ virtual std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs,
287
+ const std::optional<CFeeRate>& feerate = std::nullopt) = 0;
288
 
289
  //! Get required fee.
290
  virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0;
 
298
  //! Get tx confirm target.
299
  virtual unsigned int getConfirmTarget() = 0;
300
 
301
+ //! Return whether new transactions signal replace-by-fee by default.
302
+ virtual bool getDefaultRbf() = 0;
303
+
304
  // Return whether HD enabled.
305
  virtual bool hdEnabled() = 0;
306
 
 
461
  //! Wallet transaction output.
462
  struct WalletTxOut
463
  {
464
+ //! Outpoint identifying this output in the wallet.
465
+ COutPoint outpoint;
466
  CTxOut txout;
467
+ //! Wallet's smart transaction time for this output.
468
  int64_t time;
469
  int depth_in_main_chain = -1;
470
  bool is_spent = false;
471
+ //! Wallet-owned facts used to present coin-control choices.
472
+ int input_bytes = -1;
473
+ std::optional<CAmount> effective_value;
474
+ CAmount ancestor_bump_fees{0};
475
+ //! Native wallet ownership/selection status; does not guarantee complete signing.
476
+ bool is_spendable = false;
477
+ bool is_watch_only = false;
478
+ bool is_solvable = false;
479
+ bool is_safe = false;
480
+ bool is_locked = false;
481
+ bool is_reused = false;
482
+ bool is_immature = false;
483
+ bool is_change = false;
484
+ CTxDestination address;
485
+ CTxDestination grouping_address;
486
+ std::string label;
487
  };
488
 
489
  //! Migrated wallet info