github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/blockapps-ba-master/server/lib/bid/contracts/Bid.sol (about)

     1  import "../../common/ErrorCodes.sol";
     2  import "./BidState.sol";
     3  
     4  /**
     5   * Bid data contract
     6   */
     7  contract Bid is ErrorCodes, BidState {
     8    // NOTE: members must be public to be indexed for search
     9    uint public id;
    10    string public name;
    11    string public supplier;
    12    uint public amount;
    13    BidState public state;
    14  
    15    function Bid(uint _id, string _name, string _supplier, uint _amount) {
    16      id = _id;
    17      name = _name;
    18      supplier = _supplier;
    19      amount = _amount;
    20      state = BidState.OPEN;
    21    }
    22  
    23    function getState() returns (BidState) {
    24      return state;
    25    }
    26  
    27    function setState(BidState _state) {
    28      state = _state;
    29    }
    30  
    31    function setBidState(BidState newState) payable returns (ErrorCodes) {
    32      if (state == BidState.OPEN  &&  newState == BidState.ACCEPTED) {
    33        setState(newState);
    34        return ErrorCodes.SUCCESS;
    35      }
    36      if (state == BidState.OPEN  &&  newState == BidState.REJECTED) {
    37        setState(newState);
    38        return ErrorCodes.SUCCESS;
    39      }
    40      return ErrorCodes.ERROR;
    41    }
    42  
    43    function settle(address supplierAddress) returns (ErrorCodes) {
    44      // confirm balance, to return error
    45      if (this.balance < amount) {
    46        return ErrorCodes.INSUFFICIENT_BALANCE;
    47      }
    48      uint fee = 10000000 wei; // supplier absorbs the fee
    49      uint amountWei = amount * 1 ether;
    50  
    51      // transfer will throw
    52      supplierAddress.send(amountWei-fee);
    53      return ErrorCodes.SUCCESS;
    54    }
    55  }