Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions contracts/AdoptionCRUD.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

pragma solidity < 0.7.10;
import ./'externalAdoptionStorage.sol';
contract Adoption is externalStorage {
// Adoption a pet
//SETTER,CREATING AND UPDATING FUNCTION
function adopt(uint petId) public returns (uint) {
require(petId >= 0 && petId <= 15,'An adopter cannot adopt more than 16 pets');
adopters[petId] = msg.sender;
return petId;
}

// Retrieving the adopters
//READ FUNCTION

function getAdopters(uint id) public view returns(address) {
return adopters[id];
}

function deletePet(uint id) public {
require(id > 15,'You have not reach your limit of pet adoption');
delete adopters[id];
}
}
2 changes: 1 addition & 1 deletion contracts/ExternalStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.4.22 <0.6.0;
contract ExternalStorage{


mapping(bytes32 => uint) internal uIntStorage;
mapping(bytes32 => uint) internal uintStorage;
mapping(bytes32 => address) internal addressStorage;

struct Profile{
Expand Down
35 changes: 35 additions & 0 deletions contracts/NewContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity >=0.5.0 <0.6.0;

contract Participants {
// Event
event NewParticipant(string name, string profession, uint age);

uint participantsNum = 500;
uint activeParticipants = 50 ** participantsNum;

struct ParticipantData {
string name;
string profession;
string hobby;
uint age;
}
// Dynamic Array to keep record growing
ParticipantData[] public participants;

// This function create new participants' info/data
function createNewParticipant (string memory _name, string memory _profession, string _hobby, uint age) public {
// participants.push(ParticipantData(_name, _profession, _hobby, age));
uint data = participants.push(ParticipantData(_name, _profession, age)) - 1;
emit NewParticipant(data, name, profession, age);
}

function _activeParticipants (string memory _participants) private view returns (uint) {
uint participant = uint(keccak256(abi.encodePacked(_participants)));
return participant % activeParticipants;
}

function createActiveParticipants (string memory _name, string _memory _profession, string _hobby, uint age) public {
uint create = _activeParticipants(_participants);
createActiveParticipants(_name, _profession, _hobby, age, create);
}
}
5 changes: 5 additions & 0 deletions contracts/externalAdoptionStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity < 0.7.10;
contract externalStorage{
//STATE VARIABLE
address[16] public adopters;
}