pragma solidity ^0.4.25; contract SimpleLibrarySystem { // data needed // 必要なデータです uint totalNumberOfBooks; uint totalNumberOfBorrowers; uint currentNumberOfBorrowers; struct bookDetails { uint id; string titleOfBook; string authorOfBook; bool isBorrowed; } struct borrowerDetails { uint id; uint bookID; string borrowerName; } // initialize the contract // スマートコントラクトを初期化します constructor() public { totalNumberOfBooks = 0; totalNumberOfBorrowers = 0; currentNumberOfBorrowers = 0; } mapping (uint => bookDetails) books; mapping (uint => borrowerDetails) borrowers; // function to add books // 本を追加すること機能です function addBooks(string title, string author) public { totalNumberOfBooks+=1; books[totalNumberOfBooks] = bookDetails(totalNumberOfBooks, title, author, false); } // function to borrow a book // the book to be borrowed should be available // 本を借りること機能です // 借りる本は利用可能になるはずです function borrowBook(uint bookID, string name) public { require(books[bookID].isBorrowed == false); require(currentNumberOfBorrowers < totalNumberOfBooks); totalNumberOfBorrowers+=1; currentNumberOfBorrowers+=1; borrowers[totalNumberOfBorrowers] = borrowerDetails(totalNumberOfBorrowers, bookID, name); books[bookID].isBorrowed = true; } // function to return a book // you cannot return an unborrowed book // 本を返すこと関数です // 借りてない本を返すことはできません function returnBook(uint bookID) public { require(books[bookID].isBorrowed == true); currentNumberOfBorrowers-=1; books[bookID].isBorrowed = false; } // function to see the total number of books // 書籍の総数を表示すること機能です function getTotalNumberOfBooks() public constant returns (uint) { return totalNumberOfBooks; } // function to see the total number of borrowers // 借り手の総数を表示すること機能です function getCurrentNumberOfBorrowers() public constant returns (uint) { return currentNumberOfBorrowers; } }
0.4.25