Skip to content

Commit

Permalink
Track reward addresses in settings (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Mar 6, 2023
1 parent 61576fa commit 6813315
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,15 @@ void CSettingsView::SetDexStatsEnabled(const bool enabled) {
std::optional<bool> CSettingsView::GetDexStatsEnabled() {
return ReadBy<KVSettings, bool>(DEX_STATS_ENABLED);
}

std::optional<std::set<CScript>> CSettingsView::SettingsGetRewardAddresses() {
return ReadBy<KVSettings, std::set<CScript>>(MN_REWARD_ADDRESSES);
}

void CSettingsView::SettingsSetRewardAddresses(const std::set<CScript> &addresses) {
WriteBy<KVSettings>(MN_REWARD_ADDRESSES, addresses);
}

/*
* CCustomCSView
*/
Expand Down Expand Up @@ -1345,4 +1354,12 @@ void CalcMissingRewardTempFix(CCustomCSView &mnview, const uint32_t targetHeight

return true;
});

if (const auto addresses = mnview.SettingsGetRewardAddresses()) {
for (const auto &rewardAddress : *addresses) {
if (IsMineCached(wallet, rewardAddress) == ISMINE_SPENDABLE) {
mnview.CalculateOwnerRewards(rewardAddress, targetHeight);
}
}
}
}
4 changes: 4 additions & 0 deletions src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,16 @@ class CSettingsView : public virtual CStorageView {
public:
const std::string DEX_STATS_LAST_HEIGHT = "DexStatsLastHeight";
const std::string DEX_STATS_ENABLED = "DexStatsEnabled";
const std::string MN_REWARD_ADDRESSES = "MNRewardAddresses";

void SetDexStatsLastHeight(int32_t height);
std::optional<int32_t> GetDexStatsLastHeight();
void SetDexStatsEnabled(bool enabled);
std::optional<bool> GetDexStatsEnabled();

std::optional<std::set<CScript>> SettingsGetRewardAddresses();
void SettingsSetRewardAddresses(const std::set<CScript> &addresses);

struct KVSettings {
static constexpr uint8_t prefix() { return '0'; }
};
Expand Down
12 changes: 12 additions & 0 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,18 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {

const auto keyID = CKeyID(uint160(rawAddress));
mnview.SetForcedRewardAddress(obj.mnId, *node, addressType, keyID, height);

// Store history of all reward address changes. This allows us to call CalculateOwnerReward
// on reward addresses owned by the local wallet. This can be removed some time after the
// next hard fork as this is a workaround for the issue fixed in the following PR:
// https://github.com/DeFiCh/ain/pull/1766
if (auto addresses = mnview.SettingsGetRewardAddresses()) {
const CScript rewardAddress = GetScriptForDestination(addressType == PKHashType ?
CTxDestination(PKHash(keyID)) :
CTxDestination(WitnessV0KeyHash(keyID)));
addresses->insert(rewardAddress);
mnview.SettingsSetRewardAddresses(*addresses);
}
} else if (type == static_cast<uint8_t>(UpdateMasternodeType::RemRewardAddress)) {
CDataStructureV0 key{AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::MNSetRewardAddress};
if (!attributes->GetValue(key, false)) {
Expand Down

0 comments on commit 6813315

Please sign in to comment.