Skip to content

Commit

Permalink
Merge pull request #256 from dashpay/feature-core-21
Browse files Browse the repository at this point in the history
feat: support Core 21 and other updates
  • Loading branch information
HashEngineering authored Aug 6, 2024
2 parents c4deeb8 + cde88a3 commit d6b256d
Show file tree
Hide file tree
Showing 116 changed files with 2,391 additions and 1,457 deletions.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ test {
exclude 'org/bitcoinj/core/PeerTest*'
exclude 'org/bitcoinj/core/TransactionBroadcastTest*'
exclude 'org/bitcoinj/net/NetworkAbstractionTests*'
exclude 'org/bitcoinj/net/discovery/DnsDiscoveryTest*'
exclude 'org/bitcoinj/protocols/channels/ChannelConnectionTest*'
exclude 'org/bitcoinj/core/LevelDBFullPrunedBlockChainTest*'
exclude 'org/bitcoinj/store/LevelDBBlockStoreTest*'
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.bitcoinj.script.Script.ScriptType;
import org.bitcoinj.script.ScriptPattern;

import com.google.common.base.Objects;
import java.util.Objects;

/**
* <p>A Bitcoin address looks like 1MsScoe2fTJoq4ZPdQgqyhgWeoNamYPevy and is derived from an elliptic curve public key
Expand Down Expand Up @@ -284,7 +284,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), p2sh);
return Objects.hash(super.hashCode(), p2sh);
}

@Override
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/org/bitcoinj/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,9 @@ private void writeTransactions(OutputStream stream) throws IOException {
return;
}

if (transactions != null) {
stream.write(new VarInt(transactions.size()).encode());
for (Transaction tx : transactions) {
tx.bitcoinSerialize(stream);
}
stream.write(new VarInt(transactions.size()).encode());
for (Transaction tx : transactions) {
tx.bitcoinSerialize(stream);
}
//writeMasterNodeVotes(stream);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/BloomFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.bitcoinj.script.ScriptPattern;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.*;
Expand Down Expand Up @@ -373,7 +373,7 @@ public synchronized boolean equals(Object o) {

@Override
public synchronized int hashCode() {
return Objects.hashCode(hashFuncs, nTweak, Arrays.hashCode(data));
return Objects.hash(hashFuncs, nTweak, Arrays.hashCode(data));
}

public final byte[] getData() {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/bitcoinj/core/Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.bitcoinj.utils.MonetaryFormat;
import com.google.common.math.LongMath;
import com.google.common.primitives.Longs;

import java.io.Serializable;
import java.math.BigDecimal;
Expand Down Expand Up @@ -327,6 +326,6 @@ public int hashCode() {

@Override
public int compareTo(final Coin other) {
return Longs.compare(this.value, other.value);
return Long.compare(this.value, other.value);
}
}
14 changes: 7 additions & 7 deletions core/src/main/java/org/bitcoinj/core/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import org.bitcoin.NativeSecp256k1;
Expand Down Expand Up @@ -62,6 +61,7 @@
import java.security.SignatureException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

import static com.google.common.base.Preconditions.*;

Expand Down Expand Up @@ -611,7 +611,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(r, s);
return Objects.hash(r, s);
}
}

Expand Down Expand Up @@ -1340,11 +1340,11 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof ECKey)) return false;
ECKey other = (ECKey) o;
return Objects.equal(this.priv, other.priv)
&& Objects.equal(this.pub, other.pub)
&& Objects.equal(this.creationTimeSeconds, other.creationTimeSeconds)
&& Objects.equal(this.keyCrypter, other.keyCrypter)
&& Objects.equal(this.encryptedPrivateKey, other.encryptedPrivateKey);
return Objects.equals(this.priv, other.priv)
&& Objects.equals(this.pub, other.pub)
&& Objects.equals(this.creationTimeSeconds, other.creationTimeSeconds)
&& Objects.equals(this.keyCrypter, other.keyCrypter)
&& Objects.equals(this.encryptedPrivateKey, other.encryptedPrivateKey);
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/bitcoinj/core/FilteredBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
Expand Down Expand Up @@ -136,7 +135,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(associatedTransactions, header, merkleTree);
return Objects.hash(associatedTransactions, header, merkleTree);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/GetUTXOsMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Objects;

/**
* <p>This command is supported only by <a href="http://github.com/bitcoinxt/bitcoinxt">Bitcoin XT</a> nodes, which
Expand Down Expand Up @@ -100,6 +100,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(includeMempool, outPoints);
return Objects.hash(includeMempool, outPoints);
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/InventoryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import java.util.Objects;

public class InventoryItem {

Expand Down Expand Up @@ -86,6 +86,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(type, hash);
return Objects.hash(type, hash);
}
}
10 changes: 7 additions & 3 deletions core/src/main/java/org/bitcoinj/core/NetworkParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.bitcoinj.core;

import org.bitcoinj.core.Block;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.VerificationException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import org.bitcoinj.net.discovery.*;
import org.bitcoinj.params.*;
import org.bitcoinj.script.*;
Expand Down Expand Up @@ -298,7 +300,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(getId());
return Objects.hash(getId());
}

/** Returns the network parameters for the given string ID or NULL if not recognized. */
Expand Down Expand Up @@ -686,7 +688,9 @@ public static enum ProtocolVersion {
SMNLE_VERSIONED(70228),
MNLISTDIFF_VERSION_ORDER(70229),
MNLISTDIFF_CHAINLOCKS(70230),
CURRENT(70230); //testnet is still 70228
CORE_20_1(70231),
CORE_21(70232),
CURRENT(70232); //testnet is still 70228

private final int bitcoinProtocol;

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/PartialMerkleTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static org.bitcoinj.core.Utils.*;
import com.google.common.base.Objects;

/**
* <p>A data structure that contains proofs of block inclusion for one or more transactions, in an efficient manner.</p>
Expand Down Expand Up @@ -275,7 +275,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(transactionCount, hashes, Arrays.hashCode(matchedChildBits));
return Objects.hash(transactionCount, hashes, Arrays.hashCode(matchedChildBits));
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/java/org/bitcoinj/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;

import org.bitcoinj.coinjoin.CoinJoinQueue;
import org.bitcoinj.core.listeners.*;
import org.bitcoinj.evolution.SimplifiedMasternodeListDiff;
Expand All @@ -42,10 +39,12 @@
import org.bitcoinj.wallet.Wallet;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -1502,7 +1501,7 @@ protected void processInv(InventoryMessage inv) {
}

// The New InstantSendLock (ISLOCK)
if(context.instantSendManager != null && context.instantSendManager.isNewInstantSendEnabled() &&
if(context.instantSendManager != null && context.instantSendManager.isInstantSendEnabled() &&
context.masternodeSync != null && context.masternodeSync.hasSyncFlag(MasternodeSync.SYNC_FLAGS.SYNC_INSTANTSENDLOCKS)) {
it = instantSendLocks.iterator();
while (it.hasNext()) {
Expand Down Expand Up @@ -1764,7 +1763,7 @@ private void blockChainDownloadLocked(Sha256Hash toHash) {
StoredBlock chainHead = blockChain.getChainHead();
Sha256Hash chainHeadHash = chainHead.getHeader().getHash();
// Did we already make this request? If so, don't do it again.
if (Objects.equal(lastGetBlocksBegin, chainHeadHash) && Objects.equal(lastGetBlocksEnd, toHash)) {
if (Objects.equals(lastGetBlocksBegin, chainHeadHash) && Objects.equals(lastGetBlocksEnd, toHash)) {
log.info("blockChainDownloadLocked({}): ignoring duplicated request: {}", toHash, chainHeadHash);
for (Sha256Hash hash : pendingBlockDownloads)
log.info("Pending block download: {}", hash);
Expand Down Expand Up @@ -1841,7 +1840,7 @@ private void blockChainHeaderDownloadLocked(Sha256Hash toHash) {
StoredBlock chainHead = headerChain.getChainHead();
Sha256Hash chainHeadHash = chainHead.getHeader().getHash();
// Did we already make this request? If so, don't do it again.
if (Objects.equal(lastGetHeadersBegin, chainHeadHash) && Objects.equal(lastGetHeadersEnd, toHash)) {
if (Objects.equals(lastGetHeadersBegin, chainHeadHash) && Objects.equals(lastGetHeadersEnd, toHash)) {
log.info("blockChainDownloadLocked({}): ignoring duplicated request: {}", toHash, chainHeadHash);
for (Sha256Hash hash : pendingBlockDownloads)
log.info("Pending block download: {}", hash);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/PeerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -209,7 +209,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(addr, port, time, services);
return Objects.hash(addr, port, time, services);
}

public InetSocketAddress toSocketAddress() {
Expand Down
21 changes: 7 additions & 14 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.annotations.*;
import com.google.common.base.*;
import com.google.common.collect.*;
import com.google.common.primitives.*;
import com.google.common.util.concurrent.*;
import net.jcip.annotations.*;
import org.bitcoinj.core.listeners.*;
Expand Down Expand Up @@ -409,13 +408,9 @@ private PeerGroup(Context context, @Nullable AbstractBlockChain chain, @Nullable
public int compare(PeerAddress a, PeerAddress b) {
checkState(lock.isHeldByCurrentThread());
int result = backoffMap.get(a).compareTo(backoffMap.get(b));
if (result != 0)
return result;
result = Ints.compare(getPriority(a), getPriority(b));
if (result != 0)
return result;
// Sort by port if otherwise equals - for testing
result = Ints.compare(a.getPort(), b.getPort());
if (result == 0)
result = Integer.compare(a.getPort(), b.getPort());
return result;
}
});
Expand Down Expand Up @@ -557,8 +552,6 @@ public void go() {
discoverySuccess = discoverPeers() > 0;
}

long retryTime;
PeerAddress addrToTry;
lock.lock();
try {
if (doDiscovery) {
Expand All @@ -582,12 +575,12 @@ public void go() {
// were given a fixed set of addresses in some test scenario.
}
return;
} else {
do {
addrToTry = inactives.poll();
} while (ipv6Unreachable && addrToTry.getAddr() instanceof Inet6Address);
retryTime = backoffMap.get(addrToTry).getRetryTime();
}
PeerAddress addrToTry;
do {
addrToTry = inactives.poll();
} while (ipv6Unreachable && addrToTry.getAddr() instanceof Inet6Address);
long retryTime = backoffMap.get(addrToTry).getRetryTime();
retryTime = Math.max(retryTime, groupBackoff.getRetryTime());
if (retryTime > now) {
long delay = retryTime - now;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;

import com.google.common.base.Objects;
import com.google.common.primitives.UnsignedBytes;
import static com.google.common.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -59,7 +59,7 @@ public final NetworkParameters getParameters() {

@Override
public int hashCode() {
return Objects.hashCode(params, Arrays.hashCode(bytes));
return Objects.hash(params, Arrays.hashCode(bytes));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/RejectMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Objects;

/**
* <p>A message sent by nodes when a message we sent was rejected (ie a transaction had too little fee/was invalid/etc).</p>
Expand Down Expand Up @@ -164,6 +164,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(message, code, reason, messageHash);
return Objects.hash(message, code, reason, messageHash);
}
}
Loading

0 comments on commit d6b256d

Please sign in to comment.