{"size": 908, "ext": "js", "max_stars_repo_path": "src/services/chainz.js", "max_stars_repo_name": "kkrizzz/crypto-balances", "max_stars_repo_stars_event_min_datetime": "2018-01-31T04:51:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T09:35:30.000Z", "max_issues_repo_path": "src/services/chainz.js", "max_issues_repo_name": "kkrizzz/crypto-balances", "max_issues_repo_issues_event_min_datetime": "2018-03-09T21:17:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-06T22:48:41.000Z", "max_forks_repo_path": "src/services/chainz.js", "max_forks_repo_name": "kkrizzz/crypto-balances", "max_forks_repo_forks_event_min_datetime": "2018-01-31T04:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-07T03:57:35.000Z"}
{"max_stars_count": 27, "max_issues_count": 3, "max_forks_count": 11, "avg_line_length": 25.9428571429, "max_line_length": 107, "alphanum_fraction": 0.5055066079}
const Bluebird = require("bluebird");
const req = Bluebird.promisify(require("request"));

module.exports = {
    supported_address: [ "LTC", "STRAT", "DGB" ],

    check(addr) {
        return RegExp('^[SMD][a-km-zA-HJ-NP-Z0-9]{26,33}$').test(addr);
    },

    symbol(addr) {
        return ({
            M: "LTC",
            S: "STRAT",
            D: "DGB",
        })[addr[0]];
    },

    fetch(addr) {
        const network = this.symbol(addr);

        const url = `https://chainz.cryptoid.info/${network.toLowerCase()}/api.dws?q=getbalance&a=${addr}`;

        return req(url)
        .timeout(5000)
        .cancellable()
        .spread(function(resp, body) {
            if (resp.statusCode < 200 || resp.statusCode >= 300) throw new Error(JSON.stringify(resp));
            return {
                quantity: parseFloat(body),
                asset: network
            };
        });
    }
};