Java 类org.json.simple.JSONStreamAware 实例源码

项目:burstcoin    文件:User.java   
synchronized void processPendingResponses(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    JSONArray responses = new JSONArray();
    JSONStreamAware pendingResponse;
    while ((pendingResponse = pendingResponses.poll()) != null) {
        responses.add(pendingResponse);
    }
    if (responses.size() > 0) {
        JSONObject combinedResponse = new JSONObject();
        combinedResponse.put("responses", responses);
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
            asyncContext.complete();
            asyncContext = req.startAsync();
            asyncContext.addListener(new UserAsyncListener());
            asyncContext.setTimeout(5000);
        } else {
            resp.setContentType("text/plain; charset=UTF-8");
            try (Writer writer = resp.getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
        }
    } else {
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                JSON.emptyJSON.writeJSONString(writer);
            }
            asyncContext.complete();
        }
        asyncContext = req.startAsync();
        asyncContext.addListener(new UserAsyncListener());
        asyncContext.setTimeout(5000);
    }
}
项目:burstcoin    文件:DGSFeedback.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    DigitalGoodsStore.Purchase purchase = ParameterParser.getPurchase(req);

    Account buyerAccount = ParameterParser.getSenderAccount(req);
    if (buyerAccount.getId() != purchase.getBuyerId()) {
        return INCORRECT_PURCHASE;
    }
    if (purchase.getEncryptedGoods() == null) {
        return GOODS_NOT_DELIVERED;
    }

    Account sellerAccount = Account.getAccount(purchase.getSellerId());
    Attachment attachment = new Attachment.DigitalGoodsFeedback(purchase.getId());
    return createTransaction(req, buyerAccount, sellerAccount.getId(), 0, attachment);
}
项目:burstcoin    文件:ProcessBlock.java   
@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {

    try {

        if (! Nxt.getBlockchain().getLastBlock().getStringId().equals(request.get("previousBlock"))) {
            // do this check first to avoid validation failures of future blocks and transactions
            // when loading blockchain from scratch
            return NOT_ACCEPTED;
        }
        Nxt.getBlockchainProcessor().processPeerBlock(request);
        return ACCEPTED;

    } catch (NxtException|RuntimeException e) {
        if (peer != null) {
            peer.blacklist(e);
        }
        return NOT_ACCEPTED;
    }

}
项目:burstcoin    文件:GetPollIds.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray pollIds = new JSONArray();
    try (DbIterator<Poll> polls = Poll.getAllPolls(firstIndex, lastIndex)) {
        while (polls.hasNext()) {
            pollIds.add(Convert.toUnsignedLong(polls.next().getId()));
        }
    }
    JSONObject response = new JSONObject();
    response.put("pollIds", pollIds);
    return response;

}
项目:burstcoin    文件:GetBlockchainStatus.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    JSONObject response = new JSONObject();
    response.put("application", Nxt.APPLICATION);
    response.put("version", Nxt.VERSION);
    response.put("time", Nxt.getEpochTime());
    Block lastBlock = Nxt.getBlockchain().getLastBlock();
    response.put("lastBlock", lastBlock.getStringId());
    response.put("cumulativeDifficulty", lastBlock.getCumulativeDifficulty().toString());
    response.put("numberOfBlocks", lastBlock.getHeight() + 1);
    BlockchainProcessor blockchainProcessor = Nxt.getBlockchainProcessor();
    Peer lastBlockchainFeeder = blockchainProcessor.getLastBlockchainFeeder();
    response.put("lastBlockchainFeeder", lastBlockchainFeeder == null ? null : lastBlockchainFeeder.getAnnouncedAddress());
    response.put("lastBlockchainFeederHeight", blockchainProcessor.getLastBlockchainFeederHeight());
    response.put("isScanning", blockchainProcessor.isScanning());
    return response;
}
项目:burstcoin    文件:GetAssetsByIssuer.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    List<Account> accounts = ParameterParser.getAccounts(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONObject response = new JSONObject();
    JSONArray accountsJSONArray = new JSONArray();
    response.put("assets", accountsJSONArray);
    for (Account account : accounts) {
        JSONArray assetsJSONArray = new JSONArray();
        try (DbIterator<Asset> assets = Asset.getAssetsIssuedBy(account.getId(), firstIndex, lastIndex)) {
            while (assets.hasNext()) {
                assetsJSONArray.add(JSONData.asset(assets.next()));
            }
        }
        accountsJSONArray.add(assetsJSONArray);
    }
    return response;
}
项目:burstcoin    文件:GetBlocks.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    if (lastIndex < 0 || lastIndex - firstIndex > 99) {
        lastIndex = firstIndex + 99;
    }

    boolean includeTransactions = "true".equalsIgnoreCase(req.getParameter("includeTransactions"));

    JSONArray blocks = new JSONArray();
    try (DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            Block block = iterator.next();
            blocks.add(JSONData.block(block, includeTransactions));
        }
    }

    JSONObject response = new JSONObject();
    response.put("blocks", blocks);

    return response;
}
项目:burstcoin    文件:GetAllAssets.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONObject response = new JSONObject();
    JSONArray assetsJSONArray = new JSONArray();
    response.put("assets", assetsJSONArray);
    try (DbIterator<Asset> assets = Asset.getAllAssets(firstIndex, lastIndex)) {
        while (assets.hasNext()) {
            assetsJSONArray.add(JSONData.asset(assets.next()));
        }
    }
    return response;
}
项目:burstcoin    文件:GetMiningInfo.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    JSONObject response = new JSONObject();

    response.put("height", Long.toString(Nxt.getBlockchain().getHeight() + 1));

    Block lastBlock = Nxt.getBlockchain().getLastBlock();
    byte[] lastGenSig = lastBlock.getGenerationSignature();
    Long lastGenerator = lastBlock.getGeneratorId();

    ByteBuffer buf = ByteBuffer.allocate(32 + 8);
    buf.put(lastGenSig);
    buf.putLong(lastGenerator);

    Shabal256 md = new Shabal256();
    md.update(buf.array());
    byte[] newGenSig = md.digest();

    response.put("generationSignature", Convert.toHexString(newGenSig));
    response.put("baseTarget", Long.toString(lastBlock.getBaseTarget()));

    return response;
}
项目:burstcoin    文件:ParseTransaction.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    String transactionBytes = Convert.emptyToNull(req.getParameter("transactionBytes"));
    String transactionJSON = Convert.emptyToNull(req.getParameter("transactionJSON"));
    Transaction transaction = ParameterParser.parseTransaction(transactionBytes, transactionJSON);
    JSONObject response = JSONData.unconfirmedTransaction(transaction);
    try {
        transaction.validate();
    } catch (NxtException.ValidationException|RuntimeException e) {
        Logger.logDebugMessage(e.getMessage(), e);
        response.put("validate", false);
        response.put("errorCode", 4);
        response.put("errorDescription", "Invalid transaction: " + e.toString());
        response.put("error", e.getMessage());
    }
    response.put("verify", transaction.verifySignature() && transaction.verifyPublicKey());
    return response;
}
项目:burstcoin    文件:GetAssetAccounts.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Asset asset = ParameterParser.getAsset(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    int height = ParameterParser.getHeight(req);

    JSONArray accountAssets = new JSONArray();
    try (DbIterator<Account.AccountAsset> iterator = asset.getAccounts(height, firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            Account.AccountAsset accountAsset = iterator.next();
            accountAssets.add(JSONData.accountAsset(accountAsset));
        }
    }

    JSONObject response = new JSONObject();
    response.put("accountAssets", accountAssets);
    return response;

}
项目:burstcoin    文件:GetAllOpenAskOrders.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    JSONObject response = new JSONObject();
    JSONArray ordersData = new JSONArray();

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    try (DbIterator<Order.Ask> askOrders = Order.Ask.getAll(firstIndex, lastIndex)) {
        while (askOrders.hasNext()) {
            ordersData.add(JSONData.askOrder(askOrders.next()));
        }
    }

    response.put("openOrders", ordersData);
    return response;
}
项目:burstcoin    文件:PlaceAskOrder.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Asset asset = ParameterParser.getAsset(req);
    long priceNQT = ParameterParser.getPriceNQT(req);
    long quantityQNT = ParameterParser.getQuantityQNT(req);
    Account account = ParameterParser.getSenderAccount(req);

    long assetBalance = account.getUnconfirmedAssetBalanceQNT(asset.getId());
    if (assetBalance < 0 || quantityQNT > assetBalance) {
        return NOT_ENOUGH_ASSETS;
    }

    Attachment attachment = new Attachment.ColoredCoinsAskOrderPlacement(asset.getId(), quantityQNT, priceNQT);
    return createTransaction(req, account, attachment);

}
项目:burstcoin    文件:GetAliases.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    final int timestamp = ParameterParser.getTimestamp(req);
    final long accountId = ParameterParser.getAccount(req).getId();
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray aliases = new JSONArray();
    try (FilteringIterator<Alias> aliasIterator = new FilteringIterator<>(Alias.getAliasesByOwner(accountId, 0, -1),
            new FilteringIterator.Filter<Alias>() {
                @Override
                public boolean ok(Alias alias) {
                    return alias.getTimestamp() >= timestamp;
                }
            }, firstIndex, lastIndex)) {
        while(aliasIterator.hasNext()) {
            aliases.add(JSONData.alias(aliasIterator.next()));
        }
    }

    JSONObject response = new JSONObject();
    response.put("aliases", aliases);
    return response;
}
项目:burstcoin    文件:TransferAsset.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long recipient = ParameterParser.getRecipientId(req);

    Asset asset = ParameterParser.getAsset(req);
    long quantityQNT = ParameterParser.getQuantityQNT(req);
    Account account = ParameterParser.getSenderAccount(req);

    long assetBalance = account.getUnconfirmedAssetBalanceQNT(asset.getId());
    if (assetBalance < 0 || quantityQNT > assetBalance) {
        return NOT_ENOUGH_ASSETS;
    }

    Attachment attachment = new Attachment.ColoredCoinsAssetTransfer(asset.getId(), quantityQNT);
    return createTransaction(req, account, recipient, 0, attachment);

}
项目:burstcoin    文件:LongConvert.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    String id = Convert.emptyToNull(req.getParameter("id"));
    if (id == null) {
        return JSON.emptyJSON;
    }
    JSONObject response = new JSONObject();
    BigInteger bigInteger = new BigInteger(id);
    if (bigInteger.signum() < 0) {
        if (bigInteger.negate().compareTo(Convert.two64) > 0) {
            response.put("error", "overflow");
        } else {
            response.put("stringId", bigInteger.add(Convert.two64).toString());
            response.put("longId", String.valueOf(bigInteger.longValue()));
        }
    } else {
        if (bigInteger.compareTo(Convert.two64) >= 0) {
            response.put("error", "overflow");
        } else {
            response.put("stringId", bigInteger.toString());
            response.put("longId", String.valueOf(bigInteger.longValue()));
        }
    }
    return response;
}
项目:burstcoin    文件:GetAssets.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String[] assets = req.getParameterValues("assets");

    JSONObject response = new JSONObject();
    JSONArray assetsJSONArray = new JSONArray();
    response.put("assets", assetsJSONArray);
    for (String assetIdString : assets) {
        if (assetIdString == null || assetIdString.equals("")) {
            continue;
        }
        try {
            Asset asset = Asset.getAsset(Convert.parseUnsignedLong(assetIdString));
            if (asset == null) {
                return UNKNOWN_ASSET;
            }
            assetsJSONArray.add(JSONData.asset(asset));
        } catch (RuntimeException e) {
            return INCORRECT_ASSET;
        }
    }
    return response;
}
项目:burstcoin    文件:StartForging.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String secretPhrase = req.getParameter("secretPhrase");
    if (secretPhrase == null) {
        return MISSING_SECRET_PHRASE;
    }

    //Generator generator = Generator.startForging(secretPhrase);
    //if (generator == null) {
        return UNKNOWN_ACCOUNT;
    //}

    //JSONObject response = new JSONObject();
    //response.put("deadline", generator.getDeadline());
    //return response;

}
项目:burstcoin    文件:DecodeToken.java   
@Override
public JSONStreamAware processRequest(HttpServletRequest req) {

    String website = req.getParameter("website");
    String tokenString = req.getParameter("token");
    if (website == null) {
        return MISSING_WEBSITE;
    } else if (tokenString == null) {
        return MISSING_TOKEN;
    }

    try {

        Token token = Token.parseToken(tokenString, website.trim());

        return JSONData.token(token);

    } catch (RuntimeException e) {
        return INCORRECT_WEBSITE;
    }
}
项目:burstcoin    文件:GetAskOrderIds.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long assetId = ParameterParser.getAsset(req).getId();
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray orderIds = new JSONArray();
    try (DbIterator<Order.Ask> askOrders = Order.Ask.getSortedOrders(assetId, firstIndex, lastIndex)) {
        while (askOrders.hasNext()) {
            orderIds.add(Convert.toUnsignedLong(askOrders.next().getId()));
        }
    }

    JSONObject response = new JSONObject();
    response.put("askOrderIds", orderIds);
    return response;

}
项目:burstcoin    文件:StopForging.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String secretPhrase = req.getParameter("secretPhrase");
    if (secretPhrase == null) {
        return MISSING_SECRET_PHRASE;
    }

    //Generator generator = Generator.stopForging(secretPhrase);
    Generator.GeneratorState generator = null;

    JSONObject response = new JSONObject();
    response.put("foundAndStopped", generator != null);
    return response;

}
项目:burstcoin    文件:GetAllTrades.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    final int timestamp = ParameterParser.getTimestamp(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    boolean includeAssetInfo = !"false".equalsIgnoreCase(req.getParameter("includeAssetInfo"));

    JSONObject response = new JSONObject();
    JSONArray trades = new JSONArray();
    try (FilteringIterator<Trade> tradeIterator = new FilteringIterator<>(Trade.getAllTrades(0, -1),
            new FilteringIterator.Filter<Trade>() {
                @Override
                public boolean ok(Trade trade) {
                    return trade.getTimestamp() >= timestamp;
                }
            }, firstIndex, lastIndex)) {
        while (tradeIterator.hasNext()) {
            trades.add(JSONData.trade(tradeIterator.next(), includeAssetInfo));
        }
    }
    response.put("trades", trades);
    return response;
}
项目:burstcoin    文件:GetBidOrderIds.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long assetId = ParameterParser.getAsset(req).getId();
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray orderIds = new JSONArray();
    try (DbIterator<Order.Bid> bidOrders = Order.Bid.getSortedOrders(assetId, firstIndex, lastIndex)) {
        while (bidOrders.hasNext()) {
            orderIds.add(Convert.toUnsignedLong(bidOrders.next().getId()));
        }
    }
    JSONObject response = new JSONObject();
    response.put("bidOrderIds", orderIds);
    return response;
}
项目:burstcoin    文件:GetBidOrders.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long assetId = ParameterParser.getAsset(req).getId();
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray orders = new JSONArray();
    try (DbIterator<Order.Bid> bidOrders = Order.Bid.getSortedOrders(assetId, firstIndex, lastIndex)) {
        while (bidOrders.hasNext()) {
            orders.add(JSONData.bidOrder(bidOrders.next()));
        }
    }
    JSONObject response = new JSONObject();
    response.put("bidOrders", orders);
    return response;
}
项目:burstcoin    文件:GetAccountBlockIds.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Account account = ParameterParser.getAccount(req);
    int timestamp = ParameterParser.getTimestamp(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray blockIds = new JSONArray();
    try (DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(account, timestamp, firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            Block block = iterator.next();
            blockIds.add(block.getStringId());
        }
    }

    JSONObject response = new JSONObject();
    response.put("blockIds", blockIds);

    return response;
}
项目:burstcoin    文件:GetRewardRecipient.java   
@Override
   JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    JSONObject response = new JSONObject();

    Account account = ParameterParser.getAccount(req);
    Account.RewardRecipientAssignment assignment = account.getRewardRecipientAssignment();
    long height = Nxt.getBlockchain().getLastBlock().getHeight();
    if(account == null || assignment == null) {
        response.put("rewardRecipient", Convert.toUnsignedLong(account.getId()));
    }
    else if(assignment.getFromHeight() > height + 1) {
        response.put("rewardRecipient", Convert.toUnsignedLong(assignment.getPrevRecipientId()));
    }
    else {
        response.put("rewardRecipient", Convert.toUnsignedLong(assignment.getRecipientId()));
    }

    return response;
}
项目:burstcoin    文件:DecodeHallmark.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String hallmarkValue = req.getParameter("hallmark");
    if (hallmarkValue == null) {
        return MISSING_HALLMARK;
    }

    try {

        Hallmark hallmark = Hallmark.parseHallmark(hallmarkValue);

        return JSONData.hallmark(hallmark);

    } catch (RuntimeException e) {
        return INCORRECT_HALLMARK;
    }
}
项目:burstcoin    文件:PlaceBidOrder.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Asset asset = ParameterParser.getAsset(req);
    long priceNQT = ParameterParser.getPriceNQT(req);
    long quantityQNT = ParameterParser.getQuantityQNT(req);
    long feeNQT = ParameterParser.getFeeNQT(req);
    Account account = ParameterParser.getSenderAccount(req);

    try {
        if (Convert.safeAdd(feeNQT, Convert.safeMultiply(priceNQT, quantityQNT)) > account.getUnconfirmedBalanceNQT()) {
            return NOT_ENOUGH_FUNDS;
        }
    } catch (ArithmeticException e) {
        return NOT_ENOUGH_FUNDS;
    }

    Attachment attachment = new Attachment.ColoredCoinsBidOrderPlacement(asset.getId(), quantityQNT, priceNQT);
    return createTransaction(req, account, attachment);
}
项目:burstcoin    文件:DecryptFrom.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Account account = ParameterParser.getAccount(req);
    if (account.getPublicKey() == null) {
        return INCORRECT_ACCOUNT;
    }
    String secretPhrase = ParameterParser.getSecretPhrase(req);
    byte[] data = Convert.parseHexString(Convert.nullToEmpty(req.getParameter("data")));
    byte[] nonce = Convert.parseHexString(Convert.nullToEmpty(req.getParameter("nonce")));
    EncryptedData encryptedData = new EncryptedData(data, nonce);
    boolean isText = !"false".equalsIgnoreCase(req.getParameter("decryptedMessageIsText"));
    try {
        byte[] decrypted = account.decryptFrom(encryptedData, secretPhrase);
        JSONObject response = new JSONObject();
        response.put("decryptedMessage", isText ? Convert.toString(decrypted) : Convert.toHexString(decrypted));
        return response;
    } catch (RuntimeException e) {
        Logger.logDebugMessage(e.toString());
        return DECRYPTION_FAILED;
    }
}
项目:burstcoin    文件:GetAccountBalance.java   
@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {

    JSONObject response = new JSONObject();

    try {
        Long accountId = Convert.parseAccountId((String)request.get("account"));
        Account account = Account.getAccount(accountId);
        if(account != null) {
            response.put("balanceNQT", Convert.toUnsignedLong(account.getBalanceNQT()));
        }
        else {
            response.put("balanceNQT", "0");
        }
    }
    catch(Exception e) {
    }

    return response;
}
项目:burstcoin    文件:GetAllOpenBidOrders.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    JSONObject response = new JSONObject();
    JSONArray ordersData = new JSONArray();

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    try (DbIterator<Order.Bid> bidOrders = Order.Bid.getAll(firstIndex, lastIndex)) {
        while (bidOrders.hasNext()) {
            ordersData.add(JSONData.bidOrder(bidOrders.next()));
        }
    }

    response.put("openOrders", ordersData);
    return response;
}
项目:burstcoin    文件:GenerateToken.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    String secretPhrase = req.getParameter("secretPhrase");
    String website = req.getParameter("website");
    if (secretPhrase == null) {
        return MISSING_SECRET_PHRASE;
    } else if (website == null) {
        return MISSING_WEBSITE;
    }

    try {

        String tokenString = Token.generateToken(secretPhrase, website.trim());

        JSONObject response = new JSONObject();
        response.put("token", tokenString);

        return response;

    } catch (RuntimeException e) {
        return INCORRECT_WEBSITE;
    }

}
项目:burstcoin    文件:GetAccountBlocks.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Account account = ParameterParser.getAccount(req);
    int timestamp = ParameterParser.getTimestamp(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    boolean includeTransactions = "true".equalsIgnoreCase(req.getParameter("includeTransactions"));

    JSONArray blocks = new JSONArray();
    try (DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(account, timestamp, firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            Block block = iterator.next();
            blocks.add(JSONData.block(block, includeTransactions));
        }
    }

    JSONObject response = new JSONObject();
    response.put("blocks", blocks);

    return response;
}
项目:burstcoin    文件:GenerateAuthorizationToken.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {
    String secretPhrase = req.getParameter("secretPhrase");
    if (! user.getSecretPhrase().equals(secretPhrase)) {
        return INVALID_SECRET_PHRASE;
    }

    String tokenString = Token.generateToken(secretPhrase, req.getParameter("website").trim());

    JSONObject response = new JSONObject();
    response.put("response", "showAuthorizationToken");
    response.put("token", tokenString);

    return response;
}
项目:burstcoin    文件:RemoveActivePeer.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {
    if (Users.allowedUserHosts == null && ! InetAddress.getByName(req.getRemoteAddr()).isLoopbackAddress()) {
        return LOCAL_USERS_ONLY;
    } else {
        int index = Integer.parseInt(req.getParameter("peer"));
        Peer peer= Users.getPeer(index);
        if (peer != null && ! peer.isBlacklisted()) {
            peer.deactivate();
        }
    }
    return null;
}
项目:burstcoin    文件:RemoveBlacklistedPeer.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {
    if (Users.allowedUserHosts == null && ! InetAddress.getByName(req.getRemoteAddr()).isLoopbackAddress()) {
        return LOCAL_USERS_ONLY;
    } else {
        int index = Integer.parseInt(req.getParameter("peer"));
        Peer peer = Users.getPeer(index);
        if (peer != null && peer.isBlacklisted()) {
            peer.unBlacklist();
        }
    }
    return null;
}
项目:burstcoin    文件:RemoveKnownPeer.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {
    if (Users.allowedUserHosts == null && ! InetAddress.getByName(req.getRemoteAddr()).isLoopbackAddress()) {
        return LOCAL_USERS_ONLY;
    } else {
        int index = Integer.parseInt(req.getParameter("peer"));
        Peer peer = Users.getPeer(index);
        if (peer != null) {
            peer.remove();
        }
    }
    return null;
}
项目:burstcoin    文件:GetAccountPublicKey.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Account account = ParameterParser.getAccount(req);

    if (account.getPublicKey() != null) {
        JSONObject response = new JSONObject();
        response.put("publicKey", Convert.toHexString(account.getPublicKey()));
        return response;
    } else {
        return JSON.emptyJSON;
    }
}
项目:burstcoin    文件:CancelAskOrder.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long orderId = ParameterParser.getOrderId(req);
    Account account = ParameterParser.getSenderAccount(req);
    Order.Ask orderData = Order.Ask.getAskOrder(orderId);
    if (orderData == null || orderData.getAccountId() != account.getId()) {
        return UNKNOWN_ORDER;
    }
    Attachment attachment = new Attachment.ColoredCoinsAskOrderCancellation(orderId);
    return createTransaction(req, account, attachment);
}
项目:burstcoin    文件:DGSPriceChange.java   
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getSenderAccount(req);
    DigitalGoodsStore.Goods goods = ParameterParser.getGoods(req);
    long priceNQT = ParameterParser.getPriceNQT(req);
    if (goods.isDelisted() || goods.getSellerId() != account.getId()) {
        return UNKNOWN_GOODS;
    }
    Attachment attachment = new Attachment.DigitalGoodsPriceChange(goods.getId(), priceNQT);
    return createTransaction(req, account, attachment);
}