Search in sources :

Example 11 with Account

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

the class GetGuaranteedBalance method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getAccount(req);
    int numberOfConfirmations = ParameterParser.getNumberOfConfirmations(req);
    JSONObject response = new JSONObject();
    if (account == null) {
        response.put("guaranteedBalanceNQT", "0");
    } else {
        response.put("guaranteedBalanceNQT", String.valueOf(account.getGuaranteedBalanceNQT(numberOfConfirmations, Nxt.getBlockchain().getHeight())));
    }
    return response;
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject)

Example 12 with Account

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

the class SendMoney method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long recipient = ParameterParser.getAccountId(req, "recipient", true);
    long amountNQT = ParameterParser.getAmountNQT(req);
    Account account = ParameterParser.getSenderAccount(req);
    return createTransaction(req, account, recipient, amountNQT);
}
Also used : Account(org.xel.Account)

Example 13 with Account

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

the class UnlockAccount method processRequest.

@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {
    String secretPhrase = req.getParameter("secretPhrase");
    // lock all other instances of this account being unlocked
    Users.getAllUsers().forEach(u -> {
        if (secretPhrase.equals(u.getSecretPhrase())) {
            u.lockAccount();
            if (!u.isInactive()) {
                u.enqueue(LOCK_ACCOUNT);
            }
        }
    });
    long accountId = user.unlockAccount(secretPhrase);
    JSONObject response = new JSONObject();
    response.put("response", "unlockAccount");
    response.put("account", Long.toUnsignedString(accountId));
    if (secretPhrase.length() < 30) {
        response.put("secretPhraseStrength", 1);
    } else {
        response.put("secretPhraseStrength", 5);
    }
    Account account = Account.getAccount(accountId);
    if (account == null) {
        response.put("balanceNQT", 0);
    } else {
        response.put("balanceNQT", account.getUnconfirmedBalanceNQT());
        JSONArray myTransactions = new JSONArray();
        byte[] accountPublicKey = Account.getPublicKey(accountId);
        try (DbIterator<? extends Transaction> transactions = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions()) {
            while (transactions.hasNext()) {
                Transaction transaction = transactions.next();
                if (Arrays.equals(transaction.getSenderPublicKey(), accountPublicKey)) {
                    JSONObject myTransaction = new JSONObject();
                    myTransaction.put("index", Users.getIndex(transaction));
                    myTransaction.put("transactionTimestamp", transaction.getTimestamp());
                    myTransaction.put("deadline", transaction.getDeadline());
                    myTransaction.put("account", Long.toUnsignedString(transaction.getRecipientId()));
                    myTransaction.put("sentAmountNQT", transaction.getAmountNQT());
                    if (accountId == transaction.getRecipientId()) {
                        myTransaction.put("receivedAmountNQT", transaction.getAmountNQT());
                    }
                    myTransaction.put("feeNQT", transaction.getFeeNQT());
                    myTransaction.put("numberOfConfirmations", -1);
                    myTransaction.put("id", transaction.getStringId());
                    myTransactions.add(myTransaction);
                } else if (accountId == transaction.getRecipientId()) {
                    JSONObject myTransaction = new JSONObject();
                    myTransaction.put("index", Users.getIndex(transaction));
                    myTransaction.put("transactionTimestamp", transaction.getTimestamp());
                    myTransaction.put("deadline", transaction.getDeadline());
                    myTransaction.put("account", Long.toUnsignedString(transaction.getSenderId()));
                    myTransaction.put("receivedAmountNQT", transaction.getAmountNQT());
                    myTransaction.put("feeNQT", transaction.getFeeNQT());
                    myTransaction.put("numberOfConfirmations", -1);
                    myTransaction.put("id", transaction.getStringId());
                    myTransactions.add(myTransaction);
                }
            }
        }
        SortedSet<JSONObject> myTransactionsSet = new TreeSet<>(myTransactionsComparator);
        int blockchainHeight = Nxt.getBlockchain().getLastBlock().getHeight();
        try (DbIterator<? extends Block> blockIterator = Nxt.getBlockchain().getBlocks(accountId, 0)) {
            while (blockIterator.hasNext()) {
                Block block = blockIterator.next();
                if (block.getTotalFeeNQT() > 0) {
                    JSONObject myTransaction = new JSONObject();
                    myTransaction.put("index", "block" + Users.getIndex(block));
                    myTransaction.put("blockTimestamp", block.getTimestamp());
                    myTransaction.put("block", block.getStringId());
                    myTransaction.put("earnedAmountNQT", block.getTotalFeeNQT());
                    myTransaction.put("numberOfConfirmations", blockchainHeight - block.getHeight());
                    myTransaction.put("id", "-");
                    myTransaction.put("timestamp", block.getTimestamp());
                    myTransactionsSet.add(myTransaction);
                }
            }
        }
        try (DbIterator<? extends Transaction> transactionIterator = Nxt.getBlockchain().getTransactions(accountId, (byte) -1, (byte) -1, 0, false)) {
            while (transactionIterator.hasNext()) {
                Transaction transaction = transactionIterator.next();
                if (transaction.getSenderId() == accountId) {
                    JSONObject myTransaction = new JSONObject();
                    myTransaction.put("index", Users.getIndex(transaction));
                    myTransaction.put("blockTimestamp", transaction.getBlockTimestamp());
                    myTransaction.put("transactionTimestamp", transaction.getTimestamp());
                    myTransaction.put("account", Long.toUnsignedString(transaction.getRecipientId()));
                    myTransaction.put("sentAmountNQT", transaction.getAmountNQT());
                    if (accountId == transaction.getRecipientId()) {
                        myTransaction.put("receivedAmountNQT", transaction.getAmountNQT());
                    }
                    myTransaction.put("feeNQT", transaction.getFeeNQT());
                    myTransaction.put("numberOfConfirmations", blockchainHeight - transaction.getHeight());
                    myTransaction.put("id", transaction.getStringId());
                    myTransaction.put("timestamp", transaction.getTimestamp());
                    myTransactionsSet.add(myTransaction);
                } else if (transaction.getRecipientId() == accountId) {
                    JSONObject myTransaction = new JSONObject();
                    myTransaction.put("index", Users.getIndex(transaction));
                    myTransaction.put("blockTimestamp", transaction.getBlockTimestamp());
                    myTransaction.put("transactionTimestamp", transaction.getTimestamp());
                    myTransaction.put("account", Long.toUnsignedString(transaction.getSenderId()));
                    myTransaction.put("receivedAmountNQT", transaction.getAmountNQT());
                    myTransaction.put("feeNQT", transaction.getFeeNQT());
                    myTransaction.put("numberOfConfirmations", blockchainHeight - transaction.getHeight());
                    myTransaction.put("id", transaction.getStringId());
                    myTransaction.put("timestamp", transaction.getTimestamp());
                    myTransactionsSet.add(myTransaction);
                }
            }
        }
        Iterator<JSONObject> iterator = myTransactionsSet.iterator();
        while (myTransactions.size() < 1000 && iterator.hasNext()) {
            myTransactions.add(iterator.next());
        }
        if (myTransactions.size() > 0) {
            JSONObject response2 = new JSONObject();
            response2.put("response", "processNewData");
            response2.put("addedMyTransactions", myTransactions);
            user.enqueue(response2);
        }
    }
    return response;
}
Also used : Account(org.xel.Account) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Transaction(org.xel.Transaction) TreeSet(java.util.TreeSet) Block(org.xel.Block)

Example 14 with Account

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

the class UploadTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getSenderAccount(req);
    Attachment.TaggedDataUpload taggedDataUpload = ParameterParser.getTaggedData(req);
    return createTransaction(req, account, taggedDataUpload);
}
Also used : Account(org.xel.Account) Attachment(org.xel.Attachment)

Example 15 with Account

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

the class ParameterParser method getAccount.

public static Account getAccount(HttpServletRequest req, boolean isMandatory) throws ParameterException {
    long accountId = getAccountId(req, "account", isMandatory);
    if (accountId == 0 && !isMandatory) {
        return null;
    }
    Account account = Account.getAccount(accountId);
    if (account == null) {
        throw new ParameterException(JSONResponses.unknownAccount(accountId));
    }
    return account;
}
Also used : Account(org.xel.Account)

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