Search in sources :

Example 6 with Account

use of org.xel.Account 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 7 with Account

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

the class ExtendTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getSenderAccount(req);
    long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
    TaggedData taggedData = TaggedData.getData(transactionId);
    if (taggedData == null) {
        Transaction transaction = Nxt.getBlockchain().getTransaction(transactionId);
        if (transaction == null || transaction.getType() != TransactionType.Data.TAGGED_DATA_UPLOAD) {
            return UNKNOWN_TRANSACTION;
        }
        Attachment.TaggedDataUpload taggedDataUpload = ParameterParser.getTaggedData(req);
        taggedData = new TaggedData(transaction, taggedDataUpload);
    }
    Attachment.TaggedDataExtend taggedDataExtend = new Attachment.TaggedDataExtend(taggedData);
    return createTransaction(req, account, taggedDataExtend);
}
Also used : Account(org.xel.Account) Transaction(org.xel.Transaction) Attachment(org.xel.Attachment) TaggedData(org.xel.TaggedData)

Example 8 with Account

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

the class GetAccountLessors method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getAccount(req);
    int height = ParameterParser.getHeight(req);
    if (height < 0) {
        height = Nxt.getBlockchain().getHeight();
    }
    JSONObject response = new JSONObject();
    JSONData.putAccount(response, "account", account.getId());
    response.put("height", height);
    JSONArray lessorsJSON = new JSONArray();
    try (DbIterator<Account> lessors = account.getLessors(height)) {
        if (lessors.hasNext()) {
            while (lessors.hasNext()) {
                Account lessor = lessors.next();
                JSONObject lessorJSON = new JSONObject();
                JSONData.putAccount(lessorJSON, "lessor", lessor.getId());
                lessorJSON.put("guaranteedBalanceNQT", String.valueOf(lessor.getGuaranteedBalanceNQT(Constants.GUARANTEED_BALANCE_CONFIRMATIONS, height)));
                lessorsJSON.add(lessorJSON);
            }
        }
    }
    response.put("lessors", lessorsJSON);
    return response;
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 9 with Account

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

the class PeerImpl method getWeight.

@Override
public int getWeight() {
    if (hallmark == null) {
        return 0;
    }
    if (hallmarkBalance == -1 || hallmarkBalanceHeight < Nxt.getBlockchain().getHeight() - 60) {
        long accountId = hallmark.getAccountId();
        Account account = Account.getAccount(accountId);
        hallmarkBalance = account == null ? 0 : account.getBalanceNQT();
        hallmarkBalanceHeight = Nxt.getBlockchain().getHeight();
    }
    return (int) (adjustedWeight * (hallmarkBalance / Constants.ONE_NXT) / Constants.MAX_BALANCE_NXT);
}
Also used : Account(org.xel.Account)

Example 10 with Account

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

the class SendMoney method processRequest.

@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws NxtException.ValidationException, IOException {
    if (user.getSecretPhrase() == null) {
        return null;
    }
    String recipientValue = req.getParameter("recipient");
    String amountValue = req.getParameter("amountNXT");
    String feeValue = req.getParameter("feeNXT");
    String deadlineValue = req.getParameter("deadline");
    String secretPhrase = req.getParameter("secretPhrase");
    long recipient;
    long amountNQT = 0;
    long feeNQT = 0;
    short deadline = 0;
    try {
        recipient = Convert.parseUnsignedLong(recipientValue);
        if (recipient == 0)
            throw new IllegalArgumentException("invalid recipient");
        amountNQT = Convert.parseNXT(amountValue.trim());
        feeNQT = Convert.parseNXT(feeValue.trim());
        deadline = (short) (Double.parseDouble(deadlineValue) * 60);
    } catch (RuntimeException e) {
        JSONObject response = new JSONObject();
        response.put("response", "notifyOfIncorrectTransaction");
        response.put("message", "One of the fields is filled incorrectly!");
        response.put("recipient", recipientValue);
        response.put("amountNXT", amountValue);
        response.put("feeNXT", feeValue);
        response.put("deadline", deadlineValue);
        return response;
    }
    if (!user.getSecretPhrase().equals(secretPhrase)) {
        JSONObject response = new JSONObject();
        response.put("response", "notifyOfIncorrectTransaction");
        response.put("message", "Wrong secret phrase!");
        response.put("recipient", recipientValue);
        response.put("amountNXT", amountValue);
        response.put("feeNXT", feeValue);
        response.put("deadline", deadlineValue);
        return response;
    } else if (amountNQT <= 0 || amountNQT > Constants.MAX_BALANCE_NQT) {
        JSONObject response = new JSONObject();
        response.put("response", "notifyOfIncorrectTransaction");
        response.put("message", "\"Amount\" must be greater than 0!");
        response.put("recipient", recipientValue);
        response.put("amountNXT", amountValue);
        response.put("feeNXT", feeValue);
        response.put("deadline", deadlineValue);
        return response;
    } else if (feeNQT < Constants.ONE_NXT || feeNQT > Constants.MAX_BALANCE_NQT) {
        JSONObject response = new JSONObject();
        response.put("response", "notifyOfIncorrectTransaction");
        response.put("message", "\"Fee\" must be at least 1 XEL!");
        response.put("recipient", recipientValue);
        response.put("amountNXT", amountValue);
        response.put("feeNXT", feeValue);
        response.put("deadline", deadlineValue);
        return response;
    } else if (deadline < 1 || deadline > 1440) {
        JSONObject response = new JSONObject();
        response.put("response", "notifyOfIncorrectTransaction");
        response.put("message", "\"Deadline\" must be greater or equal to 1 minute and less than 24 hours!");
        response.put("recipient", recipientValue);
        response.put("amountNXT", amountValue);
        response.put("feeNXT", feeValue);
        response.put("deadline", deadlineValue);
        return response;
    }
    Account account = Account.getAccount(user.getPublicKey());
    if (account == null || Math.addExact(amountNQT, feeNQT) > account.getUnconfirmedBalanceNQT()) {
        JSONObject response = new JSONObject();
        response.put("response", "notifyOfIncorrectTransaction");
        response.put("message", "Not enough funds!");
        response.put("recipient", recipientValue);
        response.put("amountNXT", amountValue);
        response.put("feeNXT", feeValue);
        response.put("deadline", deadlineValue);
        return response;
    } else {
        final Transaction transaction = Nxt.newTransactionBuilder(user.getPublicKey(), amountNQT, feeNQT, deadline, Attachment.ORDINARY_PAYMENT).recipientId(recipient).build(secretPhrase);
        Nxt.getTransactionProcessor().broadcast(transaction);
        return NOTIFY_OF_ACCEPTED_TRANSACTION;
    }
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction)

Aggregations

Account (org.xel.Account)22 JSONObject (org.json.simple.JSONObject)8 Attachment (org.xel.Attachment)8 JSONArray (org.json.simple.JSONArray)5 Transaction (org.xel.Transaction)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)1 PollBuilder (org.xel.Attachment.MessagingPollCreation.PollBuilder)1 Block (org.xel.Block)1 Generator (org.xel.Generator)1 PhasingParams (org.xel.PhasingParams)1 PhasingPoll (org.xel.PhasingPoll)1 Poll (org.xel.Poll)1 TaggedData (org.xel.TaggedData)1