struct mapping in ink substrate

212 Views Asked by At

In solidity we can do the mapping of structure like this

struct BookEntry {
        string bookId;
        string bookName;
        string authorName;
        bool released;
    }

  mapping (string => BookEntry) keyval;

and set the values corresponding to bookId like this

function setBook(string memory bookId, string memory bookName, string memory authorName) public returns(string memory){
   keyval[bookId].bookId = bookId;
   keyval[bookId].bookName = bookName;
   keyval[bookId].authorName = authorName;
   keyval[bookId].released = true;
   return bookId;
}

How can this structure be mapped in ink substrate contract?

#[ink::contract]
mod btc_new {

    use ink_prelude::string::String;

    #[ink(storage)]
    pub struct BookEntry {
        book_id: String,
        book_name: String,
        author_name: String,
        is_released: bool,
        
    }
0

There are 0 best solutions below