<commit_before>(function() {
    var contract_name = document.getElementById('contract_name'),
        contract_address = document.getElementById('contract_address'),
        contract_abi = document.getElementById('contract_abi'),
        createBtn = document.getElementById('create'),
        clearBtn = document.getElementById('clear'),
        downloadBtn = document.getElementById('download');

    createBtn.addEventListener('click', function() {
        var contractName = contract_name.value;
        var contractAddress = contract_address.value;
        var contractAbi = JSON.parse(contract_abi.value);

        var abi = new ABI(contractName, contractAddress, contractAbi);

        var format = 'ts';

        var abiFile = abiToFile(abi, formats[format]);
        downloadBtn.href = abiFile.url;
        downloadBtn.download = contractName + '.' + format;

        setOutput(abiFile.text);
    }, false);

    clearBtn.addEventListener('click', function() {
        contract_name.value = '';
        contract_address.value = '';
        contract_abi.value = '';
        downloadBtn.href = "#";
        downloadBtn.download = '';

        setOutput('Output');
    }, false);

    function setOutput(output) {
        document.getElementById('output').innerHTML = output;
        window.prettyPrint();
    }
})();


var currentFile = null;

function abiToFile(abi, outputFormat) {
    var parser = new outputFormat.parser(abi);
    var text = parser.Run();

    var data = new Blob([text], { type: outputFormat.format });

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (currentFile !== null) {
        window.URL.revokeObjectURL(currentFile);
    }

    currentFile = window.URL.createObjectURL(data);

    return new ABIFile(currentFile, text);
}

var ABI = function(name, address, abiArray) {
    this.ABIArray = JSON.parse(JSON.stringify(abiArray));
    this.contractName = name;
    this.contractAddress = address;
    this.contractConstructor = null;
    this.contractMethods = [];
    this.contractEvents = [];

    for (var i = 0; i < abiArray.length; i++) {
        var element = abiArray[i];
        if (element.type === 'constructor') {
            this.contractConstructor = element;
        } else if (element.type === 'function') {
            this.contractMethods.push(element);
        } else if (element.type === 'event') {
            this.contractEvents.push(element);
        } else {
            console.log('ABI element lost: ' + JSON.stringify(element));
        }
    }
};

var ABIParser = function(abi) {
    // a value from formats (ex: formats.ts)
    this.format = '';

    this.abi = abi;
    this.currentIndent = 0;
    this.output = '';
    this.runned = false;
};

ABIParser.prototype.getInputType = function(input) {
    var type = input.type;

    var isArray = type.indexOf("[]") >= 0;
    if (isArray)
        type = type.replace("[]", "");

    if (type in this.format.types)
        type = this.format.types[type];

    if (isArray)
        type += "[]";

    return type;
};

ABIParser.prototype.appendIndent = function() {
    for (var i = 0; i < this.currentIndent; i++) {
        this.output += "\t";
    }
};

ABIParser.prototype.appendNewline = function() {
    this.output += "\r\n";
    this.appendIndent();
};

ABIParser.prototype.openBrackets = function() {
    this.output += " {";
    this.currentIndent++;

    this.appendNewline();
};

ABIParser.prototype.closeBrackets = function() {
    if (this.output[this.output.length - 1] === '\t')
        this.output = this.output.substring(0, this.output.length - 1)

    this.output += "}";
    this.currentIndent--;

    this.appendNewline();
};

ABIParser.prototype.Run = function() {
    // subclasses need to override this method
    if (this.runned)
        return this.output;
    this.output = "Not implemented";
    this.runned = true;
    return this.output;
};


var ABIToTs = function(abi) {
    ABIParser.call(this, abi);
    this.format = formats.ts;
};

ABIToTs.prototype = Object.create(ABIParser.prototype);

ABIToTs.prototype.constructor = ABIParser;

ABIToTs.prototype.appendInput = function(input, appendComma) {
    this.output += input.name + ': ' + this.getInputType(input);
    appendComma && (this.output += ', ');
};

ABIToTs.prototype.appendOutputTypes = function(outputs) {
    var out = null;
    if (outputs.length === 1) {
        out = outputs[0];
        this.output += 'Observable< ' + this.getInputType(out) + ' ' + out.name + ' >';
    } else {
        this.output += 'Observable<{ ';
        for (i = 0; i < outputs.length; i++) {
            out = outputs[i];
            this.output += out.name + ' : ' + this.getInputType(out);
            i + 1 < outputs.length && (this.output += ', ');
        }
        this.output += ' }>';
    }<commit_msg>Add possibility for outputs with type but without name<commit_after>(function() {
    var contract_name = document.getElementById('contract_name'),
        contract_address = document.getElementById('contract_address'),
        contract_abi = document.getElementById('contract_abi'),
        createBtn = document.getElementById('create'),
        clearBtn = document.getElementById('clear'),
        downloadBtn = document.getElementById('download');

    createBtn.addEventListener('click', function() {
        var contractName = contract_name.value;
        var contractAddress = contract_address.value;
        var contractAbi = JSON.parse(contract_abi.value);

        var abi = new ABI(contractName, contractAddress, contractAbi);

        var format = 'ts';

        var abiFile = abiToFile(abi, formats[format]);
        downloadBtn.href = abiFile.url;
        downloadBtn.download = contractName + '.' + format;

        setOutput(abiFile.text);
    }, false);

    clearBtn.addEventListener('click', function() {
        contract_name.value = '';
        contract_address.value = '';
        contract_abi.value = '';
        downloadBtn.href = "#";
        downloadBtn.download = '';

        setOutput('Output');
    }, false);

    function setOutput(output) {
        document.getElementById('output').innerHTML = output;
        window.prettyPrint();
    }
})();


var currentFile = null;

function abiToFile(abi, outputFormat) {
    var parser = new outputFormat.parser(abi);
    var text = parser.Run();

    var data = new Blob([text], { type: outputFormat.format });

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (currentFile !== null) {
        window.URL.revokeObjectURL(currentFile);
    }

    currentFile = window.URL.createObjectURL(data);

    return new ABIFile(currentFile, text);
}

var ABI = function(name, address, abiArray) {
    this.ABIArray = JSON.parse(JSON.stringify(abiArray));
    this.contractName = name;
    this.contractAddress = address;
    this.contractConstructor = null;
    this.contractMethods = [];
    this.contractEvents = [];

    for (var i = 0; i < abiArray.length; i++) {
        var element = abiArray[i];
        if (element.type === 'constructor') {
            this.contractConstructor = element;
        } else if (element.type === 'function') {
            this.contractMethods.push(element);
        } else if (element.type === 'event') {
            this.contractEvents.push(element);
        } else {
            console.log('ABI element lost: ' + JSON.stringify(element));
        }
    }
};

var ABIParser = function(abi) {
    // a value from formats (ex: formats.ts)
    this.format = '';

    this.abi = abi;
    this.currentIndent = 0;
    this.output = '';
    this.runned = false;
};

ABIParser.prototype.getInputType = function(input) {
    var type = input.type;

    var isArray = type.indexOf("[]") >= 0;
    if (isArray)
        type = type.replace("[]", "");

    if (type in this.format.types)
        type = this.format.types[type];

    if (isArray)
        type += "[]";

    return type;
};

ABIParser.prototype.appendIndent = function() {
    for (var i = 0; i < this.currentIndent; i++) {
        this.output += "\t";
    }
};

ABIParser.prototype.appendNewline = function() {
    this.output += "\r\n";
    this.appendIndent();
};

ABIParser.prototype.openBrackets = function() {
    this.output += " {";
    this.currentIndent++;

    this.appendNewline();
};

ABIParser.prototype.closeBrackets = function() {
    if (this.output[this.output.length - 1] === '\t')
        this.output = this.output.substring(0, this.output.length - 1)

    this.output += "}";
    this.currentIndent--;

    this.appendNewline();
};

ABIParser.prototype.Run = function() {
    // subclasses need to override this method
    if (this.runned)
        return this.output;
    this.output = "Not implemented";
    this.runned = true;
    return this.output;
};


var ABIToTs = function(abi) {
    ABIParser.call(this, abi);
    this.format = formats.ts;
};

ABIToTs.prototype = Object.create(ABIParser.prototype);

ABIToTs.prototype.constructor = ABIParser;

ABIToTs.prototype.appendInput = function(input, appendComma) {
    this.output += input.name + ': ' + this.getInputType(input);
    appendComma && (this.output += ', ');
};

ABIToTs.prototype.appendOutputTypes = function(outputs) {
    var out = null;
    if (outputs.length === 1) {
        out = outputs[0];
        this.output += 'Observable< ';
        (out.name) && (this.output += out.name + ' : ');
        this.output += this.getInputType(out) + ' >';
    } else {
        this.output += 'Observable<{ ';
        for (i = 0; i < outputs.length; i++) {
            out = outputs[i];
            (out.name) && (this.output += out.name + ' : ');
            this.output += this.getInputType(out);
            i + 1 < outputs.length && (this.output += ', ');
        }
        this.output += ' }>';
    }
{'fraction_non_alphanumeric': 0.14766185233814766, 'fraction_numerical': 0.002221997778002222, 'mean_word_length': 2.6646928201332347, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5165742', 'n_tokens_mistral': 3036, 'n_tokens_neox': 2932, 'n_words': 611}