Migration to Java 11

Updated pom.xml.
Updated dependencies, including various minor code mods, esp. bitcoin-related.

Starts up and talks to Java 8 nodes!

Dev environment should be at least Eclipse 4.11 with m2e 1.9.1+
This commit is contained in:
catbref 2019-09-30 18:01:23 +01:00
parent b95eea6763
commit 568a1f8a30
7 changed files with 57 additions and 43 deletions

54
pom.xml
View File

@ -6,20 +6,23 @@
<version>0.9</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bouncycastle.version>1.61</bouncycastle.version>
<dagger.version>1.2.2</dagger.version>
<hsqldb.version>2.5.0</hsqldb.version>
<sqltool.version>2.4.1</sqltool.version>
<jetty.version>9.4.17.v20190418</jetty.version>
<jersey.version>2.27</jersey.version>
<log4j.version>2.11.0</log4j.version>
<slf4j.version>1.7.12</slf4j.version>
<swagger-api.version>2.0.6</swagger-api.version>
<swagger-ui.version>3.19.0</swagger-ui.version>
<felix-bundle-plugin.version>3.5.0</felix-bundle-plugin.version>
<package-info-maven-plugin.version>1.1.0</package-info-maven-plugin.version>
<bitcoin.version>0.15.4</bitcoin.version>
<bouncycastle.version>1.63</bouncycastle.version>
<build.timestamp>${maven.build.timestamp}</build.timestamp>
<commons-net.version>3.6</commons-net.version>
<commons-text.version>1.8</commons-text.version>
<dagger.version>1.2.2</dagger.version>
<guava.version>28.1-jre</guava.version>
<hsqldb.version>2.5.0</hsqldb.version>
<hsqldb-sqltool.version>2.5.0</hsqldb-sqltool.version>
<jersey.version>2.29.1</jersey.version>
<jetty.version>9.4.20.v20190813</jetty.version>
<log4j.version>2.12.1</log4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.12</slf4j.version>
<swagger-api.version>2.0.9</swagger-api.version>
<swagger-ui.version>3.23.8</swagger-ui.version>
<package-info-maven-plugin.version>1.1.0</package-info-maven-plugin.version>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
@ -32,11 +35,18 @@
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<!-- unpack swagger-ui to target folder -->
@ -309,7 +319,7 @@
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>sqltool</artifactId>
<version>${sqltool.version}</version>
<version>${hsqldb-sqltool.version}</version>
<scope>test</scope>
</dependency>
<!-- CIYAM AT (automated transactions) -->
@ -322,7 +332,7 @@
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.14.7</version>
<version>${bitcoin.version}</version>
</dependency>
<!-- Utilities -->
<dependency>
@ -333,7 +343,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.4</version>
<version>${commons-text.version}</version>
</dependency>
<!-- For bitset/bitmap compression -->
<dependency>
@ -356,12 +366,12 @@
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
<version>${commons-net.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
<version>${guava.version}</version>
</dependency>
<!-- Logging: log4j2 -->
<dependency>

View File

@ -226,7 +226,7 @@ public class BTC {
protected Wallet createEmptyWallet() {
ECKey dummyKey = new ECKey();
KeyChainGroup keyChainGroup = new KeyChainGroup(params);
KeyChainGroup keyChainGroup = KeyChainGroup.createBasic(params);
keyChainGroup.importKeys(dummyKey);
Wallet wallet = new Wallet(params, keyChainGroup);
@ -242,12 +242,12 @@ public class BTC {
WalletCoinsReceivedEventListener coinsReceivedListener = new WalletCoinsReceivedEventListener() {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
System.out.println("Coins received via transaction " + tx.getHashAsString());
System.out.println("Coins received via transaction " + tx.getTxId().toString());
}
};
wallet.addCoinsReceivedEventListener(coinsReceivedListener);
Address address = Address.fromBase58(params, base58Address);
Address address = Address.fromString(params, base58Address);
wallet.addWatchedAddress(address, startTime);
StoredBlock checkpoint = manager.getCheckpointBefore(startTime);

View File

@ -385,7 +385,6 @@ public class HSQLDBRepository implements Repository {
* @return ResultSet, or null if there are no found rows
* @throws SQLException
*/
@SuppressWarnings("resource")
public ResultSet checkedExecute(String sql, Object... objects) throws SQLException {
PreparedStatement preparedStatement = this.prepareStatement(sql);

View File

@ -3,6 +3,7 @@ package org.qora.transaction;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@ -347,7 +348,7 @@ public abstract class Transaction {
if (recommendedFee.compareTo(BlockChain.getInstance().getUnitFee()) <= 0) {
recommendedFee = BlockChain.getInstance().getUnitFee();
} else {
recommendedFee = recommendedFee.setScale(0, BigDecimal.ROUND_UP);
recommendedFee = recommendedFee.setScale(0, RoundingMode.CEILING);
}
return recommendedFee.setScale(8);

View File

@ -13,6 +13,7 @@ import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Transaction;
@ -24,6 +25,7 @@ import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.Script.ScriptType;
import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptChunk;
import org.bitcoinj.script.ScriptOpCodes;
@ -120,11 +122,11 @@ public class BTCACCTTests {
kit.wallet().importKey(recipientKey);
byte[] senderPubKey = senderKey.getPubKey();
System.out.println("Sender address: " + senderKey.toAddress(params).toBase58());
System.out.println("Sender address: " + Address.fromKey(params, senderKey, ScriptType.P2PKH).toString());
System.out.println("Sender pubkey: " + HashCode.fromBytes(senderPubKey).toString());
byte[] recipientPubKey = recipientKey.getPubKey();
System.out.println("Recipient address: " + recipientKey.toAddress(params).toBase58());
System.out.println("Recipient address: " + Address.fromKey(params, recipientKey, ScriptType.P2PKH).toString());
System.out.println("Recipient pubkey: " + HashCode.fromBytes(recipientPubKey).toString());
byte[] redeemScriptBytes = buildRedeemScript(secret, senderPubKey, recipientPubKey, lockTime);
@ -132,20 +134,20 @@ public class BTCACCTTests {
byte[] redeemScriptHash = hash160(redeemScriptBytes);
Address p2shAddress = Address.fromP2SHHash(params, redeemScriptHash);
System.out.println("P2SH address: " + p2shAddress.toBase58());
Address p2shAddress = LegacyAddress.fromScriptHash(params, redeemScriptHash);
System.out.println("P2SH address: " + p2shAddress.toString());
// Send amount to P2SH address
Transaction fundingTransaction = buildFundingTransaction(params, Sha256Hash.wrap(prevTxHash), prevTxOutputIndex, prevTxBalance, senderKey,
sendValue.add(fee), redeemScriptHash);
System.out.println("Sending " + sendValue.add(fee).toPlainString() + " to " + p2shAddress.toBase58());
System.out.println("Sending " + sendValue.add(fee).toPlainString() + " to " + p2shAddress.toString());
if (!usePreviousFundingTx)
broadcastWithConfirmation(kit, fundingTransaction);
if (doRefundNotRedeem) {
// Refund
System.out.println("Refunding " + sendValue.toPlainString() + " back to " + senderKey.toAddress(params));
System.out.println("Refunding " + sendValue.toPlainString() + " back to " + Address.fromKey(params, senderKey, ScriptType.P2PKH).toString());
now = System.currentTimeMillis() / 1000L;
long refundLockTime = now - 60 * 30; // 30 minutes in the past, needs to before 'now' and before "median block time" (median of previous 11 block
@ -158,7 +160,7 @@ public class BTCACCTTests {
broadcastWithConfirmation(kit, refundTransaction);
} else {
// Redeem
System.out.println("Redeeming " + sendValue.toPlainString() + " to " + recipientKey.toAddress(params));
System.out.println("Redeeming " + sendValue.toPlainString() + " to " + Address.fromKey(params, recipientKey, ScriptType.P2PKH).toString());
TransactionOutPoint fundingOutPoint = new TransactionOutPoint(params, 0, fundingTransaction);
Transaction redeemTransaction = buildRedeemTransaction(params, fundingOutPoint, recipientKey, sendValue, secret, redeemScriptBytes);
@ -168,7 +170,7 @@ public class BTCACCTTests {
kit.wallet().cleanup();
for (Transaction transaction : kit.wallet().getTransactionPool(Pool.PENDING).values())
System.out.println("Pending tx: " + transaction.getHashAsString());
System.out.println("Pending tx: " + transaction.getTxId().toString());
}
private static final byte[] redeemScript1 = HashCode.fromString("76a820").asBytes();
@ -211,11 +213,11 @@ public class BTCACCTTests {
// Fixed amount to P2SH
fundingTransaction.addOutput(value, ScriptBuilder.createP2SHOutputScript(redeemScriptHash));
// Change to sender
fundingTransaction.addOutput(balance.minus(value).minus(fee), ScriptBuilder.createOutputScript(sigKey.toAddress(params)));
fundingTransaction.addOutput(balance.minus(value).minus(fee), ScriptBuilder.createOutputScript(Address.fromKey(params, sigKey, ScriptType.P2PKH)));
// Input
// We create fake "to address" scriptPubKey for prev tx so our spending input is P2PKH type
Script fakeScriptPubKey = ScriptBuilder.createOutputScript(sigKey.toAddress(params));
Script fakeScriptPubKey = ScriptBuilder.createOutputScript(Address.fromKey(params, sigKey, ScriptType.P2PKH));
TransactionOutPoint prevOut = new TransactionOutPoint(params, outputIndex, prevTxHash);
fundingTransaction.addSignedInput(prevOut, fakeScriptPubKey, sigKey);
@ -228,7 +230,7 @@ public class BTCACCTTests {
redeemTransaction.setVersion(2);
// Outputs
redeemTransaction.addOutput(value, ScriptBuilder.createOutputScript(recipientKey.toAddress(params)));
redeemTransaction.addOutput(value, ScriptBuilder.createOutputScript(Address.fromKey(params, recipientKey, ScriptType.P2PKH)));
// Input
byte[] recipientPubKey = recipientKey.getPubKey();
@ -265,7 +267,7 @@ public class BTCACCTTests {
refundTransaction.setVersion(2);
// Outputs
refundTransaction.addOutput(value, ScriptBuilder.createOutputScript(senderKey.toAddress(params)));
refundTransaction.addOutput(value, ScriptBuilder.createOutputScript(Address.fromKey(params, senderKey, ScriptType.P2PKH)));
// Input
byte[] recipientPubKey = senderKey.getPubKey();
@ -299,7 +301,7 @@ public class BTCACCTTests {
}
private void broadcastWithConfirmation(WalletAppKit kit, Transaction transaction) {
System.out.println("Broadcasting tx: " + transaction.getHashAsString());
System.out.println("Broadcasting tx: " + transaction.getTxId().toString());
System.out.println("TX hex: " + HashCode.fromBytes(transaction.bitcoinSerialize()).toString());
System.out.println("Number of connected peers: " + kit.peerGroup().numConnectedPeers());
@ -312,7 +314,7 @@ public class BTCACCTTests {
}
// wait for confirmation
System.out.println("Waiting for confirmation of tx: " + transaction.getHashAsString());
System.out.println("Waiting for confirmation of tx: " + transaction.getTxId().toString());
try {
transaction.getConfidence().getDepthFuture(1).get();
@ -320,7 +322,7 @@ public class BTCACCTTests {
throw new RuntimeException("Transaction confirmation failed", e);
}
System.out.println("Confirmed tx: " + transaction.getHashAsString());
System.out.println("Confirmed tx: " + transaction.getTxId().toString());
}
/** Convert int to little-endian byte array */

View File

@ -78,6 +78,7 @@ public class ByteArrayTests {
}
@Test
@SuppressWarnings("unlikely-arg-type")
public void testCompareBoxedWithPrimitive() {
byte[] testValue = testValues.get(0);
ByteArray ba1 = new ByteArray(testValue);
@ -90,6 +91,7 @@ public class ByteArrayTests {
}
@Test
@SuppressWarnings("unlikely-arg-type")
public void testMapContainsKey() {
Map<ByteArray, String> testMap = new HashMap<>();
fillMap(testMap);

View File

@ -34,7 +34,7 @@ public class ApiCommon extends Common {
public static Object buildResource(Class<?> resourceClass) {
try {
Object resource = resourceClass.newInstance();
Object resource = resourceClass.getDeclaredConstructor().newInstance();
Field requestField = resourceClass.getDeclaredField("request");
requestField.setAccessible(true);