<commit_before>package foundation.omni.consensus

import foundation.omni.PropertyType
import foundation.omni.rpc.BalanceEntry
import foundation.omni.rpc.ConsensusSnapshot
import foundation.omni.rpc.SmartPropertyListInfo
import groovy.json.JsonSlurper
import foundation.omni.CurrencyID
import groovy.transform.TypeChecked
import groovy.util.logging.Slf4j
import org.bitcoinj.core.Address

/**
 * Command-line tool and class for fetching OmniExplorer (formerly OmniChest) consensus data
 */
@Slf4j
class ChestConsensusTool implements ConsensusTool {
    static URI ChestHost_Live = new URI("https://api.omniexplorer.info");
    private final String proto
    private final String host
    private final int port
    static String file = "/ask.aspx?api=getpropertybalances"
    static String listFile = "/v1/properties/list"
    static String revisionFile = "/v1/system/revision.json"

    static final Map apiExtraHeaders = ['User-Agent': 'OmniJ/ChestConsensusTool']
    static final Map apiParameters = [requestProperties: apiExtraHeaders]

    ChestConsensusTool(URI chestURI) {
        proto = chestURI.scheme
        port = chestURI.port
        host = chestURI.host
    }

    public static void main(String[] args) {
        ChestConsensusTool tool = new ChestConsensusTool(ChestHost_Live)
        tool.run(args.toList())
    }

    private SortedMap<Address, BalanceEntry> getConsensusForCurrency(CurrencyID currencyID) {
        def balances = new JsonSlurper().parse(consensusURL(currencyID), apiParameters)

        TreeMap<Address, BalanceEntry> map = [:]
        balances.each { item ->

            Address address = new Address(null, item.address)
            BalanceEntry entry = itemToEntry(item)

            if (address != "" && (entry.balance.numberValue() > 0 || entry.reserved.numberValue() > 0)) {
                map.put(address, entry)
            }
        }
        return map;
    }

    private BalanceEntry itemToEntry(Object item) {
        BigDecimal balance = jsonToBigDecimal(item.balance)
        BigDecimal reserved = jsonToBigDecimal(item.reserved)

        def propertyType = ((String) item.balance).contains('.') ? PropertyType.DIVISIBLE : PropertyType.INDIVISIBLE

        if (propertyType == PropertyType.DIVISIBLE) {
            return new BalanceEntry(balance.divisible, reserved.divisible)
        } else {

            return new BalanceEntry(balance.indivisible, reserved.indivisible)
        }
    }

    /* We're expecting input type String here */
    private BigDecimal jsonToBigDecimal(String balanceIn) {
        BigDecimal balanceOut = new BigDecimal(balanceIn).setScale(8)
        return balanceOut
    }

    @Override
    Integer currentBlockHeight() {
        def revisionURL = new URL(proto, host, port, revisionFile)<commit_msg>Add a value for “frozen” to BalanceEntry constructor in ChestConsensusTool<commit_after>package foundation.omni.consensus

import foundation.omni.PropertyType
import foundation.omni.rpc.BalanceEntry
import foundation.omni.rpc.ConsensusSnapshot
import foundation.omni.rpc.SmartPropertyListInfo
import groovy.json.JsonSlurper
import foundation.omni.CurrencyID
import groovy.transform.TypeChecked
import groovy.util.logging.Slf4j
import org.bitcoinj.core.Address

/**
 * Command-line tool and class for fetching OmniExplorer (formerly OmniChest) consensus data
 */
@Slf4j
class ChestConsensusTool implements ConsensusTool {
    static URI ChestHost_Live = new URI("https://api.omniexplorer.info");
    private final String proto
    private final String host
    private final int port
    static String file = "/ask.aspx?api=getpropertybalances"
    static String listFile = "/v1/properties/list"
    static String revisionFile = "/v1/system/revision.json"

    static final Map apiExtraHeaders = ['User-Agent': 'OmniJ/ChestConsensusTool']
    static final Map apiParameters = [requestProperties: apiExtraHeaders]

    ChestConsensusTool(URI chestURI) {
        proto = chestURI.scheme
        port = chestURI.port
        host = chestURI.host
    }

    public static void main(String[] args) {
        ChestConsensusTool tool = new ChestConsensusTool(ChestHost_Live)
        tool.run(args.toList())
    }

    private SortedMap<Address, BalanceEntry> getConsensusForCurrency(CurrencyID currencyID) {
        def balances = new JsonSlurper().parse(consensusURL(currencyID), apiParameters)

        TreeMap<Address, BalanceEntry> map = [:]
        balances.each { item ->

            Address address = new Address(null, item.address)
            BalanceEntry entry = itemToEntry(item)

            if (address != "" && (entry.balance.numberValue() > 0 || entry.reserved.numberValue() > 0)) {
                map.put(address, entry)
            }
        }
        return map;
    }

    private BalanceEntry itemToEntry(Object item) {
        BigDecimal balance = jsonToBigDecimal(item.balance)
        BigDecimal reserved = jsonToBigDecimal(item.reserved)

        def propertyType = ((String) item.balance).contains('.') ? PropertyType.DIVISIBLE : PropertyType.INDIVISIBLE

        // TODO: Don't hardcode "frozen" to 0 (and add to tests)
        if (propertyType == PropertyType.DIVISIBLE) {
            return new BalanceEntry(balance.divisible, reserved.divisible, 0.divisible)
        } else {

            return new BalanceEntry(balance.indivisible, reserved.indivisible, 0.indivisible)
        }
    }

    /* We're expecting input type String here */
    private BigDecimal jsonToBigDecimal(String balanceIn) {
        BigDecimal balanceOut = new BigDecimal(balanceIn).setScale(8)
        return balanceOut
    }

    @Override
    Integer currentBlockHeight() {
        def revisionURL = new URL(proto, host, port, revisionFile)
{'fraction_non_alphanumeric': 0.08843061866480252, 'fraction_numerical': 0.0029709891646277527, 'mean_word_length': 3.2677106636838182, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '6101401', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1561, 'n_words': 384}