Skip to content

Commit bcdd0f5

Browse files
committed
[Mining] Use -miningaddress for in-wallet mining.
Replaces the hook to get a mining address from the wallet with a retrieval of the address set as `-miningaddress`. Disallows stealth addresses as per current behavior validating `-miningaddress` at startup and in rpc mining. Performs an additional safety check that the wallet actually owns the given address, falling back to a random wallet address otherwise (preserving current behavior).
1 parent 7e19268 commit bcdd0f5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/wallet/wallet.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,7 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
47024702
}
47034703
}
47044704

4705-
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4705+
void CWallet::GetScriptForMiningReserveKey(std::shared_ptr<CReserveScript> &script)
47064706
{
47074707
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
47084708
CPubKey pubkey;
@@ -4713,6 +4713,31 @@ void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
47134713
script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
47144714
}
47154715

4716+
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4717+
{
4718+
std::string sAddress = gArgs.GetArg("-miningaddress", "");
4719+
if (!sAddress.empty()) {
4720+
CTxDestination dest = DecodeDestination(sAddress);
4721+
4722+
if (IsValidDestination(dest)) {
4723+
if (IsMine(dest) != ISMINE_SPENDABLE) {
4724+
WalletLogPrintf("-miningaddress %s not under my control, falling back to random address", sAddress);
4725+
return GetScriptForMiningReserveKey(script);
4726+
}
4727+
// Disallow Stealth Addresses for now
4728+
CBitcoinAddress address(sAddress);
4729+
if (address.IsValidStealthAddress()) {
4730+
WalletLogPrintf("-miningaddress must be a basecoin address");
4731+
return GetScriptForMiningReserveKey(script);
4732+
}
4733+
script = std::make_shared<CReserveScript>();
4734+
script->reserveScript = GetScriptForDestination(dest);
4735+
return;
4736+
}
4737+
}
4738+
return GetScriptForMiningReserveKey(script);
4739+
}
4740+
47164741
void CWallet::LockCoin(const COutPoint& output)
47174742
{
47184743
AssertLockHeld(cs_wallet); // setLockedCoins

src/wallet/wallet.h

+1
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
12211221

12221222
const std::string& GetLabelName(const CScript& scriptPubKey) const;
12231223

1224+
void GetScriptForMiningReserveKey(std::shared_ptr<CReserveScript> &script);
12241225
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
12251226

12261227
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)

0 commit comments

Comments
 (0)