Verified contractPartial
SVDelegation
Address0xd78d4beabfd3054390d10aeb4258dc2d867f5e17
- Balance
0 ETH
- Transactions
51
- Compiler
solc 0.4.20
- Same code
Only this contract
Details
- Compiler
- solc 0.4.20+commit.3155dd80
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 5,173,255
- Creation transaction
- 0x79f447aa6c…17ca2bc72f
SVDelegation.sol
pragma solidity ^0.4.19;
// DELEGATION SC
// (c) SecureVote 2018
// Released under MIT licence
contract SVDelegation {
address public owner;
struct Delegation {
uint256 thisDelegationId;
address dlgt;
uint256 setAtBlock;
uint256 prevDelegation;
}
mapping (address => mapping (address => Delegation)) tokenDlgts;
mapping (address => Delegation) globalDlgts;
mapping (uint256 => Delegation) public historicalDelegations;
uint256 public totalDelegations = 0;
event SetGlobalDelegation(address voter, address delegate);
event SetTokenDelegation(address voter, address tokenContract, address delegate);
function SVDelegation() public {
owner = msg.sender;
// commit the genesis historical delegation to history (like genesis block)
createDelegation(address(0), 0);
}
function createDelegation(address dlgtAddress, uint256 prevDelegationId) internal returns(Delegation) {
uint256 myDelegationId = totalDelegations;
historicalDelegations[myDelegationId] = Delegation(myDelegationId, dlgtAddress, block.number, prevDelegationId);
totalDelegations += 1;
return historicalDelegations[myDelegationId];
}
// get previous delegation, create new delegation via function and then commit to globalDlgts
function setGlobalDelegation(address dlgtAddress) public {
uint256 prevDelegationId = globalDlgts[msg.sender].thisDelegationId;
globalDlgts[msg.sender] = createDelegation(dlgtAddress, prevDelegationId);
SetGlobalDelegation(msg.sender, dlgtAddress);
}
// get previous delegation, create new delegation via function and then commit to tokenDlgts
function setTokenDelegation(address tokenContract, address dlgtAddress) public {
uint256 prevDelegationId = tokenDlgts[tokenContract][msg.sender].thisDelegationId;
tokenDlgts[tokenContract][msg.sender] = createDelegation(dlgtAddress, prevDelegationId);
SetTokenDelegation(msg.sender, tokenContract, dlgtAddress);
}
function resolveDelegation(address voter, address tokenContract) public constant returns(uint256, address, uint256, uint256) {
Delegation memory _tokenDlgt = tokenDlgts[tokenContract][voter];
// probs simplest test to check if we have a valid delegation
if (_tokenDlgt.setAtBlock > 0) {
return _dlgtRet(_tokenDlgt);
} else {
return _dlgtRet(globalDlgts[voter]);
}
}
function _rawGetGlobalDelegation(address _voter) public constant returns(uint256, address, uint256, uint256) {
return _dlgtRet(globalDlgts[_voter]);
}
function _rawGetTokenDelegation(address _voter, address _tokenContract) public constant returns(uint256, address, uint256, uint256) {
return _dlgtRet(tokenDlgts[_tokenContract][_voter]);
}
function _dlgtRet(Delegation d) internal pure returns(uint256, address, uint256, uint256) {
return (d.thisDelegationId, d.dlgt, d.setAtBlock, d.prevDelegation);
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.