<commit_before>import 'isomorphic-fetch';

const baseHeaders = {
    'Content-Type': 'application/json',
};

const emeraldMethods = [
    "eth_sendTransaction",
    "eth_accounts"
];

export class RpcApi {
    constructor(urlEmerald, urlGeth) {
        this.requestSeq = 1;
        this.urlEmerald = urlEmerald || 'http://localhost:1920';
        this.urlGeth = urlGeth || 'http://localhost:8545';
    }

    static routeToEmerald(method) {
        if (method.startsWith('emerald_') || method.startsWith('personal_') || method.startsWith('backend_')) {
            return true
        }
        return emeraldMethods.indexOf(method) >= 0
    }

    /**
    * This call analyses JSON RPC response.
    * It returns promise which resolves whether 'result' field found
    * or reject in case 'error' field found.
    *
    * @returns {Promise}
    */
    call(name, params, headers) {
        return new Promise((resolve, reject) => {
            this.jsonPost(name, params, headers).then((json) => {
                // eth_syncing will return {.. "result": false}
                if (json.result || json.result === false) {
                    resolve(json.result);
                } else if (json.error) {
                    reject(json.error);
                } else {
                    reject(new Error(`Unknown JSON RPC response: ${JSON.stringify(json)},
                     name: ${name},
                     params: ${JSON.stringify(params)}`));
                }
            }).catch((error) => reject(error));
        });
    }

    jsonPost(name, params, headers) {
        const data = {
            jsonrpc: '2.0',
            method: name,
            params,
            id: this.requestSeq++,
        };
        const url = RpcApi.routeToEmerald(name) ? this.urlEmerald : this.urlGeth;
        return fetch(url, {
            method: 'POST',
            headers: Object.assign(baseHeaders, headers),
            body: JSON.stringify(data),
        }).then((response) => response.json());
    }
}


export default RpcApi;
<commit_msg>rpcapi: problem: emerald method receives undefined call<commit_after>import 'isomorphic-fetch';

const baseHeaders = {
    'Content-Type': 'application/json',
};

const emeraldMethods = [
    "eth_sendTransaction",
    "eth_accounts"
];

export class RpcApi {
    constructor(urlEmerald, urlGeth) {
        this.requestSeq = 1;
        this.urlEmerald = urlEmerald || 'http://localhost:1920';
        this.urlGeth = urlGeth || 'http://localhost:8545';
    }

    static routeToEmerald(method) {
        if (typeof method !== 'string') {
            return false;
        }
        if (method.startsWith('emerald_') || method.startsWith('personal_') || method.startsWith('backend_')) {
            return true;
        }
        return emeraldMethods.indexOf(method) >= 0;
    }

    /**
    * This call analyses JSON RPC response.
    * It returns promise which resolves whether 'result' field found
    * or reject in case 'error' field found.
    *
    * @returns {Promise}
    */
    call(name, params, headers) {
        return new Promise((resolve, reject) => {
            if (typeof name !== 'string') {
                reject(new Error(`RPC call method must be a string, got:
                    method: ${name},
                    params: ${JSON.stringify(params)},
                    headers: ${JSON.stringify(headers)}`));
            }
            this.jsonPost(name, params, headers).then((json) => {
                // eth_syncing will return {.. "result": false}
                if (json.result || json.result === false) {
                    resolve(json.result);
                } else if (json.error) {
                    reject(json.error);
                } else {
                    reject(new Error(`Unknown JSON RPC response: ${JSON.stringify(json)},
                     name: ${name},
                     params: ${JSON.stringify(params)}`));
                }
            }).catch((error) => reject(error));
        });
    }

    jsonPost(name, params, headers) {
        const data = {
            jsonrpc: '2.0',
            method: name,
            params,
            id: this.requestSeq++,
        };
        const url = RpcApi.routeToEmerald(name) ? this.urlEmerald : this.urlGeth;
        return fetch(url, {
            method: 'POST',
            headers: Object.assign(baseHeaders, headers),
            body: JSON.stringify(data),
        }).then((response) => response.json());
    }
}


export default RpcApi;

{'fraction_non_alphanumeric': 0.1344575105391613, 'fraction_numerical': 0.005325049922343022, 'mean_word_length': 1.8387909319899245, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, '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': '3780550', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1230, 'n_words': 283}