<commit_before>package org.ethereumclassic.etherjar.contract;

import org.bouncycastle.jcajce.provider.digest.Keccak;
import org.ethereumclassic.etherjar.model.Hex32;
import org.ethereumclassic.etherjar.model.HexData;
import org.ethereumclassic.etherjar.model.MethodId;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.regex.Pattern;

/**
 * The first four bytes of the call data for a function call specifies the function to be called. It is the
 * first (left, high-order in big-endian) four bytes of the Keccak (SHA-3) hash of the signature of the function. The
 * signature is defined as the canonical expression of the basic prototype, i.e. the function name with the
 * parenthesised list of parameter types. Parameter types are split by a single comma - no spaces are used.
 *
 * <p><b>Example:</b> <code>baz(uint32,bool)</code> with arguments <tt>(69, true)</tt> becomes
 * <tt>0xcdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001</tt>
 *
 * @author <NAME>
 * @see <a href="https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI">Ethereum Contract ABI</a>
 */
public class ContractMethod {

    private MethodId id;

    private ContractMethod(MethodId id) {
        this.id = id;
    }

    /**
     * @return function id
     */
    public MethodId getId() {
        return id;
    }

    /**
     * Encodes call data to send through RPC
     *
     * @param params parameters of the call
     * @return encoded call
     */
    public HexData encodeCall(Hex32... params) {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        try {
            buf.write(id.getBytes());
            for (Hex32 param: params) {
                buf.write(param.getBytes());
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return new HexData(buf.toByteArray());
    }

    static class Builder {

        final static Pattern SIGNATURE_PATTERN =
                Pattern.compile("\\p{Alpha}+\\d*\\(((\\p{Alnum}*)|([\\[\\]])|((?<!,),(?!\\))))*\\)");

        /**
         * Check contract method signature
         *
         * @param signature a method name
         * @return boolean
         */
        static boolean isSignatureValid(String signature) {
            return SIGNATURE_PATTERN.matcher(signature).matches();
        }
<commit_msg>Minor fix. Contract's method validation regexp.<commit_after>package org.ethereumclassic.etherjar.contract;

import org.bouncycastle.jcajce.provider.digest.Keccak;
import org.ethereumclassic.etherjar.model.Hex32;
import org.ethereumclassic.etherjar.model.HexData;
import org.ethereumclassic.etherjar.model.MethodId;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.regex.Pattern;

/**
 * The first four bytes of the call data for a function call specifies the function to be called. It is the
 * first (left, high-order in big-endian) four bytes of the Keccak (SHA-3) hash of the signature of the function. The
 * signature is defined as the canonical expression of the basic prototype, i.e. the function name with the
 * parenthesised list of parameter types. Parameter types are split by a single comma - no spaces are used.
 *
 * <p><b>Example:</b> <code>baz(uint32,bool)</code> with arguments <tt>(69, true)</tt> becomes
 * <tt>0xcdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001</tt>
 *
 * @author <NAME>
 * @see <a href="https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI">Ethereum Contract ABI</a>
 */
public class ContractMethod {

    private MethodId id;

    private ContractMethod(MethodId id) {
        this.id = id;
    }

    /**
     * @return function id
     */
    public MethodId getId() {
        return id;
    }

    /**
     * Encodes call data to send through RPC
     *
     * @param params parameters of the call
     * @return encoded call
     */
    public HexData encodeCall(Hex32... params) {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        try {
            buf.write(id.getBytes());
            for (Hex32 param: params) {
                buf.write(param.getBytes());
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return new HexData(buf.toByteArray());
    }

    static class Builder {

        final static Pattern SIGNATURE_PATTERN =
                Pattern.compile("\\p{Alpha}+\\d*\\((\\w*|\\[|\\]|((?<!,),(?!\\))))*\\)");

        /**
         * Check contract method signature
         *
         * @param signature a method name
         * @return boolean
         */
        static boolean isSignatureValid(String signature) {
            return SIGNATURE_PATTERN.matcher(signature).matches();
        }

{'fraction_non_alphanumeric': 0.11468076453843025, 'fraction_numerical': 0.05815372102480683, 'mean_word_length': 2.7896764252696458, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '5218910', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1364, 'n_words': 379}