mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
wallet: refactor GetNewDestination, use BResult
This commit is contained in:
parent
22351725bc
commit
111ea3ab71
13 changed files with 72 additions and 86 deletions
|
@ -47,12 +47,11 @@ static void BenchUnloadWallet(std::shared_ptr<CWallet>&& wallet)
|
||||||
|
|
||||||
static void AddTx(CWallet& wallet)
|
static void AddTx(CWallet& wallet)
|
||||||
{
|
{
|
||||||
bilingual_str error;
|
const auto& dest = wallet.GetNewDestination(OutputType::BECH32, "");
|
||||||
CTxDestination dest;
|
assert(dest.HasRes());
|
||||||
wallet.GetNewDestination(OutputType::BECH32, "", dest, error);
|
|
||||||
|
|
||||||
CMutableTransaction mtx;
|
CMutableTransaction mtx;
|
||||||
mtx.vout.push_back({COIN, GetScriptForDestination(dest)});
|
mtx.vout.push_back({COIN, GetScriptForDestination(dest.GetObj())});
|
||||||
mtx.vin.push_back(CTxIn());
|
mtx.vin.push_back(CTxIn());
|
||||||
|
|
||||||
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
|
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
|
||||||
|
|
|
@ -88,7 +88,7 @@ public:
|
||||||
virtual std::string getWalletName() = 0;
|
virtual std::string getWalletName() = 0;
|
||||||
|
|
||||||
// Get a new address.
|
// Get a new address.
|
||||||
virtual bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) = 0;
|
virtual BResult<CTxDestination> getNewDestination(const OutputType type, const std::string label) = 0;
|
||||||
|
|
||||||
//! Get public key.
|
//! Get public key.
|
||||||
virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0;
|
virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0;
|
||||||
|
|
|
@ -370,23 +370,21 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
|
||||||
else if(type == Receive)
|
else if(type == Receive)
|
||||||
{
|
{
|
||||||
// Generate a new address to associate with given label
|
// Generate a new address to associate with given label
|
||||||
CTxDestination dest;
|
auto op_dest = walletModel->wallet().getNewDestination(address_type, strLabel);
|
||||||
if(!walletModel->wallet().getNewDestination(address_type, strLabel, dest))
|
if (!op_dest) {
|
||||||
{
|
|
||||||
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
|
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
|
||||||
if(!ctx.isValid())
|
if (!ctx.isValid()) {
|
||||||
{
|
|
||||||
// Unlock wallet failed or was cancelled
|
// Unlock wallet failed or was cancelled
|
||||||
editStatus = WALLET_UNLOCK_FAILURE;
|
editStatus = WALLET_UNLOCK_FAILURE;
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if(!walletModel->wallet().getNewDestination(address_type, strLabel, dest))
|
op_dest = walletModel->wallet().getNewDestination(address_type, strLabel);
|
||||||
{
|
if (!op_dest) {
|
||||||
editStatus = KEY_GENERATION_FAILURE;
|
editStatus = KEY_GENERATION_FAILURE;
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strAddress = EncodeDestination(dest);
|
strAddress = EncodeDestination(op_dest.GetObj());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,11 +20,10 @@ const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqq
|
||||||
std::string getnewaddress(CWallet& w)
|
std::string getnewaddress(CWallet& w)
|
||||||
{
|
{
|
||||||
constexpr auto output_type = OutputType::BECH32;
|
constexpr auto output_type = OutputType::BECH32;
|
||||||
CTxDestination dest;
|
auto op_dest = w.GetNewDestination(output_type, "");
|
||||||
bilingual_str error;
|
assert(op_dest.HasRes());
|
||||||
if (!w.GetNewDestination(output_type, "", dest, error)) assert(false);
|
|
||||||
|
|
||||||
return EncodeDestination(dest);
|
return EncodeDestination(op_dest.GetObj());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_WALLET
|
#endif // ENABLE_WALLET
|
||||||
|
|
|
@ -146,11 +146,10 @@ public:
|
||||||
void abortRescan() override { m_wallet->AbortRescan(); }
|
void abortRescan() override { m_wallet->AbortRescan(); }
|
||||||
bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
|
bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
|
||||||
std::string getWalletName() override { return m_wallet->GetName(); }
|
std::string getWalletName() override { return m_wallet->GetName(); }
|
||||||
bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override
|
BResult<CTxDestination> getNewDestination(const OutputType type, const std::string label) override
|
||||||
{
|
{
|
||||||
LOCK(m_wallet->cs_wallet);
|
LOCK(m_wallet->cs_wallet);
|
||||||
bilingual_str error;
|
return m_wallet->GetNewDestination(type, label);
|
||||||
return m_wallet->GetNewDestination(type, label, dest, error);
|
|
||||||
}
|
}
|
||||||
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
|
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,13 +58,12 @@ RPCHelpMan getnewaddress()
|
||||||
output_type = parsed.value();
|
output_type = parsed.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxDestination dest;
|
auto op_dest = pwallet->GetNewDestination(output_type, label);
|
||||||
bilingual_str error;
|
if (!op_dest) {
|
||||||
if (!pwallet->GetNewDestination(output_type, label, dest, error)) {
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, op_dest.GetError().original);
|
||||||
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error.original);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EncodeDestination(dest);
|
return EncodeDestination(op_dest.GetObj());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -106,12 +105,11 @@ RPCHelpMan getrawchangeaddress()
|
||||||
output_type = parsed.value();
|
output_type = parsed.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxDestination dest;
|
auto op_dest = pwallet->GetNewChangeDestination(output_type);
|
||||||
bilingual_str error;
|
if (!op_dest) {
|
||||||
if (!pwallet->GetNewChangeDestination(output_type, dest, error)) {
|
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, op_dest.GetError().original);
|
||||||
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error.original);
|
|
||||||
}
|
}
|
||||||
return EncodeDestination(dest);
|
return EncodeDestination(op_dest.GetObj());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,26 +21,22 @@ namespace wallet {
|
||||||
//! Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value. See BIP 32 for more details.
|
//! Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value. See BIP 32 for more details.
|
||||||
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
|
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error)
|
BResult<CTxDestination> LegacyScriptPubKeyMan::GetNewDestination(const OutputType type)
|
||||||
{
|
{
|
||||||
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
|
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
|
||||||
error = _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types");
|
return _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types");;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
assert(type != OutputType::BECH32M);
|
assert(type != OutputType::BECH32M);
|
||||||
|
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
error.clear();
|
|
||||||
|
|
||||||
// Generate a new key that is added to wallet
|
// Generate a new key that is added to wallet
|
||||||
CPubKey new_key;
|
CPubKey new_key;
|
||||||
if (!GetKeyFromPool(new_key, type)) {
|
if (!GetKeyFromPool(new_key, type)) {
|
||||||
error = _("Error: Keypool ran out, please call keypoolrefill first");
|
return _("Error: Keypool ran out, please call keypoolrefill first");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
LearnRelatedScripts(new_key, type);
|
LearnRelatedScripts(new_key, type);
|
||||||
dest = GetDestinationForKey(new_key, type);
|
return GetDestinationForKey(new_key, type);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::vector<unsigned char> valtype;
|
typedef std::vector<unsigned char> valtype;
|
||||||
|
@ -1658,12 +1654,11 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
|
||||||
return set_address;
|
return set_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error)
|
BResult<CTxDestination> DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type)
|
||||||
{
|
{
|
||||||
// Returns true if this descriptor supports getting new addresses. Conditions where we may be unable to fetch them (e.g. locked) are caught later
|
// Returns true if this descriptor supports getting new addresses. Conditions where we may be unable to fetch them (e.g. locked) are caught later
|
||||||
if (!CanGetAddresses()) {
|
if (!CanGetAddresses()) {
|
||||||
error = _("No addresses available");
|
return _("No addresses available");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
LOCK(cs_desc_man);
|
LOCK(cs_desc_man);
|
||||||
|
@ -1681,15 +1676,14 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
|
||||||
std::vector<CScript> scripts_temp;
|
std::vector<CScript> scripts_temp;
|
||||||
if (m_wallet_descriptor.range_end <= m_max_cached_index && !TopUp(1)) {
|
if (m_wallet_descriptor.range_end <= m_max_cached_index && !TopUp(1)) {
|
||||||
// We can't generate anymore keys
|
// We can't generate anymore keys
|
||||||
error = _("Error: Keypool ran out, please call keypoolrefill first");
|
return _("Error: Keypool ran out, please call keypoolrefill first");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (!m_wallet_descriptor.descriptor->ExpandFromCache(m_wallet_descriptor.next_index, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
|
if (!m_wallet_descriptor.descriptor->ExpandFromCache(m_wallet_descriptor.next_index, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
|
||||||
// We can't generate anymore keys
|
// We can't generate anymore keys
|
||||||
error = _("Error: Keypool ran out, please call keypoolrefill first");
|
return _("Error: Keypool ran out, please call keypoolrefill first");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTxDestination dest;
|
||||||
std::optional<OutputType> out_script_type = m_wallet_descriptor.descriptor->GetOutputType();
|
std::optional<OutputType> out_script_type = m_wallet_descriptor.descriptor->GetOutputType();
|
||||||
if (out_script_type && out_script_type == type) {
|
if (out_script_type && out_script_type == type) {
|
||||||
ExtractDestination(scripts_temp[0], dest);
|
ExtractDestination(scripts_temp[0], dest);
|
||||||
|
@ -1698,7 +1692,7 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
|
||||||
}
|
}
|
||||||
m_wallet_descriptor.next_index++;
|
m_wallet_descriptor.next_index++;
|
||||||
WalletBatch(m_storage.GetDatabase()).WriteDescriptor(GetID(), m_wallet_descriptor);
|
WalletBatch(m_storage.GetDatabase()).WriteDescriptor(GetID(), m_wallet_descriptor);
|
||||||
return true;
|
return dest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1769,9 +1763,14 @@ bool DescriptorScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, Walle
|
||||||
bool DescriptorScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error)
|
bool DescriptorScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error)
|
||||||
{
|
{
|
||||||
LOCK(cs_desc_man);
|
LOCK(cs_desc_man);
|
||||||
bool result = GetNewDestination(type, address, error);
|
auto op_dest = GetNewDestination(type);
|
||||||
index = m_wallet_descriptor.next_index - 1;
|
index = m_wallet_descriptor.next_index - 1;
|
||||||
return result;
|
if (op_dest) {
|
||||||
|
address = op_dest.GetObj();
|
||||||
|
} else {
|
||||||
|
error = op_dest.GetError();
|
||||||
|
}
|
||||||
|
return op_dest.HasRes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, const CTxDestination& addr)
|
void DescriptorScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, const CTxDestination& addr)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <script/standard.h>
|
#include <script/standard.h>
|
||||||
#include <util/error.h>
|
#include <util/error.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
|
#include <util/result.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <wallet/crypter.h>
|
#include <wallet/crypter.h>
|
||||||
#include <wallet/ismine.h>
|
#include <wallet/ismine.h>
|
||||||
|
@ -171,7 +172,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
explicit ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {}
|
explicit ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {}
|
||||||
virtual ~ScriptPubKeyMan() {};
|
virtual ~ScriptPubKeyMan() {};
|
||||||
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error) { return false; }
|
virtual BResult<CTxDestination> GetNewDestination(const OutputType type) { return Untranslated("Not supported"); }
|
||||||
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
|
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
|
||||||
|
|
||||||
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
|
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
|
||||||
|
@ -359,7 +360,7 @@ private:
|
||||||
public:
|
public:
|
||||||
using ScriptPubKeyMan::ScriptPubKeyMan;
|
using ScriptPubKeyMan::ScriptPubKeyMan;
|
||||||
|
|
||||||
bool GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error) override;
|
BResult<CTxDestination> GetNewDestination(const OutputType type) override;
|
||||||
isminetype IsMine(const CScript& script) const override;
|
isminetype IsMine(const CScript& script) const override;
|
||||||
|
|
||||||
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
|
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
|
||||||
|
@ -567,7 +568,7 @@ public:
|
||||||
|
|
||||||
mutable RecursiveMutex cs_desc_man;
|
mutable RecursiveMutex cs_desc_man;
|
||||||
|
|
||||||
bool GetNewDestination(const OutputType type, CTxDestination& dest, bilingual_str& error) override;
|
BResult<CTxDestination> GetNewDestination(const OutputType type) override;
|
||||||
isminetype IsMine(const CScript& script) const override;
|
isminetype IsMine(const CScript& script) const override;
|
||||||
|
|
||||||
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
|
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
|
||||||
|
|
|
@ -74,11 +74,9 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
|
||||||
tx.vout.resize(nInput + 1);
|
tx.vout.resize(nInput + 1);
|
||||||
tx.vout[nInput].nValue = nValue;
|
tx.vout[nInput].nValue = nValue;
|
||||||
if (spendable) {
|
if (spendable) {
|
||||||
CTxDestination dest;
|
auto op_dest = wallet.GetNewDestination(OutputType::BECH32, "");
|
||||||
bilingual_str error;
|
assert(op_dest.HasRes());
|
||||||
const bool destination_ok = wallet.GetNewDestination(OutputType::BECH32, "", dest, error);
|
tx.vout[nInput].scriptPubKey = GetScriptForDestination(op_dest.GetObj());
|
||||||
assert(destination_ok);
|
|
||||||
tx.vout[nInput].scriptPubKey = GetScriptForDestination(dest);
|
|
||||||
}
|
}
|
||||||
uint256 txid = tx.GetHash();
|
uint256 txid = tx.GetHash();
|
||||||
|
|
||||||
|
|
|
@ -69,15 +69,14 @@ struct FuzzedWallet {
|
||||||
CScript GetScriptPubKey(FuzzedDataProvider& fuzzed_data_provider)
|
CScript GetScriptPubKey(FuzzedDataProvider& fuzzed_data_provider)
|
||||||
{
|
{
|
||||||
auto type{fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES)};
|
auto type{fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES)};
|
||||||
CTxDestination dest;
|
BResult<CTxDestination> op_dest;
|
||||||
bilingual_str error;
|
|
||||||
if (fuzzed_data_provider.ConsumeBool()) {
|
if (fuzzed_data_provider.ConsumeBool()) {
|
||||||
assert(wallet->GetNewDestination(type, "", dest, error));
|
op_dest = wallet->GetNewDestination(type, "");
|
||||||
} else {
|
} else {
|
||||||
assert(wallet->GetNewChangeDestination(type, dest, error));
|
op_dest = wallet->GetNewChangeDestination(type);
|
||||||
}
|
}
|
||||||
assert(error.empty());
|
assert(op_dest.HasRes());
|
||||||
return GetScriptForDestination(dest);
|
return GetScriptForDestination(op_dest.GetObj());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -610,9 +610,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||||
wallet->SetMinVersion(FEATURE_LATEST);
|
wallet->SetMinVersion(FEATURE_LATEST);
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||||
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
|
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
|
||||||
CTxDestination dest;
|
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
|
||||||
bilingual_str error;
|
|
||||||
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase());
|
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase());
|
||||||
|
@ -620,9 +618,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
wallet->SetMinVersion(FEATURE_LATEST);
|
wallet->SetMinVersion(FEATURE_LATEST);
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||||
CTxDestination dest;
|
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
|
||||||
bilingual_str error;
|
|
||||||
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2307,37 +2307,36 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, bilingual_str& error)
|
BResult<CTxDestination> CWallet::GetNewDestination(const OutputType type, const std::string label)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
error.clear();
|
|
||||||
bool result = false;
|
|
||||||
auto spk_man = GetScriptPubKeyMan(type, false /* internal */);
|
auto spk_man = GetScriptPubKeyMan(type, false /* internal */);
|
||||||
if (spk_man) {
|
if (!spk_man) {
|
||||||
spk_man->TopUp();
|
return strprintf(_("Error: No %s addresses available."), FormatOutputType(type));
|
||||||
result = spk_man->GetNewDestination(type, dest, error);
|
|
||||||
} else {
|
|
||||||
error = strprintf(_("Error: No %s addresses available."), FormatOutputType(type));
|
|
||||||
}
|
|
||||||
if (result) {
|
|
||||||
SetAddressBook(dest, label, "receive");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
spk_man->TopUp();
|
||||||
|
auto op_dest = spk_man->GetNewDestination(type);
|
||||||
|
if (op_dest) {
|
||||||
|
SetAddressBook(op_dest.GetObj(), label, "receive");
|
||||||
|
}
|
||||||
|
|
||||||
|
return op_dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& dest, bilingual_str& error)
|
BResult<CTxDestination> CWallet::GetNewChangeDestination(const OutputType type)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
error.clear();
|
|
||||||
|
|
||||||
|
CTxDestination dest;
|
||||||
|
bilingual_str error;
|
||||||
ReserveDestination reservedest(this, type);
|
ReserveDestination reservedest(this, type);
|
||||||
if (!reservedest.GetReservedDestination(dest, true, error)) {
|
if (!reservedest.GetReservedDestination(dest, true, error)) {
|
||||||
return false;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
reservedest.KeepDestination();
|
reservedest.KeepDestination();
|
||||||
return true;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int64_t> CWallet::GetOldestKeyPoolTime() const
|
std::optional<int64_t> CWallet::GetOldestKeyPoolTime() const
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <psbt.h>
|
#include <psbt.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
|
#include <util/result.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
@ -665,8 +666,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, bilingual_str& error);
|
BResult<CTxDestination> GetNewDestination(const OutputType type, const std::string label);
|
||||||
bool GetNewChangeDestination(const OutputType type, CTxDestination& dest, bilingual_str& error);
|
BResult<CTxDestination> GetNewChangeDestination(const OutputType type);
|
||||||
|
|
||||||
isminetype IsMine(const CTxDestination& dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
isminetype IsMine(const CTxDestination& dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
isminetype IsMine(const CScript& script) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
isminetype IsMine(const CScript& script) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
Loading…
Add table
Reference in a new issue