https://github.com/jaerith/ethginelite
A proof-of-concept business rules engine for the Ethereum platform that is inherently metadata-driven.
https://github.com/jaerith/ethginelite
business-rules ethereum javascript metadata-driven solidity truffle-framework
Last synced: 3 months ago
JSON representation
A proof-of-concept business rules engine for the Ethereum platform that is inherently metadata-driven.
- Host: GitHub
- URL: https://github.com/jaerith/ethginelite
- Owner: jaerith
- License: apache-2.0
- Created: 2018-02-19T23:05:35.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-06T19:58:34.000Z (about 8 years ago)
- Last Synced: 2025-03-01T08:13:43.451Z (over 1 year ago)
- Topics: business-rules, ethereum, javascript, metadata-driven, solidity, truffle-framework
- Language: JavaScript
- Size: 34.2 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.