- JavaScript 53%
- Solidity 39.9%
- CSS 3.8%
- HTML 3.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| client | ||
| contracts | ||
| migrations | ||
| test | ||
| .gitignore | ||
| Heritage Solidity Engineer JD.pdf | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| truffle-config.js | ||
A3 by Airbus Group - Solidity Engineer - Solidity Challenge
Solidity Smart Contracts to manage the inventory of a book library.
Initial Requirements
- The library has an owner and librarians.✔️
- The owner may add or remove librarians.✔️
- Only librarians may check books out to an address.✔️
- A book owner may trade the book to anyone else. ✔️
- Only the owner of a book can put it on sale
- Anyone can buy a book which is on sale
- Anyone may check in a book.✅
I changed this requirement into anyone except librarians... because I found weird to let librarians check back in books to themselves. - Librarians may add/remove books to the library. ✔️
- Track the history of the book's ownership. ✔️
To fulfill this requirement I am using an array ofTransferstructs within the Book struct. - Record damage & repair for a book.✔️
This is also covered by a book'sTransferstruct. - View book status/history. ✅
For a given book, the view/get function returns all Book's parameters but only the last recorded transfer. - Log relevant events. ✔️
- Use of the following tools/resource: ✔️
- Truffle Framework
- GitHub
- Mocha/Chai
- OpenZeppelin
- npm
- Perform unit tests ✔️
Additional requirements
On top of the requirements which were already specified, I also fulfilled the following:
13. Separate contract data from app logic (libraryData.sol and libraryApp.sol) to ensure upgradability. In the case where business rules were to change, a new app contract would be deployed without modifying the data contract.
14. Control which app contracts can call the data contract (callerAuthorized modifier and proper migration set up).
15. Operational control: set a boolean flag (operational)to stop the contracts in case something goes wrong (setOperationalStatus()).
16. Follow a CRUD pattern to manage books. Credit Rob Hitchens
17. Follow security best practice for payments/transfer: don't push the transfers but let users pull/withdraw their credited amount.
Data structures
- Tracks registered librarians:
librariansmapping - Track books
Bookstruct- Track check out/in:
checkedOutboolean - Track history of ownership and e.g damages:
Transferstruct andTransfers[]array
- Track check out/in:
booksmappingbookKeyshash keys array
- Trade books
priceproperty in Book struct- pattern: put book on sale, buy book, withdrawal
Getting Started
- Clone repository
- Install dependencies:
npm install - Run tests:
npm run test
Further developments
- Build front end (e.g with drizzle)
- Make contract ready for prod: some variables (e.g
withdrawalsmapping) were deliberately left with a public visibility to ease unit testing. This should be changed.