• Discover
  • Partner with us
  • Chapters
  • Blog

Learn everything about Solidity

Getting Started
✨Connect Your Profile to Open Campus
Introduction to Remix IDE
Counter Contract and Solidity Basics
Submit Your First Homework
Solidity Cheat Sheet
Creating Proposal Structure
Submit Your Second Homework

Creating a Counter
Creating a Proposal
Submit Your Third Homework
The Constructor
OnlyOwner Modifier
Voting Functionality

Correcting the Voting Functionality
Correcting the Voting Functionality 2
Calculating the Current State of a Proposal
Submit Your Fourth Task
Finalizing Proposal Contract
Final Version of the Proposal Contract

Submit Your Final Homework
Next Steps

Before moving forward with the function implementation, let's check the logic of calculating the current state of the contract.

You have three different choices:

  • Approve
  • Reject
  • Pass

For a proposal to succeed, the number of approve votes should be higher than the sum of reject and half the pass votes (you can think like pass vote has the half the impact). So, our formula is:approve = reject + pass / 2

You may have odd number of pass votes which cannot be divided by two. In these cases, you add 1 to the number of pass votes and then divide.

After knowing the logic of the function, the implementation is pretty straight forward:

function calculateCurrentState() private view returns(bool) {
    Proposal storage proposal = proposal_history[counter];

    uint256 approve = proposal.approve;
    uint256 reject = proposal.reject;
    uint256 pass = proposal.pass;
        
    if (proposal.pass %2 == 1) {
        pass += 1;
    }

    pass = pass / 2;

    if (approve > reject + pass) {
        return true;
    } else {
        return false;
    }
}

If you check the function definition, you see that you have used private and view.

  • You used private because this function is just a helper function for our previous vote function and it is only being used in the contract.
  • You used view because the function only views data from the blockchain and does not alter it.
Previous
Next

Lesson discussion

Swap insights and ask questions about “Learn everything about Solidity”.

Enroll to participate
Start the course to unlock the discussion. Enrolling helps us keep conversations relevant to learners.
WebsiteDiscoverPartner with UsBlogEvents
Discover
CoursesCircleRustSoliditySolanaWeb3 FundamentalsBlockchain Basics
CompanyAbout UsBrand GuidelineFAQsTerms of UsePrivacy PolicyGDPR NoticeCookies
Don't miss any update!

Disclaimer: The information, programs, and events provided on https://risein.com is strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice, nor do we make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://risein.com disclaims any responsibility for financial decisions made by users based on the information provided here.

© 2026 Rise In, All rights reserved