Skip to content

Commit

Permalink
Counter contract
Browse files Browse the repository at this point in the history
  • Loading branch information
TimTinkers committed Apr 19, 2021
1 parent 08b90cf commit 81e637c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions contracts/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

/**
@title A simple, example contract for incrementing a counter.
@author Tim Clancy
We use this contract to test out our centralized chain.
*/
contract Counter {

/// A version number for this contract's interface.
uint256 public version = 1;

/// The current value of the counter.
uint256 public value;

/// A mapping of addresses to the last value they incremented to.
mapping (address => uint256) public increments;

/// An event to track the counter incrementing.
event Increment(address incrementer, uint256 oldValue, uint256 newValue);

/**
Construct a new Counter with a starting initial value.
@param _initialValue The initial value of the Counter.
*/
constructor(uint256 _initialValue) public {
value = _initialValue;
}

/**
Returns the last value incremented to by a given address.
@param _incrementer The address to check.
@return the last value incremented to by an address.
*/
function getIncrementFor(address _incrementer) external view returns (uint256) {
return increments[_incrementer];
}

/**
Allow a user to increment this counter.
*/
function increment() external {
uint256 oldValue = value;
value = value + 1;
increments[msg.sender] = value;
emit Increment(msg.sender, oldValue, value);
}
}

0 comments on commit 81e637c

Please sign in to comment.