Giter Site home page Giter Site logo

pervaje28megh / library-entry--blockchain Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.17 MB

functionality for storing and checking the existence of entries based on their hashed values.

Solidity 100.00%
blockchain ethereum-contract metamask remix solidity-contracts

library-entry--blockchain's Introduction

Library-Entry--Blockchain

The code you provided is a simple Solidity smart contract written for the Ethereum blockchain. Let's go through the code and understand its functionality.

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

contract Library {

The contract is named "Library" and is specified to follow the GPLv3 license. It is written using Solidity version 0.8.0.

    mapping (bytes32 => bool) private entryExists;

The contract declares a private mapping called entryExists. It maps a bytes32 hash value to a boolean indicating whether an entry exists or not.

    event NewEntry(bytes32 indexed entryHash);

The contract defines an event called "NewEntry", which is emitted when a new entry is added. It includes the indexed parameter entryHash, which is of type bytes32.

    function addEntry(string memory entry) public {
        bytes32 hash = keccak256(bytes(entry));
        require(!entryExists[hash], "Entry already exists");
        entryExists[hash] = true;
        emit NewEntry(hash);
    }

The addEntry function takes a string parameter called entry and adds it as a new entry to the library. First, it calculates the keccak256 hash of the entry string using keccak256(bytes(entry)). It then checks if an entry with the calculated hash already exists in the entryExists mapping. If it does, the function reverts with the error message "Entry already exists." If the entry doesn't exist, the function sets the corresponding mapping value to true and emits the "NewEntry" event with the calculated hash.

    function checkEntry(string memory entry) public view returns (bool) {
        bytes32 hash = keccak256(bytes(entry));
        return entryExists[hash];
    }
}

The checkEntry function takes a string parameter called entry and returns a boolean indicating whether the entry exists in the library. It calculates the hash of the entry string and retrieves the corresponding boolean value from the entryExists mapping.

Overall, this contract provides a simple library-like functionality for storing and checking the existence of entries based on their hashed values.

library-entry--blockchain's People

Contributors

pervaje28megh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.