-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08b90cf
commit 81e637c
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |