Skip to content
Permalink
Browse files

v 1.20.00

  • Loading branch information...
CryTrExcom committed Aug 22, 2019
1 parent b12c86f commit 4d7210c2987085d467564b548cc85919fdea28d4

Large diffs are not rendered by default.

@@ -1,76 +1,76 @@
/*
* Copyright © 2013-2016 The Nxt Core Developers.
* Copyright © 2016-2019 Jelurida IP B.V.
*
* See the LICENSE.txt file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,
* no part of the Nxt software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE.txt file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/

package nxt;

public interface Fee {

long getFee(TransactionImpl transaction, Appendix appendage);

Fee DEFAULT_FEE = new Fee.ConstantFee(Constants.ONE_NXT);

Fee NONE = new Fee.ConstantFee(0L);

final class ConstantFee implements Fee {

private final long fee;

public ConstantFee(long fee) {
this.fee = fee;
}

@Override
public long getFee(TransactionImpl transaction, Appendix appendage) {
return fee;
}

}

abstract class SizeBasedFee implements Fee {

private final long constantFee;
private final long feePerSize;
private final int unitSize;

public SizeBasedFee(long feePerSize) {
this(0, feePerSize);
}

public SizeBasedFee(long constantFee, long feePerSize) {
this(constantFee, feePerSize, 1024);
}

public SizeBasedFee(long constantFee, long feePerSize, int unitSize) {
this.constantFee = constantFee;
this.feePerSize = feePerSize;
this.unitSize = unitSize;
}

// the first size unit is free if constantFee is 0
@Override
public final long getFee(TransactionImpl transaction, Appendix appendage) {
int size = getSize(transaction, appendage) - 1;
if (size < 0) {
return constantFee;
}
return Math.addExact(constantFee, Math.multiplyExact((long) (size / unitSize), feePerSize));
}

public abstract int getSize(TransactionImpl transaction, Appendix appendage);

}

}
/*
* Copyright © 2013-2016 The Nxt Core Developers.
* Copyright © 2016-2019 Jelurida IP B.V.
*
* See the LICENSE.txt file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,
* no part of the Nxt software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE.txt file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/

package nxt;

public interface Fee {

long getFee(TransactionImpl transaction, Appendix appendage);

Fee DEFAULT_FEE = new Fee.ConstantFee(1000000);

Fee NONE = new Fee.ConstantFee(0L);

final class ConstantFee implements Fee {

private final long fee;

public ConstantFee(long fee) {
this.fee = fee;
}

@Override
public long getFee(TransactionImpl transaction, Appendix appendage) {
return fee;
}

}

abstract class SizeBasedFee implements Fee {

private final long constantFee;
private final long feePerSize;
private final int unitSize;

public SizeBasedFee(long feePerSize) {
this(0, feePerSize);
}

public SizeBasedFee(long constantFee, long feePerSize) {
this(constantFee, feePerSize, 1024);
}

public SizeBasedFee(long constantFee, long feePerSize, int unitSize) {
this.constantFee = constantFee;
this.feePerSize = feePerSize;
this.unitSize = unitSize;
}

// the first size unit is free if constantFee is 0
@Override
public final long getFee(TransactionImpl transaction, Appendix appendage) {
int size = getSize(transaction, appendage) - 1;
if (size < 0) {
return constantFee;
}
return Math.addExact(constantFee, Math.multiplyExact((long) (size / unitSize), feePerSize));
}

public abstract int getSize(TransactionImpl transaction, Appendix appendage);

}

}
@@ -51,7 +51,7 @@

public final class Nxt {

public static final String VERSION = "1.11.15";
public static final String VERSION = "1.20.00";
public static final String APPLICATION = "CryTrExCoin";

private static volatile Time time = new Time.EpochTime();
@@ -404,7 +404,7 @@ public static void shutdown() {
long currentTime = System.currentTimeMillis();
Logger.logMessage("Initialization took " + (currentTime - startTime) / 1000 + " seconds");
Logger.logMessage(Nxt.APPLICATION + " server " + VERSION + " started successfully.");
Logger.logMessage("Copyright © 2019 The CRYT Core Developers.");
Logger.logMessage("Copyright © 2019 CryTrEx.com");
if (API.getWelcomePageUri() != null) {
Logger.logMessage("Client UI is at " + API.getWelcomePageUri());
}
@@ -425,7 +425,7 @@ public static void shutdown() {

private static void init() {
if (initialized) {
throw new RuntimeException("Nxt.init has already been called");
throw new RuntimeException("init has already been called");
}
initialized = true;
}
@@ -0,0 +1,55 @@
/*
* Copyright © 2013-2016 The Nxt Core Developers.
* Copyright © 2016-2018 Jelurida IP B.V.
*
* See the LICENSE.txt file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,
* no part of the Nxt software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE.txt file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/

package nxt.user;

import nxt.Token;
import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

import static nxt.user.JSONResponses.INVALID_SECRET_PHRASE;

public final class GenerateAuthorizationToken extends UserServlet.UserRequestHandler {

static final GenerateAuthorizationToken instance = new GenerateAuthorizationToken();

private GenerateAuthorizationToken() {}

@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;
}

@Override
boolean requirePost() {
return true;
}

}
@@ -0,0 +1,144 @@
/*
* Copyright © 2013-2016 The Nxt Core Developers.
* Copyright © 2016-2018 Jelurida IP B.V.
*
* See the LICENSE.txt file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,
* no part of the Nxt software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE.txt file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/

package nxt.user;

import nxt.Block;
import nxt.Constants;
import nxt.Nxt;
import nxt.Transaction;
import nxt.db.DbIterator;
import nxt.peer.Peer;
import nxt.peer.Peers;
import nxt.util.Convert;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigInteger;

public final class GetInitialData extends UserServlet.UserRequestHandler {

static final GetInitialData instance = new GetInitialData();

private GetInitialData() {}

@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {

JSONArray unconfirmedTransactions = new JSONArray();
JSONArray activePeers = new JSONArray(), knownPeers = new JSONArray(), blacklistedPeers = new JSONArray();
JSONArray recentBlocks = new JSONArray();

try (DbIterator<? extends Transaction> transactions = Nxt.getTransactionProcessor().getAllUnconfirmedTransactions()) {
while (transactions.hasNext()) {
Transaction transaction = transactions.next();

JSONObject unconfirmedTransaction = new JSONObject();
unconfirmedTransaction.put("index", Users.getIndex(transaction));
unconfirmedTransaction.put("timestamp", transaction.getTimestamp());
unconfirmedTransaction.put("deadline", transaction.getDeadline());
unconfirmedTransaction.put("recipient", Long.toUnsignedString(transaction.getRecipientId()));
unconfirmedTransaction.put("amountNQT", transaction.getAmountNQT());
unconfirmedTransaction.put("feeNQT", transaction.getFeeNQT());
unconfirmedTransaction.put("sender", Long.toUnsignedString(transaction.getSenderId()));
unconfirmedTransaction.put("id", transaction.getStringId());

unconfirmedTransactions.add(unconfirmedTransaction);
}
}

for (Peer peer : Peers.getAllPeers()) {

if (peer.isBlacklisted()) {

JSONObject blacklistedPeer = new JSONObject();
blacklistedPeer.put("index", Users.getIndex(peer));
blacklistedPeer.put("address", peer.getHost());
blacklistedPeer.put("announcedAddress", Convert.truncate(peer.getAnnouncedAddress(), "-", 25, true));
blacklistedPeer.put("software", peer.getSoftware());
blacklistedPeers.add(blacklistedPeer);

} else if (peer.getState() == Peer.State.NON_CONNECTED) {

JSONObject knownPeer = new JSONObject();
knownPeer.put("index", Users.getIndex(peer));
knownPeer.put("address", peer.getHost());
knownPeer.put("announcedAddress", Convert.truncate(peer.getAnnouncedAddress(), "-", 25, true));
knownPeer.put("software", peer.getSoftware());
knownPeers.add(knownPeer);

} else {

JSONObject activePeer = new JSONObject();
activePeer.put("index", Users.getIndex(peer));
if (peer.getState() == Peer.State.DISCONNECTED) {
activePeer.put("disconnected", true);
}
activePeer.put("address", peer.getHost());
activePeer.put("announcedAddress", Convert.truncate(peer.getAnnouncedAddress(), "-", 25, true));
activePeer.put("weight", peer.getWeight());
activePeer.put("downloaded", peer.getDownloadedVolume());
activePeer.put("uploaded", peer.getUploadedVolume());
activePeer.put("software", peer.getSoftware());
activePeers.add(activePeer);
}
}

try (DbIterator<? extends Block> lastBlocks = Nxt.getBlockchain().getBlocks(0, 59)) {
for (Block block : lastBlocks) {
JSONObject recentBlock = new JSONObject();
recentBlock.put("index", Users.getIndex(block));
recentBlock.put("timestamp", block.getTimestamp());
recentBlock.put("numberOfTransactions", block.getTransactions().size());
recentBlock.put("totalAmountNQT", block.getTotalAmountNQT());
recentBlock.put("totalFeeNQT", block.getTotalFeeNQT());
recentBlock.put("payloadLength", block.getPayloadLength());
recentBlock.put("generator", Long.toUnsignedString(block.getGeneratorId()));
recentBlock.put("height", block.getHeight());
recentBlock.put("version", block.getVersion());
recentBlock.put("block", block.getStringId());
recentBlock.put("baseTarget", BigInteger.valueOf(block.getBaseTarget()).multiply(BigInteger.valueOf(100000))
.divide(BigInteger.valueOf(Constants.INITIAL_BASE_TARGET)));

recentBlocks.add(recentBlock);
}
}

JSONObject response = new JSONObject();
response.put("response", "processInitialData");
response.put("version", Nxt.VERSION);
if (unconfirmedTransactions.size() > 0) {
response.put("unconfirmedTransactions", unconfirmedTransactions);
}
if (activePeers.size() > 0) {
response.put("activePeers", activePeers);
}
if (knownPeers.size() > 0) {
response.put("knownPeers", knownPeers);
}
if (blacklistedPeers.size() > 0) {
response.put("blacklistedPeers", blacklistedPeers);
}
if (recentBlocks.size() > 0) {
response.put("recentBlocks", recentBlocks);
}

return response;
}
}

0 comments on commit 4d7210c

Please sign in to comment.
You can’t perform that action at this time.