diff --git a/contracts/AdoptionCRUD.sol b/contracts/AdoptionCRUD.sol new file mode 100644 index 0000000..3b1ad6a --- /dev/null +++ b/contracts/AdoptionCRUD.sol @@ -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]; + } +} diff --git a/contracts/ExternalStorage.sol b/contracts/ExternalStorage.sol index 24661c6..d06aa08 100644 --- a/contracts/ExternalStorage.sol +++ b/contracts/ExternalStorage.sol @@ -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{ diff --git a/contracts/NewContract.sol b/contracts/NewContract.sol new file mode 100644 index 0000000..90a5835 --- /dev/null +++ b/contracts/NewContract.sol @@ -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); + } +} \ No newline at end of file diff --git a/contracts/externalAdoptionStorage.sol b/contracts/externalAdoptionStorage.sol new file mode 100644 index 0000000..894e670 --- /dev/null +++ b/contracts/externalAdoptionStorage.sol @@ -0,0 +1,5 @@ +pragma solidity < 0.7.10; + contract externalStorage{ + //STATE VARIABLE + address[16] public adopters; +} \ No newline at end of file