<commit_before>/**
 * Created by Julien on 22.04.2017.
 */
var express = require('express');
var app = express();
var async = require('async');
var PythonShell = require('python-shell');
var PORT = 3000;

var bodyParser = require('body-parser');
app.use(bodyParser.json());

var accountCounter = 0;
var users = {};

app.post('/new-contract', function (req, res) {
    var owner = req.body.owner;
    var partner = req.body.partner;
    var text = req.body.text;

    var options = {
      args: ['newContract', owner, partner, text]
    };

    PythonShell.run('smartContract.py', options, function (err, results) {
      if (err) throw err;
      var transID = results[0];
      if(!users[owner]) {
        users[owner] = [transID]
      } else {
        users[owner].push(transID)
      }
      if(!users[partner]) {
        users[partner] = [transID]
      } else {
        users[partner].push(transID)
      }
      //console.log(users);
      res.send(users);
    });
});

app.post('/contract-data', function (req, res) {
    var transID = req.body.address;
    getContractData(transID, function(result) {
        console.log(result);
        res.send(result);
    });
});

app.post('/contracts', function (req, res) {
    var userAddress = req.body.address;
    var contracts = [];
    var counter = 0;

    for(id in users[userAddress]) {
        var transID = users[userAddress].id;
        getContractData(transID, function(result) {
            counter ++;
            contracts.push(result);
            if (counter == users[userAddress].length) {
                res.send(contracts);
            }
        })
    }
});

app.get('/identification', function (req, res) {
    
});

app.post('/new-account', function (req, res) {
    
    var options = {
      mode: 'text',
      args: ['accounts', accountCounter++]
    };

    PythonShell.run('smartContract.py', options, function (err, result) {
        if (err) res.send(err);
        res.send(result[0]);
    });
});

app.listen(PORT, function () {
    console.log('ethereum backend online on port ' + PORT);
});

function getContractData(transID, callback) {
    var options = {
      args: ['contractData', transID]
    };

    PythonShell.run('smartContract.py', options, function (err, result) {
      if (err) throw err;
      callback(result);
    });<commit_msg>added option to save identity data in backend<commit_after>/**
 * Created by Julien on 22.04.2017.
 */
var express = require('express');
var app = express();
var async = require('async');
var PythonShell = require('python-shell');
var PORT = 3000;

var bodyParser = require('body-parser');
app.use(bodyParser.json());

var accountCounter = 0;
var users = {};

app.post('/new-contract', function (req, res) {
    var owner = req.body.owner;
    var partner = req.body.partner;
    var text = req.body.text;

    var options = {
      args: ['newContract', owner, partner, text]
    };

    PythonShell.run('smartContract.py', options, function (err, results) {
      if (err) throw err;
      var transID = results[0];
      if(!users[owner]) {
        users[owner] = [transID]
      } else {
        users[owner].push(transID)
      }
      if(!users[partner]) {
        users[partner] = [transID]
      } else {
        users[partner].push(transID)
      }
      //console.log(users);
      res.send(users);
    });
});

app.post('/contract-data', function (req, res) {
    var transID = req.body.address;
    getContractData(transID, function(result) {
        console.log(result);
        res.send(result);
    });
});

app.post('/contracts', function (req, res) {
    var userAddress = req.body.address;
    var contracts = [];
    var counter = 0;

    for(id in users[userAddress]) {
        var transID = users[userAddress].id;
        getContractData(transID, function(result) {
            counter ++;
            contracts.push(result);
            if (counter == users[userAddress].length) {
                res.send(contracts);
            }
        })
    }
});

app.post('/identity-data', function (req, res) {
    var userAddress = req.body.address;
    var identityData = users[userAddress]['identityData'];
    res.send(identityData);
});

app.post('/new-account', function (req, res) {
    var data = req.body.data;

    var options = {
      mode: 'text',
      args: ['accounts', accountCounter++]
    };

    PythonShell.run('smartContract.py', options, function (err, result) {
        if (err) res.send(err);
        userAddress = result[0];
        users[userAddress] = {
            'identityData': data
        };
        res.send(userAddress);
    });
});

app.listen(PORT, function () {
    console.log('ethereum backend online on port ' + PORT);
});

function getContractData(transID, callback) {
    var options = {
      args: ['contractData', transID]
    };

    PythonShell.run('smartContract.py', options, function (err, result) {
      if (err) throw err;
      callback(result);
    });
{'fraction_non_alphanumeric': 0.15899919289749798, 'fraction_numerical': 0.00645682001614205, 'mean_word_length': 2.5636232925952553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1509836', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1523, 'n_words': 344}