util.h raw

   1  // Copyright (c) 2017-present The Limenka developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef LIMENKA_WALLET_RPC_UTIL_H
   6  #define LIMENKA_WALLET_RPC_UTIL_H
   7  
   8  #include <rpc/util.h>
   9  #include <script/script.h>
  10  #include <wallet/wallet.h>
  11  
  12  #include <any>
  13  #include <memory>
  14  #include <string>
  15  #include <vector>
  16  
  17  class JSONRPCRequest;
  18  class UniValue;
  19  struct bilingual_str;
  20  
  21  namespace wallet {
  22  class LegacyScriptPubKeyMan;
  23  enum class DatabaseStatus;
  24  struct WalletContext;
  25  
  26  extern const std::string HELP_REQUIRING_PASSPHRASE;
  27  
  28  static const RPCResult RESULT_LAST_PROCESSED_BLOCK { RPCResult::Type::OBJ, "lastprocessedblock", "hash and height of the block this information was generated on",{
  29      {RPCResult::Type::STR_HEX, "hash", "hash of the block this information was generated on"},
  30      {RPCResult::Type::NUM, "height", "height of the block this information was generated on"}}
  31  };
  32  
  33  /**
  34   * Figures out what wallet, if any, to use for a JSONRPCRequest.
  35   *
  36   * @param[in] request JSONRPCRequest that wishes to access a wallet
  37   * @return nullptr if no wallet should be used, or a pointer to the CWallet
  38   */
  39  std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request);
  40  bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name);
  41  /**
  42   * Ensures that a wallet name is specified across the endpoint and wallet_name.
  43   * Throws `RPC_INVALID_PARAMETER` if none or different wallet names are specified.
  44   */
  45  std::string EnsureUniqueWalletName(const JSONRPCRequest& request, const std::string* wallet_name);
  46  
  47  void EnsureWalletIsUnlocked(const CWallet&);
  48  WalletContext& EnsureWalletContext(const std::any& context);
  49  LegacyScriptPubKeyMan& EnsureLegacyScriptPubKeyMan(CWallet& wallet, bool also_create = false);
  50  const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wallet);
  51  
  52  bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param);
  53  bool ParseIncludeWatchonly(const UniValue& include_watchonly, const CWallet& wallet);
  54  std::string LabelFromValue(const UniValue& value);
  55  //! Fetch parent descriptors of this scriptPubKey.
  56  void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry);
  57  
  58  void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error);
  59  void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
  60  } //  namespace wallet
  61  
  62  #endif // LIMENKA_WALLET_RPC_UTIL_H
  63