LoginSignup
0
0

More than 5 years have passed since last update.

Library System: Smart Contract

Last updated at Posted at 2018-10-15

これはとしょかんのシステムです

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);
  }

}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0