From 2c593a4d1a2383e6d824a2a316df2336af127f3e Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 13:24:25 -0300 Subject: [PATCH 1/3] add poex example --- contracts/examples/ProofOfExistence.sol | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 contracts/examples/ProofOfExistence.sol diff --git a/contracts/examples/ProofOfExistence.sol b/contracts/examples/ProofOfExistence.sol new file mode 100644 index 000000000..76df19e82 --- /dev/null +++ b/contracts/examples/ProofOfExistence.sol @@ -0,0 +1,32 @@ +// Proof of Existence contract, version 3 +contract ProofOfExistence3 { + + mapping (bytes32 => bool) proofs; + + // store a proof of existence in the contract state + function storeProof(bytes32 proof) { + proofs[proof] = true; + } + + // calculate and store the proof for a document + function notarize(string document) { + var proof = calculateProof(document); + storeProof(proof); + } + + // helper function to get a document's sha256 + function calculateProof(string document) returns (bytes32) { + return sha256(document); + } + + // check if a document has been notarized + function checkDocument(string document) returns (bool) { + var proof = calculateProof(document); + return hasProof(proof); + } + + // returns true if proof is stored + function hasProof(bytes32 proof) returns (bool) { + return proofs[proof]; + } +} From fd45473367921588dbf5dd460742ab41d4b00d56 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 13:29:34 -0300 Subject: [PATCH 2/3] minor mods to poex contract --- contracts/examples/ProofOfExistence.sol | 9 +++++++-- migrations/2_deploy_contracts.js | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/contracts/examples/ProofOfExistence.sol b/contracts/examples/ProofOfExistence.sol index 76df19e82..626ae015c 100644 --- a/contracts/examples/ProofOfExistence.sol +++ b/contracts/examples/ProofOfExistence.sol @@ -1,5 +1,10 @@ -// Proof of Existence contract, version 3 -contract ProofOfExistence3 { +import "../Rejector.sol"; + +/* + * Proof of Existence example contract + * see https://medium.com/zeppelin-blog/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05 + */ +contract ProofOfExistence is Rejector { mapping (bytes32 => bool) proofs; diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 8db14c0b9..b29a532cc 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -1,6 +1,7 @@ module.exports = function(deployer) { deployer.deploy(PullPaymentBid); deployer.deploy(BadArrayUse); + deployer.deploy(ProofOfExistence); deployer.deploy(Bounty); deployer.deploy(Ownable); deployer.deploy(LimitFunds); From c7f74555a3e1fb32d6c487fd14fd1a249270d286 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 13:45:55 -0300 Subject: [PATCH 3/3] add some modifiers to poex example --- contracts/examples/ProofOfExistence.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/examples/ProofOfExistence.sol b/contracts/examples/ProofOfExistence.sol index 626ae015c..e12382e43 100644 --- a/contracts/examples/ProofOfExistence.sol +++ b/contracts/examples/ProofOfExistence.sol @@ -6,7 +6,7 @@ import "../Rejector.sol"; */ contract ProofOfExistence is Rejector { - mapping (bytes32 => bool) proofs; + mapping (bytes32 => bool) public proofs; // store a proof of existence in the contract state function storeProof(bytes32 proof) { @@ -20,18 +20,18 @@ contract ProofOfExistence is Rejector { } // helper function to get a document's sha256 - function calculateProof(string document) returns (bytes32) { + function calculateProof(string document) constant returns (bytes32) { return sha256(document); } // check if a document has been notarized - function checkDocument(string document) returns (bool) { + function checkDocument(string document) constant returns (bool) { var proof = calculateProof(document); return hasProof(proof); } // returns true if proof is stored - function hasProof(bytes32 proof) returns (bool) { + function hasProof(bytes32 proof) constant returns (bool) { return proofs[proof]; } }