concept design process in category blockchain

appears as: design process, The design process
Blockchain in Action

This is an excerpt from Manning's book Blockchain in Action.

In this book we use two UML behavioral diagrams: use case diagrams for requirements gathering as one of the first steps in the design process, and finite state machine (FSM) diagrams later in the design process for defining state transitions of the executable code (smart contracts) on the blockchain. We’ll start by examining both of these in depth.

A smart contract is deployed on the blockchain by a transaction. It is permanently recorded on the blockchain, irreversible and unchangeable, and part of the chain of blocks, as stated in design principle 1.

// modifiers
   modifier validPhase(Phase reqPhase)                             #1
    { require(state == reqPhase); 
      _; 
    } 
    modifier onlyChair()                                           #1
     {require(msg.sender == chairperson);
      _;
     }
 
    constructor (uint numProposals) public  {
        chairperson = msg.sender;
        voters[chairperson].weight = 2; // weight 2 for testing purposes
        for (uint prop = 0; prop < numProposals; prop ++)
            proposals.push(Proposal(0));        
        state = Phase.Regs;
    }
    
     function changeState(Phase x) onlyChair public {              #2
        
        require (x > state );                                      #3
        state = x;
     }
    
    function register(address voter) public validPhase(Phase.Regs)      
                                                   onlyChair {     #4
       
        require (! voters[voter].voted);                           #3
        
        voters[voter].weight = 1;
       // voters[voter].voted = false;
    }
 
   
    function vote(uint toProposal) public validPhase(Phase.Vote)  {
      
        Voter memory sender = voters[msg.sender];                  #5
        
        require (!sender.voted);                                   #6
        require (toProposal < proposals.length);                   #6
        
        sender.voted = true;
        sender.vote = toProposal;   
        proposals[toProposal].voteCount += sender.weight;
    }
 
    function reqWinner() public validPhase(Phase.Done) view 
                            returns (uint winningProposal) 
    {
       
        uint winningVoteCount = 0;
        for (uint prop = 0; prop < proposals.length; prop++) 
            if (proposals[prop].voteCount > winningVoteCount) {
                winningVoteCount = proposals[prop].voteCount;
                winningProposal = prop;
            } 
       assert(winningVoteCount>=3);                                #7
    }
}