mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Move non-production apps from main to test
+ Move test apps from org.qora.test to org.qora.test.apps ("app" being a class with a main() method)
This commit is contained in:
@@ -1,105 +0,0 @@
|
||||
package org.qora;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
import org.bitcoinj.core.Base58;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
|
||||
import org.qora.block.BlockChain;
|
||||
import org.qora.controller.Controller;
|
||||
import org.qora.data.account.RewardShareData;
|
||||
import org.qora.gui.Gui;
|
||||
import org.qora.repository.DataException;
|
||||
import org.qora.repository.Repository;
|
||||
import org.qora.repository.RepositoryFactory;
|
||||
import org.qora.repository.RepositoryManager;
|
||||
import org.qora.repository.hsqldb.HSQLDBRepositoryFactory;
|
||||
import org.qora.settings.Settings;
|
||||
import org.qora.transform.block.BlockTransformer;
|
||||
import org.roaringbitmap.IntIterator;
|
||||
|
||||
import io.druid.extendedset.intset.ConciseSet;
|
||||
|
||||
public class DecodeOnlineAccounts {
|
||||
|
||||
private static void usage() {
|
||||
System.err.println("Usage: DecodeOnlineAccounts [<settings-file>] <base58-encoded-accounts>");
|
||||
System.err.println("Example: DecodeOnlineAccounts 4GmR5B");
|
||||
System.err.println("Example: DecodeOnlineAccounts settings-test.json 4GmR5B");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1 || args.length > 2)
|
||||
usage();
|
||||
|
||||
byte[] encodedOnlineAccounts = Base58.decode(args[args.length - 1]);
|
||||
|
||||
ConciseSet accountIndexes = BlockTransformer.decodeOnlineAccounts(encodedOnlineAccounts);
|
||||
|
||||
String delimiter = "";
|
||||
System.out.print("Account indexes: ");
|
||||
|
||||
IntIterator iterator = accountIndexes.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
int accountIndex = iterator.next();
|
||||
|
||||
System.out.print(String.format("%s%d", delimiter, accountIndex));
|
||||
delimiter = ", ";
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0);
|
||||
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
|
||||
|
||||
// Load/check settings, which potentially sets up blockchain config, etc.
|
||||
try {
|
||||
if (args.length > 1)
|
||||
Settings.fileInstance(args[0]);
|
||||
else
|
||||
Settings.getInstance();
|
||||
} catch (Throwable t) {
|
||||
Gui.getInstance().fatalError("Settings file", t.getMessage());
|
||||
return; // Not System.exit() so that GUI can display error
|
||||
}
|
||||
|
||||
try {
|
||||
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(Controller.getRepositoryUrl());
|
||||
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||
} catch (DataException e) {
|
||||
System.err.println("Couldn't connect to repository: " + e.getMessage());
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
try {
|
||||
BlockChain.validate();
|
||||
} catch (DataException e) {
|
||||
System.err.println("Couldn't validate repository: " + e.getMessage());
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
iterator = accountIndexes.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
int accountIndex = iterator.next();
|
||||
|
||||
RewardShareData rewardShareData = repository.getAccountRepository().getRewardShareByIndex(accountIndex);
|
||||
|
||||
System.out.println(String.format("Reward-share public key: %s, minter: %s, recipient: %s, share: %s",
|
||||
Base58.encode(rewardShareData.getRewardSharePublicKey()),
|
||||
rewardShareData.getMintingAccount(), rewardShareData.getRecipient(),
|
||||
rewardShareData.getSharePercent().toPlainString()));
|
||||
}
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
RepositoryManager.closeRepositoryFactory();
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package org.qora;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
|
||||
import org.qora.account.PrivateKeyAccount;
|
||||
import org.qora.account.PublicKeyAccount;
|
||||
import org.qora.utils.Base58;
|
||||
|
||||
public class RewardShareKeys {
|
||||
|
||||
private static void usage() {
|
||||
System.err.println("Usage: RewardShareKeys <minter-private-key> [<recipient-public-key>]");
|
||||
System.err.println("Example: RewardShareKeys pYQ6DpQBJ2n72TCLJLScEvwhf3boxWy2kQEPynakwpj 6rNn9b3pYRrG9UKqzMWYZ9qa8F3Zgv2mVWrULGHUusb");
|
||||
System.err.println("Example (self-share): RewardShareKeys pYQ6DpQBJ2n72TCLJLScEvwhf3boxWy2kQEPynakwpj");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1 || args.length > 2)
|
||||
usage();
|
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0);
|
||||
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
|
||||
|
||||
PrivateKeyAccount minterAccount = new PrivateKeyAccount(null, Base58.decode(args[0]));
|
||||
PublicKeyAccount recipientAccount = new PublicKeyAccount(null, args.length > 1 ? Base58.decode(args[1]) : minterAccount.getPublicKey());
|
||||
|
||||
byte[] rewardSharePrivateKey = minterAccount.getRewardSharePrivateKey(recipientAccount.getPublicKey());
|
||||
byte[] rewardSharePublicKey = PrivateKeyAccount.toPublicKey(rewardSharePrivateKey);
|
||||
|
||||
System.out.println(String.format("Minter account: %s", minterAccount.getAddress()));
|
||||
System.out.println(String.format("Minter's public key: %s", Base58.encode(minterAccount.getPublicKey())));
|
||||
|
||||
System.out.println(String.format("Recipient account: %s", recipientAccount.getAddress()));
|
||||
|
||||
System.out.println(String.format("Reward-share private key: %s", Base58.encode(rewardSharePrivateKey)));
|
||||
System.out.println(String.format("Reward-share public key: %s", Base58.encode(rewardSharePublicKey)));
|
||||
}
|
||||
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
package org.qora;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
|
||||
import org.qora.account.PrivateKeyAccount;
|
||||
import org.qora.crypto.Crypto;
|
||||
import org.qora.utils.BIP39;
|
||||
import org.qora.utils.Base58;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
public class VanityGen {
|
||||
|
||||
// From utils.Base58:
|
||||
private static final String ALPHABET_STR = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
|
||||
private static String prefix = null;
|
||||
|
||||
private static void usage() {
|
||||
System.err.println("Usage: Vanitygen [-t threads] <leading-chars>");
|
||||
System.err.println("Example: VanityGen Qcat");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private static class Generator implements Runnable {
|
||||
public void run() {
|
||||
Random random = new SecureRandom();
|
||||
byte[] entropy = new byte[16];
|
||||
|
||||
while (true) {
|
||||
// Generate entropy internally
|
||||
random.nextBytes(entropy);
|
||||
|
||||
// Use SHA256 to generate more bits
|
||||
byte[] hash = Crypto.digest(entropy);
|
||||
|
||||
// Append first 4 bits from hash to end. (Actually 8 bits but we only use 4).
|
||||
byte checksum = (byte) (hash[0] & 0xf0);
|
||||
byte[] entropy132 = Bytes.concat(entropy, new byte[] { checksum });
|
||||
|
||||
String mnemonic = BIP39.encode(entropy132, "en");
|
||||
|
||||
PrivateKeyAccount account = new PrivateKeyAccount(null, hash);
|
||||
|
||||
if (!account.getAddress().startsWith(prefix))
|
||||
continue;
|
||||
|
||||
System.out.println(String.format("Address: %s, public key: %s, private key: %s, mnemonic: %s",
|
||||
account.getAddress(), Base58.encode(account.getPublicKey()), Base58.encode(hash), mnemonic));
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0)
|
||||
usage();
|
||||
|
||||
int threadCount = 1;
|
||||
|
||||
int argIndex = 0;
|
||||
while (argIndex < args.length) {
|
||||
String arg = args[argIndex++];
|
||||
|
||||
if (arg.equals("-t")) {
|
||||
if (argIndex >= args.length)
|
||||
usage();
|
||||
|
||||
try {
|
||||
threadCount = Integer.parseInt(args[argIndex++]);
|
||||
} catch (NumberFormatException e) {
|
||||
usage();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefix != null)
|
||||
usage();
|
||||
|
||||
prefix = arg;
|
||||
if (!prefix.matches("[" + ALPHABET_STR + "]+")) {
|
||||
System.err.println("Only the following characters are allowed:\n" + ALPHABET_STR);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0);
|
||||
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
|
||||
|
||||
for (int ti = 0; ti < threadCount; ++ti)
|
||||
executor.execute(new Generator());
|
||||
}
|
||||
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
package org.qora;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.qora.controller.AutoUpdate;
|
||||
|
||||
public class XorUpdate {
|
||||
|
||||
private static final byte XOR_VALUE = AutoUpdate.XOR_VALUE;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length != 2) {
|
||||
System.err.println("usage: XorUpdate <input-file> <output-file>");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Path inPath = Paths.get(args[0]);
|
||||
if (!Files.isReadable(inPath)) {
|
||||
System.err.println(String.format("Cannot open '%s'", args[0]));
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
Path outPath = Paths.get(args[1]);
|
||||
|
||||
try (InputStream in = Files.newInputStream(inPath); OutputStream out = Files.newOutputStream(outPath)) {
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
do {
|
||||
int nread = in.read(buffer);
|
||||
if (nread == -1)
|
||||
break;
|
||||
|
||||
for (int i = 0; i < nread; ++i)
|
||||
buffer[i] ^= XOR_VALUE;
|
||||
|
||||
out.write(buffer, 0, nread);
|
||||
} while (true);
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getLocalizedMessage());
|
||||
|
||||
try {
|
||||
Files.deleteIfExists(outPath);
|
||||
} catch (IOException e1) {
|
||||
System.err.println(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package org.qora;
|
||||
import org.qora.crypto.BrokenMD160;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class brokenmd160 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
System.err.println("usage: broken-md160 <hex>\noutputs: hex");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
byte[] raw = HashCode.fromString(args[0]).asBytes();
|
||||
BrokenMD160 brokenMD160 = new BrokenMD160();
|
||||
byte[] digest = brokenMD160.digest(raw);
|
||||
|
||||
System.out.println(HashCode.fromBytes(digest).toString());
|
||||
}
|
||||
|
||||
}
|
@@ -2,7 +2,7 @@ package org.qora.crypto;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
public class CiyamMemoryPoW {
|
||||
public class MemoryPoW {
|
||||
|
||||
private static final int WORK_BUFFER_LENGTH = 4 * 1024 * 1024;
|
||||
private static final int WORK_BUFFER_LENGTH_MASK = WORK_BUFFER_LENGTH - 1;
|
@@ -1,56 +0,0 @@
|
||||
package org.qora;
|
||||
import java.security.Security;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.qora.block.BlockChain;
|
||||
import org.qora.controller.Controller;
|
||||
import org.qora.repository.DataException;
|
||||
import org.qora.repository.RepositoryFactory;
|
||||
import org.qora.repository.RepositoryManager;
|
||||
import org.qora.repository.hsqldb.HSQLDBRepositoryFactory;
|
||||
import org.qora.settings.Settings;
|
||||
|
||||
public class orphan {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
System.err.println("usage: orphan <new-blockchain-tip-height>");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
int targetHeight = Integer.parseInt(args[0]);
|
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0);
|
||||
|
||||
// Load/check settings, which potentially sets up blockchain config, etc.
|
||||
Settings.getInstance();
|
||||
|
||||
try {
|
||||
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(Controller.getRepositoryUrl());
|
||||
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||
} catch (DataException e) {
|
||||
System.err.println("Couldn't connect to repository: " + e.getMessage());
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
try {
|
||||
BlockChain.validate();
|
||||
} catch (DataException e) {
|
||||
System.err.println("Couldn't validate repository: " + e.getMessage());
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
try {
|
||||
BlockChain.orphan(targetHeight);
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
RepositoryManager.closeRepositoryFactory();
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user