Search in sources :

Example 1 with Generator

use of org.xel.Generator in project elastic-core-maven by OrdinaryDude.

the class GetForging method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String secretPhrase = ParameterParser.getSecretPhrase(req, false);
    int elapsedTime = Nxt.getEpochTime() - Nxt.getBlockchain().getLastBlock().getTimestamp();
    if (secretPhrase != null) {
        Account account = Account.getAccount(Crypto.getPublicKey(secretPhrase));
        if (account == null) {
            return UNKNOWN_ACCOUNT;
        }
        Generator generator = Generator.getGenerator(secretPhrase);
        if (generator == null) {
            return NOT_FORGING;
        }
        return JSONData.generator(generator, elapsedTime);
    } else {
        API.verifyPassword(req);
        JSONObject response = new JSONObject();
        JSONArray generators = new JSONArray();
        Generator.getSortedForgers().forEach(generator -> generators.add(JSONData.generator(generator, elapsedTime)));
        response.put("generators", generators);
        return response;
    }
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) Generator(org.xel.Generator)

Example 2 with Generator

use of org.xel.Generator in project elastic-core-maven by OrdinaryDude.

the class GetNextBlockGeneratorsTemp method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    JSONObject response = new JSONObject();
    int limit = Math.max(1, ParameterParser.getInt(req, "limit", 1, Integer.MAX_VALUE, false));
    Blockchain blockchain = Nxt.getBlockchain();
    blockchain.readLock();
    try {
        Block lastBlock = blockchain.getLastBlock();
        response.put("timestamp", lastBlock.getTimestamp());
        response.put("height", lastBlock.getHeight());
        response.put("lastBlock", Long.toUnsignedString(lastBlock.getId()));
        List<Generator.ActiveGenerator> activeGenerators = Generator.getNextGenerators();
        response.put("activeCount", activeGenerators.size());
        JSONArray generators = new JSONArray();
        for (Generator.ActiveGenerator generator : activeGenerators) {
            if (generator.getHitTime() > Integer.MAX_VALUE) {
                break;
            }
            JSONObject resp = new JSONObject();
            JSONData.putAccount(resp, "account", generator.getAccountId());
            resp.put("effectiveBalanceNXT", generator.getEffectiveBalance());
            resp.put("hitTime", generator.getHitTime());
            resp.put("deadline", (int) generator.getHitTime() - lastBlock.getTimestamp());
            generators.add(resp);
            if (generators.size() == limit) {
                break;
            }
        }
        response.put("generators", generators);
    } finally {
        blockchain.readUnlock();
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) Blockchain(org.xel.Blockchain) JSONArray(org.json.simple.JSONArray) Block(org.xel.Block) Generator(org.xel.Generator)

Example 3 with Generator

use of org.xel.Generator in project elastic-core-maven by OrdinaryDude.

the class StopForging method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String secretPhrase = ParameterParser.getSecretPhrase(req, false);
    JSONObject response = new JSONObject();
    if (secretPhrase != null) {
        Generator generator = Generator.stopForging(secretPhrase);
        response.put("foundAndStopped", generator != null);
        response.put("forgersCount", Generator.getGeneratorCount());
    } else {
        API.verifyPassword(req);
        int count = Generator.stopForging();
        response.put("stopped", count);
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) Generator(org.xel.Generator)

Example 4 with Generator

use of org.xel.Generator in project elastic-core-maven by OrdinaryDude.

the class DesktopSystemTray method displayStatus.

private void displayStatus() {
    Block lastBlock = Nxt.getBlockchain().getLastBlock();
    Collection<Generator> allGenerators = Generator.getAllGenerators();
    StringBuilder generators = new StringBuilder();
    for (Generator generator : allGenerators) {
        generators.append(Convert.rsAccount(generator.getAccountId())).append(' ');
    }
    Object optionPaneBackground = UIManager.get("OptionPane.background");
    UIManager.put("OptionPane.background", Color.WHITE);
    Object panelBackground = UIManager.get("Panel.background");
    UIManager.put("Panel.background", Color.WHITE);
    Object textFieldBackground = UIManager.get("TextField.background");
    UIManager.put("TextField.background", Color.WHITE);
    Container statusPanelParent = null;
    if (statusDialog != null && statusPanel != null) {
        statusPanelParent = statusPanel.getParent();
        statusPanelParent.remove(statusPanel);
    }
    statusPanel = new JPanel();
    statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.Y_AXIS));
    addLabelRow(statusPanel, "Installation");
    addDataRow(statusPanel, "Application", Nxt.APPLICATION);
    addDataRow(statusPanel, "Version", Nxt.VERSION);
    addDataRow(statusPanel, "Network", (Constants.isTestnet) ? "TestNet" : "MainNet");
    addDataRow(statusPanel, "Working offline", "" + Constants.isOffline);
    addDataRow(statusPanel, "Wallet", String.valueOf(API.getWelcomePageUri()));
    addDataRow(statusPanel, "Peer port", String.valueOf(Peers.getDefaultPeerPort()));
    addDataRow(statusPanel, "Program folder", String.valueOf(Paths.get(".").toAbsolutePath().getParent()));
    addDataRow(statusPanel, "User folder", String.valueOf(Paths.get(Nxt.getUserHomeDir()).toAbsolutePath()));
    addDataRow(statusPanel, "Database URL", Db.db == null ? "unavailable" : Db.db.getUrl());
    addEmptyRow(statusPanel);
    if (lastBlock != null) {
        addLabelRow(statusPanel, "Last Block");
        addDataRow(statusPanel, "Height", String.valueOf(lastBlock.getHeight()));
        addDataRow(statusPanel, "Timestamp", String.valueOf(lastBlock.getTimestamp()));
        addDataRow(statusPanel, "Time", String.valueOf(new Date(Convert.fromEpochTime(lastBlock.getTimestamp()))));
        addDataRow(statusPanel, "Seconds passed", String.valueOf(Nxt.getEpochTime() - lastBlock.getTimestamp()));
        addDataRow(statusPanel, "Forging", String.valueOf(allGenerators.size() > 0));
        if (allGenerators.size() > 0) {
            addDataRow(statusPanel, "Forging accounts", generators.toString());
        }
    }
    addEmptyRow(statusPanel);
    addLabelRow(statusPanel, "Environment");
    addDataRow(statusPanel, "Number of peers", String.valueOf(Peers.getAllPeers().size()));
    addDataRow(statusPanel, "Available processors", String.valueOf(Runtime.getRuntime().availableProcessors()));
    addDataRow(statusPanel, "Max memory", humanReadableByteCount(Runtime.getRuntime().maxMemory()));
    addDataRow(statusPanel, "Total memory", humanReadableByteCount(Runtime.getRuntime().totalMemory()));
    addDataRow(statusPanel, "Free memory", humanReadableByteCount(Runtime.getRuntime().freeMemory()));
    addDataRow(statusPanel, "Process id", Nxt.getProcessId());
    addEmptyRow(statusPanel);
    addDataRow(statusPanel, "Updated", dateFormat.format(new Date()));
    if (statusDialog == null || !statusDialog.isVisible()) {
        JOptionPane pane = new JOptionPane(statusPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, imageIcon);
        statusDialog = pane.createDialog(wrapper, "XEL Server Status");
        statusDialog.setVisible(true);
        statusDialog.dispose();
    } else {
        if (statusPanelParent != null) {
            statusPanelParent.add(statusPanel);
            statusPanelParent.revalidate();
        }
        statusDialog.getContentPane().validate();
        statusDialog.getContentPane().repaint();
        EventQueue.invokeLater(statusDialog::toFront);
    }
    UIManager.put("OptionPane.background", optionPaneBackground);
    UIManager.put("Panel.background", panelBackground);
    UIManager.put("TextField.background", textFieldBackground);
}
Also used : Block(org.xel.Block) Date(java.util.Date) Generator(org.xel.Generator)

Example 5 with Generator

use of org.xel.Generator in project elastic-core-maven by OrdinaryDude.

the class StartForging method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String secretPhrase = ParameterParser.getSecretPhrase(req, true);
    Generator generator = Generator.startForging(secretPhrase);
    JSONObject response = new JSONObject();
    response.put("deadline", generator.getDeadline());
    response.put("hitTime", generator.getHitTime());
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) Generator(org.xel.Generator)

Aggregations

Generator (org.xel.Generator)5 JSONObject (org.json.simple.JSONObject)4 JSONArray (org.json.simple.JSONArray)2 Block (org.xel.Block)2 Date (java.util.Date)1 Account (org.xel.Account)1 Blockchain (org.xel.Blockchain)1