Skip to content

Instantly share code, notes, and snippets.

@rgsk
Created November 21, 2021 10:04
Show Gist options
  • Save rgsk/8089d4a58e72c5fa5d0d3c1f5d512d5b to your computer and use it in GitHub Desktop.
Save rgsk/8089d4a58e72c5fa5d0d3c1f5d512d5b to your computer and use it in GitHub Desktop.
web 3.0 Session 1
pragma solidity >=0.7.0 <0.9.0;
contract Kudos {
mapping (address => Kudo[]) allKudos;
function giveKudos(address who, string memory what, string memory comments) public {
Kudo memory kudo = Kudo(what, msg.sender, comments);
allKudos[who].push(kudo);
}
function getKudosAtIndex(address who, uint index) public view returns (string memory, address, string memory) {
Kudo memory kudo = allKudos[who][index];
return (kudo.what, kudo.giver, kudo.comments);
}
function getKudosLength(address who) public view returns (uint) {
Kudo[] memory kudos = allKudos[who];
return kudos.length;
}
}
struct Kudo {
string what;
address giver;
string comments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment