github.com/XinFinOrg/xdcchain@v1.1.0/contracts/blocksigner/contract/BlockSigner.sol (about) 1 pragma solidity ^0.4.21; 2 3 import "./libs/SafeMath.sol"; 4 5 contract BlockSigner { 6 using SafeMath for uint256; 7 8 event Sign(address _signer, uint256 _blockNumber, bytes32 _blockHash); 9 10 mapping(bytes32 => address[]) blockSigners; 11 mapping(uint256 => bytes32[]) blocks; 12 uint256 public epochNumber; 13 14 function BlockSigner(uint256 _epochNumber) public { 15 epochNumber = _epochNumber; 16 } 17 18 function sign(uint256 _blockNumber, bytes32 _blockHash) external { 19 // consensus should validate all senders are validators, gas = 0 20 require(block.number >= _blockNumber); 21 require(block.number <= _blockNumber.add(epochNumber * 2)); 22 blocks[_blockNumber].push(_blockHash); 23 blockSigners[_blockHash].push(msg.sender); 24 25 emit Sign(msg.sender, _blockNumber, _blockHash); 26 } 27 28 function getSigners(bytes32 _blockHash) public view returns(address[]) { 29 return blockSigners[_blockHash]; 30 } 31 }