From 7d373c3f6bdf834b710bd2ac86639040cb6ebd07 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 1 Oct 2023 16:39:24 -0400 Subject: [PATCH] Some corrections (to be squashed) --- src/gridcoin/contract/contract.cpp | 21 +++++++++++++++++---- src/gridcoin/sidestake.h | 30 ++++++++++++++++++++++++++++-- src/rpc/blockchain.cpp | 12 ++++++------ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/gridcoin/contract/contract.cpp b/src/gridcoin/contract/contract.cpp index b68685068c..94ed78d5ab 100644 --- a/src/gridcoin/contract/contract.cpp +++ b/src/gridcoin/contract/contract.cpp @@ -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 diff --git a/src/gridcoin/sidestake.h b/src/gridcoin/sidestake.h index 92f28255f4..5018a438e6 100644 --- a/src/gridcoin/sidestake.h +++ b/src/gridcoin/sidestake.h @@ -11,6 +11,7 @@ #include "gridcoin/contract/registry_db.h" #include "gridcoin/support/enumbytes.h" #include "serialize.h" +#include "logging.h" namespace GRC { @@ -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); } }; @@ -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; } //! diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 9ffab4b17f..025d6584f3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2454,12 +2454,12 @@ UniValue addkey(const UniValue& params, bool fHelp) } contract = GRC::MakeContract( - 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; }