<commit_before>/**
 * This script should be run as child process
 */
var web3 = require('web3');

var globalRegistrar = require('./global_registrar');
var utils = require('./utils');
var errors = require('./errors');

var abi = [{
    "type": "event", "name": "Transfer", "inputs": [
        {"indexed": true, "name": "from", "type": "bytes32"},
        {"indexed": true, "name": "to", "type": "address"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "event", "name": "IcapTransfer", "inputs": [
        {"indexed": true, "name": "from", "type": "bytes32"},
        {"indexed": true, "name": "to", "type": "address"},
        {"indexed": false, "name": "indirectId", "type": "bytes32"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "event", "name": "AnonymousDeposit", "inputs": [
        {"indexed": true, "name": "from", "type": "address"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "event", "name": "Deposit", "inputs": [
        {"indexed": true, "name": "from", "type": "address"},
        {"indexed": true, "name": "to", "type": "bytes32"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "function", "name": "transfer", "constant": false, "inputs": [
        {"name": "from", "type": "bytes32"},
        {"name": "to", "type": "address"},
        {"name": "value", "type": "uint256"},
    ], "outputs": []
}, {
    "type": "function", "name": "icapTransfer", "constant": false, "inputs": [
        {"name": "from", "type": "bytes32"},
        {"name": "to", "type": "address"},
        {"name": "indirectId", "type": "bytes32"},
        {"name": "value", "type": "uint256"},
    ], "outputs": []
}];

/**
 * If any synchronous JSON-RPC request fails, UNKNOWN_ERROR should be thrown
 */
var transactions = function (config, identifier, options, callback) {
    try {

        // setup configurable properties
        var namereg = config.namereg === 'default' ? web3.eth.namereg : globalRegistrar.at(config.namereg);

        // start web3.js
        web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));
        if (!utils.validateIdentifier(identifier)) {
            return callback(errors.IDENTIFIER_IS_INCORRECT);
        }

        // validate exchange identifier
        var address = namereg.addr(identifier);
        if (utils.isEmptyAddress(address)) {
            return callback(errors.IDENTIFIER_NO_ADDRESS);
        }
    
        // this may take a while if we search from block 0
        // TODO: merge everything together ?
        var SmartExchange = web3.eth.contract(abi).at(address);
        var deposits = SmartExchange.Deposit({}, options).get();
        var anonymousDeposits = SmartExchange.AnonymousDeposit({}, options).get();
        var txs = SmartExchange.Transfer({}, options).get();
        var icapTxs = SmartExchange.IcapTransfer({}, options).get();
        callback(null, deposits.concat(anonymousDeposits).concat(txs).concat(icapTxs)); 

    } catch(err) {
        callback(errors.UNKNOWN_ERROR(err));
    }
};

module.exports = transactions;
<commit_msg>getting all transactions in one request instead of 4<commit_after>/**
 * This script should be run as child process
 */
var web3 = require('web3');

var globalRegistrar = require('./global_registrar');
var utils = require('./utils');
var errors = require('./errors');

var abi = [{
    "type": "event", "name": "Transfer", "inputs": [
        {"indexed": true, "name": "from", "type": "bytes32"},
        {"indexed": true, "name": "to", "type": "address"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "event", "name": "IcapTransfer", "inputs": [
        {"indexed": true, "name": "from", "type": "bytes32"},
        {"indexed": true, "name": "to", "type": "address"},
        {"indexed": false, "name": "indirectId", "type": "bytes32"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "event", "name": "AnonymousDeposit", "inputs": [
        {"indexed": true, "name": "from", "type": "address"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "event", "name": "Deposit", "inputs": [
        {"indexed": true, "name": "from", "type": "address"},
        {"indexed": true, "name": "to", "type": "bytes32"},
        {"indexed": false, "name": "value", "type": "uint256"},
    ]
}, {
    "type": "function", "name": "transfer", "constant": false, "inputs": [
        {"name": "from", "type": "bytes32"},
        {"name": "to", "type": "address"},
        {"name": "value", "type": "uint256"},
    ], "outputs": []
}, {
    "type": "function", "name": "icapTransfer", "constant": false, "inputs": [
        {"name": "from", "type": "bytes32"},
        {"name": "to", "type": "address"},
        {"name": "indirectId", "type": "bytes32"},
        {"name": "value", "type": "uint256"},
    ], "outputs": []
}];

/**
 * If any synchronous JSON-RPC request fails, UNKNOWN_ERROR should be thrown
 */
var transactions = function (config, identifier, options, callback) {
    try {

        // setup configurable properties
        var namereg = config.namereg === 'default' ? web3.eth.namereg : globalRegistrar.at(config.namereg);

        // start web3.js
        web3.setProvider(new web3.providers.HttpProvider('http://' + config.jsonrpc_host + ':' + config.jsonrpc_port));
        if (!utils.validateIdentifier(identifier)) {
            return callback(errors.IDENTIFIER_IS_INCORRECT);
        }

        // validate exchange identifier
        var address = namereg.addr(identifier);
        if (utils.isEmptyAddress(address)) {
            return callback(errors.IDENTIFIER_NO_ADDRESS);
        }
    
        var SmartExchange = web3.eth.contract(abi).at(address);
        var transactions = SmartExchange.allEvents(options).get();
        callback(null, transactions);
    } catch(err) {
        callback(errors.UNKNOWN_ERROR(err));
    }
};

module.exports = transactions;

{'fraction_non_alphanumeric': 0.21141268803139307, 'fraction_numerical': 0.013080444735120994, 'mean_word_length': 3.1612244897959183, 'pattern_counts': {'":': 144, '<': 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': '7122103', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1878, 'n_words': 472}