-
Notifications
You must be signed in to change notification settings - Fork 1
/
SnapshotToken.sol
executable file
·82 lines (70 loc) · 2.22 KB
/
SnapshotToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pragma solidity ^0.4.18;
import './ISnapshotToken.sol';
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
import 'zeppelin-solidity/contracts/token/StandardToken.sol';
/**
* @title Snapshot Token
*
* @dev Snapshot Token implementtion
* @dev https://send.sd/token
*/
contract SnapshotToken is ISnapshotToken, StandardToken, Ownable {
uint256 public snapshotBlock;
mapping (address => Snapshot) internal snapshots;
struct Snapshot {
uint256 block;
uint256 balance;
}
address public polls;
modifier isPolls() {
require(msg.sender == address(polls));
_;
}
/**
* @dev Remove Verified status of a given address
* @notice Only contract owner
* @param _address Address to unverify
*/
function setPolls(address _address) public onlyOwner {
polls = _address;
}
/**
* @dev Extend OpenZeppelin's BasicToken transfer function to store snapshot
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
takeSnapshot(msg.sender);
takeSnapshot(_to);
return BasicToken.transfer(_to, _value);
}
/**
* @dev Extend OpenZeppelin's StandardToken transferFrom function to store snapshot
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
takeSnapshot(_from);
takeSnapshot(_to);
return StandardToken.transferFrom(_from, _to, _value);
}
/**
* @dev Take snapshot
* @param _owner address The address to take snapshot from
*/
function takeSnapshot(address _owner) public returns(uint256) {
if (snapshots[_owner].block < snapshotBlock) {
snapshots[_owner].block = snapshotBlock;
snapshots[_owner].balance = balanceOf(_owner);
}
return snapshots[_owner].balance;
}
/**
* @dev Set snacpshot block
* @param _blockNumber uint256 The new blocknumber for snapshots
*/
function requestSnapshots(uint256 _blockNumber) public isPolls {
snapshotBlock = _blockNumber;
}
}