Exercise - Demonstrate your knowledge of the new
keyword.
Ownable
contract called AddressBook
. It includes:
struct
called Contact
with properties for:
id
firstName
lastName
uint
array of phoneNumbers
contacts
addContact
function should be usable only by the owner of the contract. It should take in the necessary arguments to add a given contact’s information to contacts
.
deleteContact
function should be usable only by the owner and should delete the contact under the supplied _id
number.
If the _id
is not found, it should revert with an error called ContactNotFound
with the supplied id number.
getContact
function returns the contact information of the supplied _id
number. It reverts to ContactNotFound
if the contact isn’t present.
contacts
?getAllContacts
function returns an array with all of the user’s current, non-deleted contacts.
onlyOwner
for the two get functions. Doing so won’t prevent a third party from accessing the information, because all information on the blockchain is public. However, it may give the mistaken impression that information is hidden, which could lead to a security incident.AddressBookFactory
contains one function, deploy
. It creates an instance of AddressBook
and assigns the caller as the owner of that instance. It then returns the address
of the newly-created contract.