Skip to content

Instantly share code, notes, and snippets.

@wanseob
Created April 26, 2019 08:30
Show Gist options
  • Save wanseob/6986d27e825aef5dd5fb16a200034ea8 to your computer and use it in GitHub Desktop.
Save wanseob/6986d27e825aef5dd5fb16a200034ea8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=true&gist=
pragma solidity >=0.4.21 < 0.6.0;
contract DocumentSigner {
mapping(bytes32=>string) public docs;
mapping(bytes32=>address[]) public signers;
modifier validDoc(bytes32 _docHash) {
require(bytes(docs[_docHash]).length != 0, "Document is not submitted");
_;
}
event Sign(bytes32 indexed _doc, address indexed _signer);
event NewDocument(bytes32 _docHash);
function submitDocument(string memory _doc) public {
bytes32 _docHash = getHash(_doc);
if(bytes(docs[_docHash]).length == 0) {
docs[_docHash] = _doc;
emit NewDocument(_docHash);
}
}
function signDocument(bytes32 _docHash) public validDoc(_docHash) {
address[] storage _signers = signers[_docHash];
for(uint i = 0; i < _signers.length; i++) {
if(_signers[i] == msg.sender) return;
}
_signers.push(msg.sender);
}
function getDetail(bytes32 _docHash) public validDoc(_docHash) view returns(string memory _doc, address[] memory _signers) {
_doc = docs[_docHash];
_signers = signers[_docHash];
}
function getHash(string memory _doc) public pure returns(bytes32) {
return keccak256(abi.encodePacked(_doc));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment