これはとしょかんのシステムです
pragma solidity ^0.4.25; //version
。
contract Library {
//This is the structure of the contract
struct Book {
string bookTitle;
bool inTheShelf;
address user;
}
//Declaration of two books
Book book = Book("book1",true,address(0));
Book book2 = Book("book2",true,address(0));
//This is an array container of the books
Book[] books;
//calls first
//This is the constructor of the smart contract
constructor() public {
books.push(book);
books.push(book2);
}
//This is the function for borrowBook
function borrowBook(uint i) public {
require(!books[i].inTheShelf);
books[i].inTheShelf = false;
books[i].user = msg.sender;
}
//This is the function for returnBook
function returnBook(uint i) public {
require(books[i].inTheShelf);
require(books[i].user == msg.sender);
books[i].intheShelf = true;
books[i].user = address(0);
}
}