A generic "Claim and Endorse" Ethereum Smart Contract

in #ethereum8 years ago (edited)

Did you already endorse someone at LinkedIn? For instance, someone claims that he knows C++ and you endorse this claim because you know it’s true. A large number of processes can be modelled in this way.

A simple Solidity contract for managing claims and endorsements could look like below.

contract ClaimAndEndorse {
  struct ENDORSEMENT {
  uint creationTime;
 }
 
 struct CLAIM {
  uint creationTime;
  uint claimHash;
  mapping (address => ENDORSEMENT) endorsements;
 }
 
 mapping (address => 
  mapping (uint /* CLAIM GUID */ => CLAIM)) claims;
 
 function setClaim(uint claimGuid, uint claimHash) {
  CLAIM c = claims[msg.sender][claimGuid];
  if(c.claimHash > 0) throw; // unset first!
  c.creationTime = now;
  c.claimHash = claimHash;
 }
 
 function unsetClaim(uint claimGuid) {
  delete claims[msg.sender][claimGuid];
 }
 
 function setEndorsement(
  address claimer, uint claimGuid, uint expectedClaimHash
 ) {
  CLAIM c = claims[claimer][claimGuid];
  if(c.claimHash != expectedClaimHash) throw;
  ENDORSEMENT e = c.endorsements[msg.sender];
  e.creationTime = now;
 }
 
 function unsetEndorsement(address claimer, uint claimGuid) {
  delete claims[claimer][claimGuid]
          .endorsements[msg.sender];
 }
 
 function checkClaim(
  address claimer, uint claimGuid, uint expectedClaimHash
 ) constant returns (bool) {
  return claims[claimer][claimGuid].claimHash 
         == expectedClaimHash;
 }
 
 function checkEndorsement(
  address claimer, uint claimGuid, address endorsedBy
 ) constant returns (bool) {
  return claims[claimer][claimGuid]
   .endorsements[endorsedBy].creationTime > 0;
 }
}

The fantastic thing about this very simple contract is that we now can answer the following question:

Who claims what and who endorses it?

...

Read the full article at blockchainers.org.

Sort:  

Great article and very informative! 👍

Congratulations @ivicaa! You have received a personal award!

Happy Birthday - 1 Year on Steemit Happy Birthday - 1 Year on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.

For more information about this award, click here

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @ivicaa! You have received a personal award!

2 Years on Steemit
Click on the badge to view your Board of Honor.

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @ivicaa! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 3 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.19
TRX 0.24
JST 0.037
BTC 96612.01
ETH 3387.37
USDT 1.00
SBD 3.05