It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
Block block = new Block(1, getEpochTime(System.currentTimeMillis()), lastBlock, newTransactions.size(), 0, 0, 0, null, Crypto.getPublicKey(secretPhrase), null, new byte[64]);
Block block = new Block(1, getEpochTime(System.currentTimeMillis()), lastBlock, newTransactions.size(), 0, 0, 0, null, Crypto.getPublicKey(secretPhrase), null, new byte[64]);
int elapsedTime = getEpochTime(System.currentTimeMillis()) - lastBlock.timestamp;
if (elapsedTime > 0) {
BigInteger target = BigInteger.valueOf(Block.getBaseTarget()).multiply(BigInteger.valueOf(account.getEffectiveBalance())).multiply(BigInteger.valueOf(elapsedTime));
if (hits.get(account).compareTo(target) < 0) {
account.generateBlock(user.secretPhrase);
}
}
if (bootstrappingState >= 0) {
peer = Peer.getAnyConnectedPeer();
if (peer != null) {
setBootstrappingState(0);
ByteBuffer outputBuffer = Peer.getOutputBuffer(0, Peer.PACKET_TYPE_CUMULATIVE_DIFFICULTY_REQUEST);
peer.send(outputBuffer);
}
}
case PACKET_TYPE_CUMULATIVE_DIFFICULTY_REQUEST:
{
byte[] cumulativeDifficulty = Block.getLastBlock().cumulativeDifficulty.toByteArray();
ByteBuffer outputBuffer = getOutputBuffer(2 + cumulativeDifficulty.length, PACKET_TYPE_CUMULATIVE_DIFFICULTY_RESPONSE);
outputBuffer.putShort((short)cumulativeDifficulty.length);
outputBuffer.put(cumulativeDifficulty);
send(outputBuffer);
}
break;
case PACKET_TYPE_CUMULATIVE_DIFFICULTY_RESPONSE:
{
if (bootstrappingState == 0) {
int cumulativeDifficultyLength = inputBuffer.getShort();
byte[] cumulativeDifficulty = new byte[cumulativeDifficultyLength];
inputBuffer.get(cumulativeDifficulty);
betterCumulativeDifficulty = new BigInteger(cumulativeDifficulty);
synchronized (blocks) {
if (betterCumulativeDifficulty.compareTo(Block.getLastBlock().cumulativeDifficulty) > 0) {
setBootstrappingState(-1);
bootstrappingPeer = this;
ByteBuffer outputBuffer = Peer.getOutputBuffer(0, PACKET_TYPE_MILESTONE_BLOCKS_REQUEST);
send(outputBuffer);
} else {
setBootstrappingState(1);
}
}
}
}
break;
case PACKET_TYPE_MILESTONE_BLOCKS_REQUEST:
{
try {
LinkedListmilestoneBlocks = new LinkedList<>();
Block block = Block.getLastBlock();
int jumpLength = block.height / 4093 + 1;
while (block.height > 0) {
milestoneBlocks.add(block.getId());
for (int i = 0; i < jumpLength && block.height > 0; i++) {
block = blocks.get(block.previousBlock);
}
}
ByteBuffer outputBuffer = Peer.getOutputBuffer(2 + milestoneBlocks.size() * 8, PACKET_TYPE_MILESTONE_BLOCKS_RESPONSE);
outputBuffer.putShort((short)milestoneBlocks.size());
for (int i = 0; i < milestoneBlocks.size(); i++) {
outputBuffer.putLong(milestoneBlocks.get(i));
}
send(outputBuffer);
} catch (Exception e) {
log("12: " + e.toString());
}
}
break;
case PACKET_TYPE_MILESTONE_BLOCKS_RESPONSE:
{
if (bootstrappingState < 0) {
Block commonBlock = blocks.get(genesisBlock);
int numberOfBlocks = inputBuffer.getShort();
while (numberOfBlocks-- > 0) {
long blockId = inputBuffer.getLong();
Block block = blocks.get(blockId);
if (block != null) {
commonBlock = block;
break;
}
}
try {
ByteBuffer outputBuffer = Peer.getOutputBuffer(8, PACKET_TYPE_NEXT_BLOCK_IDS_REQUEST);
lastCommonBlock = commonBlock.getId();
outputBuffer.putLong(lastCommonBlock);
send(outputBuffer);
} catch (Exception e) {
log("13: " + e.toString());
}
}
}
break;
case PACKET_TYPE_NEXT_BLOCK_IDS_REQUEST:
{
try {
LinkedListnextBlocks = new LinkedList<>();
Block block = blocks.get(inputBuffer.getLong());
while (block != null && nextBlocks.size() < 4093) {
block = blocks.get(block.nextBlock);
if (block != null) {
nextBlocks.add(block.getId());
}
}
ByteBuffer outputBuffer = Peer.getOutputBuffer(2 + nextBlocks.size() * 8, PACKET_TYPE_NEXT_BLOCK_IDS_RESPONSE);
outputBuffer.putShort((short)nextBlocks.size());
for (int i = 0; i < nextBlocks.size(); i++) {
outputBuffer.putLong(nextBlocks.get(i));
}
send(outputBuffer);
} catch (Exception e) {
log("14: " + e.toString());
}
}
break;
case PACKET_TYPE_NEXT_BLOCK_IDS_RESPONSE:
{
if (bootstrappingState < 0) {
int numberOfBlocks = inputBuffer.getShort();
if (numberOfBlocks == 0) {
setBootstrappingState(1);
break;
}
long blockId;
while (numberOfBlocks-- > 0) {
blockId = inputBuffer.getLong();
if (blocks.get(blockId) == null) {
break;
}
lastCommonBlock = blockId;
}
if (numberOfBlocks < 0) {
ByteBuffer outputBuffer = Peer.getOutputBuffer(8, PACKET_TYPE_NEXT_BLOCK_IDS_REQUEST);
outputBuffer.putLong(lastCommonBlock);
send(outputBuffer);
} else {
if (Block.getLastBlock().height - blocks.get(lastCommonBlock).height > 720) {
setBootstrappingState(1);
} else {
while (lastBlock != lastCommonBlock && Block.popLastBlock()) { }
if (lastBlock == lastCommonBlock) {
ByteBuffer outputBuffer = Peer.getOutputBuffer(8, PACKET_TYPE_NEXT_BLOCKS_REQUEST);
outputBuffer.putLong(lastBlock);
send(outputBuffer);
} else {
setBootstrappingState(1);
}
}
}
}
}
break;
case PACKET_TYPE_NEXT_BLOCKS_REQUEST:
{
LinkedListnextBlocks = new LinkedList<>();
int totalLength = 0;
Block block = blocks.get(inputBuffer.getLong());
while (block != null) {
block = blocks.get(block.nextBlock);
if (block != null) {
int length = 224 + block.payloadLength;
if (totalLength + length > 32768 - (8 + 2)) {
break;
}
nextBlocks.add(block);
totalLength += length;
}
}
ByteBuffer outputBuffer = Peer.getOutputBuffer(2 + totalLength, PACKET_TYPE_NEXT_BLOCKS_RESPONSE);
outputBuffer.putShort((short)nextBlocks.size());
for (int i = 0; i < nextBlocks.size(); i++) {
block = nextBlocks.get(i);
outputBuffer.put(block.getBytes());
for (int j = 0; j < block.numberOfTransactions; j++) {
outputBuffer.put(transactions.get(block.transactions[j]).getBytes());
}
}
send(outputBuffer);
}
break;
case PACKET_TYPE_NEXT_BLOCKS_RESPONSE:
{
if (bootstrappingState < 0) {
int numberOfBlocks = inputBuffer.getShort();
if (numberOfBlocks == 0) {
setBootstrappingState(1);
break;
}
while (numberOfBlocks-- > 0) {
if (!Block.pushBlock(inputBuffer)) {
break;
}
}
ByteBuffer outputBuffer = Peer.getOutputBuffer(8, PACKET_TYPE_NEXT_BLOCKS_REQUEST);
outputBuffer.putLong(lastBlock);
send(outputBuffer);
}
}
break;
(new Thread() {
@Override
public void run() {
HashMaplastBlocks = new HashMap<>();
HashMaphits = new HashMap<>();
while (state == 0) {
try {
if (bootstrappingState >= 0) {
HashMapunlockedAccounts = new HashMap<>();
for (User user : users.values()) {
if (user.secretPhrase != null) {
Account account = accounts.get(Account.getId(Crypto.getPublicKey(user.secretPhrase)));
if (account != null && account.getEffectiveBalance() > 0) {
unlockedAccounts.put(account, user);
}
}
}
for (Map.EntryunlockedAccountEntry : unlockedAccounts.entrySet()) {
Account account = unlockedAccountEntry.getKey();
User user = unlockedAccountEntry.getValue();
Block lastBlock = Block.getLastBlock();
if (lastBlocks.get(account) != lastBlock) {
byte[] generationSignature = Crypto.sign(lastBlock.generationSignature, user.secretPhrase);
byte[] generationSignatureHash = MessageDigest.getInstance("SHA-256").digest(generationSignature);
BigInteger hit = new BigInteger(1, new byte[] {generationSignatureHash[7], generationSignatureHash[6], generationSignatureHash[5], generationSignatureHash[4], generationSignatureHash[3], generationSignatureHash[2], generationSignatureHash[1], generationSignatureHash[0]});
lastBlocks.put(account, lastBlock);
hits.put(account, hit);
JSONObject response = new JSONObject();
response.put("response", "setBlockGenerationDeadline");
response.put("deadline", hit.divide(BigInteger.valueOf(Block.getBaseTarget()).multiply(BigInteger.valueOf(account.getEffectiveBalance()))).longValue() - (getEpochTime(System.currentTimeMillis()) - lastBlock.timestamp));
user.send(response);
}
int elapsedTime = getEpochTime(System.currentTimeMillis()) - lastBlock.timestamp;
if (elapsedTime > 0) {
BigInteger target = BigInteger.valueOf(Block.getBaseTarget()).multiply(BigInteger.valueOf(account.getEffectiveBalance())).multiply(BigInteger.valueOf(elapsedTime));
if (hits.get(account).compareTo(target) < 0) {
account.generateBlock(user.secretPhrase);
}
}
}
}
Thread.sleep(1000);
} catch (Exception e) {
log("9: " + e.toString());
}
}
}
}).start();
int getEffectiveBalance() {
if (height == 0) {
return (int)(balance / 100);
}
if (Block.getLastBlock().height - height < 1440) {
return 0;
}
int amount = 0;
for (long transactionId : Block.getLastBlock().transactions) {
Transaction transaction = transactions.get(transactionId);
if (transaction.recipient == id) {
amount += transaction.amount;
}
}
return (int)(balance / 100) - amount;
}
void generateBlock(String secretPhrase) throws Exception {
HashMapnewTransactions;
synchronized (transactions) {
Transaction[] sortedTransactions = unconfirmedTransactions.values().toArray(new Transaction[0]);
while (sortedTransactions.length > 0) {
int i;
for (i = 0; i < sortedTransactions.length; i++) {
Transaction transaction = sortedTransactions[i];
if (transaction.referencedTransaction != 0 && transactions.get(transaction.referencedTransaction) == null) {
sortedTransactions[i] = sortedTransactions[sortedTransactions.length - 1];
Transaction[] tmp = new Transaction[sortedTransactions.length - 1];
System.arraycopy(sortedTransactions, 0, tmp, 0, tmp.length);
sortedTransactions = tmp;
break;
}
}
if (i == sortedTransactions.length) {
break;
}
}
Arrays.sort(sortedTransactions);
newTransactions = new HashMap<>();
for (int i = 0; i < 255 && i < sortedTransactions.length; i++) {
long id = sortedTransactions[i].getId();
newTransactions.put(id, sortedTransactions[i]);
}
}
Block block = new Block(1, getEpochTime(System.currentTimeMillis()), lastBlock, newTransactions.size(), 0, 0, 0, null, Crypto.getPublicKey(secretPhrase), null, new byte[64]);
block.transactions = new long[block.numberOfTransactions];
int i = 0;
for (Map.EntrytransactionEntry : newTransactions.entrySet()) {
Transaction transaction = transactionEntry.getValue();
if (transaction.type == Transaction.TYPE_PAYMENT && transaction.subtype == Transaction.SUBTYPE_PAYMENT_ORDINARY_PAYMENT) {
block.totalAmount += transaction.amount;
}
block.totalFee += transaction.fee;
block.payloadLength += transaction.getBytes().length;
block.transactions[i++] = transactionEntry.getKey();
}
Arrays.sort(block.transactions);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
for (i = 0; i < block.numberOfTransactions; i++) {
digest.update(newTransactions.get(block.transactions[i]).getBytes());
}
block.payloadHash = digest.digest();
block.generationSignature = Crypto.sign(Block.getLastBlock().generationSignature, secretPhrase);
byte[] data = block.getBytes();
byte[] data2 = new byte[data.length - 64];
System.arraycopy(data, 0, data2, 0, data2.length);
block.blockSignature = Crypto.sign(data2, secretPhrase);
ByteBuffer outputBuffer = Peer.getOutputBuffer(224 + block.payloadLength, Peer.PACKET_TYPE_NEW_BLOCK_REQUEST);
outputBuffer.put(block.getBytes());
for (i = 0; i < block.numberOfTransactions; i++) {
Transaction transaction = newTransactions.get(block.transactions[i]);
outputBuffer.put(transaction.getBytes());
}
Peer.sendToAllPeers(outputBuffer);
}
public int compareTo(Transaction o) {
if (height < o.height) {
return -1;
} else if (height > o.height) {
return 1;
} else {
if (fee * 32768L / getBytes().length > o.fee * 32768L / o.getBytes().length) {
return -1;
} else if (fee * 32768L / getBytes().length < o.fee * 32768L / o.getBytes().length) {
return 1;
} else {
if (timestamp < o.timestamp) {
return -1;
} else if (timestamp > o.timestamp) {
return 1;
} else {
if (index < o.index) {
return -1;
} else if (index > o.index) {
return 1;
} else {
return 0;
}
}
}
}
}