Git Product home page Git Product logo

ethginelite's Introduction

EthgineLite

A proof-of-concept business rules engine for the Ethereum platform that is inherently metadata-driven, written into the form of a smart contract using the Solidity language. Basically, after providing a number of rules and populating a record, a user can submit the populated record for validation by the rules engine.

Requirements

  • Basic knowledge of Ethereum and some experience with Javascript
  • An installation of Truffle and a local blockchain (like Ganache)
  • A fair amount of patience and forgiveness

Disclaimer

This prototype only serves as an example, and it should not even be considered an attempt at an actual implementation, since it has a number of shortcomings. For example, in terms of gas usage, this contract can be somewhat expensive.

The Basics

Quick Runthrough

After installing the Truffle framework and configuring/starting your local blockchain, change directory to the EthgineLite repo and compile the contracts:

$ truffle compile

Then deploy them to your local blockchain

$ truffle migrate

And finally test the engine using the provided Javascript file:

$ truffle test

Brief Overview of How to Use the Engine

1.) First, you need to define the data point(s) that we will want to test with the rules engine (like a Price, for example).

        // INSIDE THE CONTRACT'S CONSTRUCTOR
        attributes.push(WonkaLib.WonkaAttr({
                attrId: 2,
                attrName: "Price",
                maxLength: 128,
                maxLengthTruncate: false,
                maxNumValue: 1000000,
                defaultValue: "000",
                isString: false,
                isDecimal: false,
                isNumeric: true,
                isValue: true               
            }));
    // INSIDE THE TEST SCRIPT
    instance.addAttribute(web3.fromAscii('Language'), 64, 0, new String('ENG').valueOf(), true, false);

For now, the engine automatically creates three Attributes in the engine's constructor, but that could be changed easily.

2.) Next, you need to create a RuleSet for containing the rules:

    instance.addRuleSet(accounts[0], web3.fromAscii('ValidateProduct'));

As well as create the Rule itself:

    instance.addRule(accounts[0], web3.fromAscii('Validate price'), web3.fromAscii('Price'), GREATER_THAN_RULE, new String('0099').valueOf()); // in cents, since we can't use decimals

3.) Then, we need to populate our record (held within the contract instance for us) with the data:

    // SINCE ETHEREUM HAS LIMITATIONS WHEN DEALING WITH DYNAMIC ARRAYS AND MAPPINGS, WE MUST KEEP AN ARRAY/MAPPING
    // ON THE CONTRACT SIDE AND MANIPULATE IT FROM THE CLIENT
    instance.setValueOnRecord(accounts[0], web3.fromAscii('Title'), new String('The First Book').valueOf());
    instance.setValueOnRecord(accounts[0], web3.fromAscii('Price'), new String('0999').valueOf()); // in cents
    instance.setValueOnRecord(accounts[0], web3.fromAscii('PageAmount'), new String('289').valueOf());

4.) Finally, we execute the rules engine, using our provided RuleSet and applying it to our specified data record:

    instance.execute.call(accounts[0]);

And we learn whether or not the data record is valid, according to our provided rules.

Notices

This project will no longer be developed any further, since it only served as a proof of concept. However, you can understand its basis by reading about the ideas and the general design presented in my InfoQ article that talks about metadata-driven design (i.e., MDD) and business rules.

ethginelite's People

Stargazers

 avatar  avatar

Watchers

 avatar  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.