Coder Social home page Coder Social logo

cron's Introduction

Cron

Build Status codecov

About

This solidity library enable schedule periodical states on the Ethereum Blockchain from a Smart Contract , making it possible for external contracts to lazily allow other state changes on a periodic Basis.

Install

In order to install the library, just run the following commands on your root solidity directory

npm init -y
npm i -E solidity-cron

How to use

There are two different cases where the library could be used:

  • Periods: When your DApp just needs an index counting the amount of blocks passed since a certain block-
  • Periodic Stages: When your DApp includes also certain actions inside every period.

Using Periods

A periodic Ethereum DApp that needs to handle the current period index.

Importing

Just import the Periodic contract into your Smart Contract, and initialize it.

import "@frontier-token-research/contracts/Period.sol";

Initializing

After that you can define your own period in Blocks, just doing

Period MyDAppPeriod = new Period(T)

Being T the amount of blocks that you want to have as a period.

Getting the current period number

After that, from your Smart Contract you can always reference your current period by calling getCurrentPeriod():

uint256 currentPeriod =  myDappPeriod.getCurrentPeriod();

It will return an incremented value every T blocks.

Using Periodic Stages

Your DApp might have different stages that are repeated over the previously defined period. For example, you might need to give permissions to certain actions only on a certain stage of your period. In this case, instead of creating just a period, it is possible to create a Periodic Stages instance, defininig just the period number :

Importing

import "@frontier-token-research/contracts/Period.sol";

PeriodicStages MyDAppStages = new PeriodicStages(T)

Pushing stages

You can now push any stage using the stages FIFOstack, just defininng the amount of blocks the given stage is going to last:

myDappStages.push(duration)

This will add to your stack a new scheduled Task, filling the period since last pushed stage index to the specified above duration

Getting the current stage

Once the stage has been pushed, you can always get the current stage (by reading the current block), by calling

myDappStages.currentStage()

Testing

You can always use the truffle package to test and contribute to the library. The package needs from a running Ethereum rpc instance in localhost, port 8545. You can run a ganache-cli instance or run geth. You can run the tests by just running:

truffle test

Contributing

If you want to contribute, just open a PR making sure your commits follow Angular Git Commit guidelines, to follow semantic-releaseversioning.

cron's People

Contributors

buendiadas avatar joaosantos15 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

cron's Issues

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.