From 0194ff2e1d530f3f97564445e63182802940ab92 Mon Sep 17 00:00:00 2001 From: Sam Ayorinde Date: Wed, 22 Jan 2020 00:09:41 +0100 Subject: [PATCH 1/5] Sam-Devs added a new contract --- contracts/ExternalStorage.sol | 2 +- contracts/NewContract.sol | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 contracts/NewContract.sol 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..c3c9536 --- /dev/null +++ b/contracts/NewContract.sol @@ -0,0 +1,5 @@ +pragma solidity >=0.4.22 <0.6.0; + +contract participantsInfo { + uint participantsNum = 500; +} \ No newline at end of file From 8189c332aac2ef69e063c10c3ffd8dd1a20f7141 Mon Sep 17 00:00:00 2001 From: Sam Ayorinde Date: Wed, 22 Jan 2020 09:03:38 +0100 Subject: [PATCH 2/5] Update New Contract --- contracts/NewContract.sol | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/contracts/NewContract.sol b/contracts/NewContract.sol index c3c9536..76debdb 100644 --- a/contracts/NewContract.sol +++ b/contracts/NewContract.sol @@ -1,5 +1,20 @@ -pragma solidity >=0.4.22 <0.6.0; +pragma solidity >=0.5.0 <0.6.0; -contract participantsInfo { +contract Participants { uint participantsNum = 500; + uint + + 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 + function createNewParticipant (string memory _name, string memory _profession, string _hobby, uint age) public { + participants.push(ParticipantData(_name, _profession, _hobby, age)); + } } \ No newline at end of file From f30f2b95e663b1c55027d9e06b5d480866612a7a Mon Sep 17 00:00:00 2001 From: Sam Ayorinde Date: Wed, 22 Jan 2020 10:02:05 +0100 Subject: [PATCH 3/5] Additional functions to New Contract --- contracts/NewContract.sol | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/contracts/NewContract.sol b/contracts/NewContract.sol index 76debdb..dd1ecfb 100644 --- a/contracts/NewContract.sol +++ b/contracts/NewContract.sol @@ -1,8 +1,11 @@ pragma solidity >=0.5.0 <0.6.0; contract Participants { + // Event + event NewParticipant(string name, string profession, uint age); + uint participantsNum = 500; - uint + uint activeParticipants = 50 ** participantsNum; struct ParticipantData { string name; @@ -15,6 +18,18 @@ contract Participants { // This function create new participants' info function createNewParticipant (string memory _name, string memory _profession, string _hobby, uint age) public { - participants.push(ParticipantData(_name, _profession, _hobby, age)); + // 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 From 01185d14e88fd110b7e692dbdad7c7c811a89cb1 Mon Sep 17 00:00:00 2001 From: Sam Ayorinde Date: Wed, 22 Jan 2020 10:06:00 +0100 Subject: [PATCH 4/5] Addtional functions to New Contract --- contracts/NewContract.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/NewContract.sol b/contracts/NewContract.sol index dd1ecfb..90a5835 100644 --- a/contracts/NewContract.sol +++ b/contracts/NewContract.sol @@ -16,7 +16,7 @@ contract Participants { // Dynamic Array to keep record growing ParticipantData[] public participants; - // This function create new participants' info + // 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; From 1bbc1d65a6cdddeae249b6918ed00ed9e23f5177 Mon Sep 17 00:00:00 2001 From: princeadeayomide2019 Date: Sat, 8 Feb 2020 12:30:49 +0100 Subject: [PATCH 5/5] Just added my CRUD project --- contracts/AdoptionCRUD.sol | 24 ++++++++++++++++++++++++ contracts/externalAdoptionStorage.sol | 5 +++++ 2 files changed, 29 insertions(+) create mode 100644 contracts/AdoptionCRUD.sol create mode 100644 contracts/externalAdoptionStorage.sol 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/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