GithubHelp home page GithubHelp logo

arcology-network / concurrentlib Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 455 KB

A suite of Solidity APIs customized for concurrent programming tasks on Arcology

Go 46.41% Python 0.22% Solidity 53.37%

concurrentlib's Introduction

Your Image Alt Text

Concurrent APIs

Solidity, the programming language used to develop smart contracts on the Ethereum platform, was not initially designed for concurrent use, so it does not include the features and capabilities necessary for efficient concurrent programming.

Arcology Network offers a suite of Solidity APIs customized for concurrent programming tasks. This package includes the Solidity APIs for smart contract developers to fully utilize the power of Arcology's parallel execution capabilities.

Please be aware that all the libraries in the package are specifically designed for Arcology Network only. They are not going to bring any benefits to Ethereum or other blockchain platforms.

Installation

$ npm install @arcologynetwork/concurrentlib

Usage

Once installed, you can use the contracts in the library by importing them.

Example

The following example demonstrates how to use the concurrentlib to parallelize a simple smart contract. Arcology has a set of concurrent data structures and variables that allow concurrent manipulations. Below is an example of that.

Simple Contract

The following example of a simple smart contract that allows users to like a post. A simplest version of the contract is shown below. When a calls the like() function, the likes of the receiver is incremented by 1.

This implementation doesn't support concurrent execution. If multiple users call the like() function concurrently, the likes of the receiver will be incremented concurrently. This is not allowed in Solidity.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

contract Like {
    uint public likes;

    function like() public {
        likes += 1;
    }    
}

Parallelized Version

In the parallelized version, the likes is replaced with a U256Cumulative variable from the arcologynetwork/contracts/concurrentlib/commutative/U256Cum.sol library. The variable allows concurrent increment and decrement operations. Now, the like() function can be called concurrently by multiple transactions.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
import "@arcologynetwork/concurrentlib/lib/commutative/U256Cum.sol";

contract Like {
    U256Cumulative likes = new U256Cumulative(0, type(uint256).max);

    function like() public {
        likes.add(1);
    }    
}

Learn More

You can find more examples in the developer's guide.

License

Arcology's concurrent lib is released under the MIT License.

Disclaimer

Arcology's concurrent lib is made available under the MIT License, which disclaims all warranties in relation to the project and which limits the liability of those that contribute and maintain the project. You acknowledge that you are solely responsible for any use of the Contracts and you assume all risks associated with any such use.

concurrentlib's People

Contributors

laurentyzhang avatar sameplacewei avatar jchyang avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar Kostas Georgiou avatar  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.