@arcologynetwork/concurrentlib

2.0.8 • Public • Published
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.

/@arcologynetwork/concurrentlib/

    Package Sidebar

    Install

    npm i @arcologynetwork/concurrentlib

    Weekly Downloads

    5

    Version

    2.0.8

    License

    MIT

    Unpacked Size

    131 kB

    Total Files

    37

    Last publish

    Collaborators

    • laurentyzhang
    • sameplace