Skip to content

Commit

Permalink
Some corrections (to be squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Oct 1, 2023
1 parent 471c71a commit 7d373c3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
21 changes: 17 additions & 4 deletions src/gridcoin/contract/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,23 @@ CAmount Contract::RequiredBurnAmount() const

bool Contract::WellFormed() const
{
return m_version > 0 && m_version <= Contract::CURRENT_VERSION
&& m_type != ContractType::UNKNOWN
&& m_action != ContractAction::UNKNOWN
&& m_body.WellFormed(m_action.Value());
bool result = m_version > 0 && m_version <= Contract::CURRENT_VERSION
&& m_type != ContractType::UNKNOWN
&& m_action != ContractAction::UNKNOWN
&& m_body.WellFormed(m_action.Value());

if (!result) {
LogPrint(BCLog::LogFlags::CONTRACT, "WARN: %s: Contract was not well formed. m_version = %u, m_type = %s, "
"m_action = %s, m_body.Wellformed(m_action.Value()) = %u",
__func__,
m_version,
m_type.ToString(),
m_action.ToString(),
m_body.WellFormed(m_action.Value())
);
}

return result;
}

ContractPayload Contract::SharePayload() const
Expand Down
30 changes: 28 additions & 2 deletions src/gridcoin/sidestake.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "gridcoin/contract/registry_db.h"
#include "gridcoin/support/enumbytes.h"
#include "serialize.h"
#include "logging.h"

namespace GRC {

Expand All @@ -29,6 +30,7 @@ class CBitcoinAddressForStorage : public CBitcoinAddress
// Note that (de)serializing the raw underlying vector char data for the address is safe here
// because this is only used in this module and validations were performed before serialization into
// storage.
READWRITE(nVersion);
READWRITE(vchData);
}
};
Expand Down Expand Up @@ -274,11 +276,35 @@ class SideStakePayload : public IContractPayload
//!
bool WellFormed(const ContractAction action) const override
{
if (m_version <= 0 || m_version > CURRENT_VERSION) {
bool valid = !(m_version <= 0 || m_version > CURRENT_VERSION);

if (!valid) {
LogPrint(BCLog::LogFlags::CONTRACT, "WARN: %s: Payload is not well formed. "
"m_version = %u, CURRENT_VERSION = %u",
__func__,
m_version,
CURRENT_VERSION);

return false;
}

valid = m_entry.WellFormed();

if (!valid) {
LogPrint(BCLog::LogFlags::CONTRACT, "WARN: %s: Sidestake entry is not well-formed. "
"m_entry.WellFormed = %u, m_entry.m_key = %s, m_entry.m_allocation = %f, "
"m_entry.StatusToString() = %s",
__func__,
valid,
m_entry.m_key.ToString(),
m_entry.m_allocation,
m_entry.StatusToString()
);

return false;
}

return m_entry.WellFormed();
return valid;
}

//!
Expand Down
12 changes: 6 additions & 6 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,12 +2454,12 @@ UniValue addkey(const UniValue& params, bool fHelp)
}

contract = GRC::MakeContract<GRC::SideStakePayload>(
contract_version,
action,
uint32_t {1}, // Contract payload version number
sidestake_address, // Sidestake address
allocation, // Sidestake allocation
GRC::SideStakeStatus::ACTIVE
contract_version, // Contract version number
action, // Contract action
uint32_t {1}, // Contract payload version number
sidestake_address, // Sidestake address
allocation, // Sidestake allocation
GRC::SideStakeStatus::MANDATORY // sidestake status
);
break;
}
Expand Down

0 comments on commit 7d373c3

Please sign in to comment.