Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to bitcoinj 0.17-alpha1, ConsensusJ 0.7.0-alpha1 #228

Merged
merged 7 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/omnij-test-design-patterns.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
OmniJ Test Architecture and Design Patterns
============================================
= OmniJ Test Architecture and Design Patterns
:toc:
:toc-placement: manual
:numbered:
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ omnijVersion = 0.7.0-SNAPSHOT

useMavenLocal = false

bitcoinjVersion = 0.16.2
consensusjVersion = 0.6.5
bitcoinjVersion = 0.17-alpha1
consensusjVersion = 0.7.0-alpha1
slf4jVersion = 2.0.7
groovyVersion = 4.0.12
spockVersion = 2.3-groovy-4.0
junitJupiterVersion = 5.8.1
junitJupiterVersion = 5.9.2

rpcTestUser=bitcoinrpc
rpcTestPassword=pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void run(OmniCoreCLICall call) throws IOException, InterruptedException,
tool1 = new OmniCoreConsensusTool((OmniClient) call.rpcClient());
if (line.hasOption("omnicore-url")) {
uri2 = URI.create(line.getOptionValue("omnicore-url"));
tool2 = new OmniCoreConsensusTool(call.getRPCConfig().getNetParams(), uri2);
tool2 = new OmniCoreConsensusTool(call.getRPCConfig().network(), uri2);
} else if (line.hasOption("omniwallet-url")) {
uri2 = URI.create(line.getOptionValue("omniwallet-url"));
tool2 = new OmniwalletConsensusTool(uri2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package foundation.omni.cli;

import foundation.omni.netapi.omnicore.RxOmniClient;
import org.consensusj.bitcoin.jsonrpc.RpcConfig;
import foundation.omni.rpc.OmniClient;
import org.consensusj.bitcoin.cli.BitcoinCLITool;
Expand All @@ -23,6 +22,6 @@ public OmniCoreCLICall(BitcoinCLITool tool, PrintStream out, PrintStream err, St

@Override
public OmniClient createClient(SSLSocketFactory sslSocketFactory, RpcConfig config) {
return new OmniClient(sslSocketFactory, config.getNetParams(), config.getURI(), config.getUsername(), config.getPassword(), false, false);
return new OmniClient(sslSocketFactory, config.network(), config.getURI(), config.getUsername(), config.getPassword(), false, false);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package foundation.omni;

import org.bitcoinj.core.Address;
import org.bitcoinj.base.Address;

/**
* Balance entry for an Address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package foundation.omni;

import org.bitcoinj.core.Coin;
import org.bitcoinj.base.Coin;

import java.math.BigDecimal;
import java.math.MathContext;
Expand Down
2 changes: 1 addition & 1 deletion omnij-core/src/main/java/foundation/omni/OmniOutput.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package foundation.omni;

import org.bitcoinj.core.Address;
import org.bitcoinj.base.Address;

/**
* A record-like container for an amount and a destination address. Intended for {@code omni_sendmany}.
Expand Down
2 changes: 1 addition & 1 deletion omnij-core/src/main/java/foundation/omni/OmniValue.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package foundation.omni;

import org.bitcoinj.core.Coin;
import org.bitcoinj.base.Coin;

import javax.money.NumberValue;
import java.math.BigDecimal;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package foundation.omni.address;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.params.MainNetParams;
import foundation.omni.net.OmniNetwork;
import org.bitcoinj.base.Address;
import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.LegacyAddress;

/**
* EXPERIMENTAL 2-way Conversion between MAINNET Omni and BTC Addresses
* @deprecated Omni "Safe" addresses will be implemented for Segwit and/or Taproot, not Base58
*/
@Deprecated
class OmniBase58LegacyAddressConverter {
static final OmniAddressMainNetParams omniParams = OmniAddressMainNetParams.get();
static final MainNetParams btcParams = MainNetParams.get();

static Address btcToOmni(Address btcAddress) {
return LegacyAddress.fromPubKeyHash(omniParams, btcAddress.getHash());
return LegacyAddress.fromPubKeyHash(OmniNetwork.MAINNET, btcAddress.getHash());
}

static Address omniToBTC(Address omniAddress) {
return LegacyAddress.fromPubKeyHash(btcParams, omniAddress.getHash());
return LegacyAddress.fromPubKeyHash(BitcoinNetwork.MAINNET, omniAddress.getHash());
}
}
Original file line number Diff line number Diff line change
@@ -1,101 +1,64 @@
package foundation.omni.address;

import org.bitcoinj.core.Bech32;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.SegwitAddress;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.Networks;
import org.bitcoinj.params.RegTestParams;
import org.bitcoinj.params.TestNet3Params;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import foundation.omni.net.OmniNetwork;
import org.bitcoinj.base.Bech32;
import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.SegwitAddress;

/**
* Convert between Bitcoin and Omni Bech32 Segwit addresses
* Adds Omni networks to bitcoinj's {@link Networks} registry
* Bitcoin: bc1xxxx
* Omni: om1xxxx
*/
class OmniSegwitAddressConverter {
/**
* Default set of Omni Networks for Omni Address parsing
* (We don't include RegTest by default because RegTest and TestNet addresses use the same
* prefix in Base58 format)
*/
public static final Set<NetworkParameters> defaultOmniNetworks =
unmodifiableSet(OmniAddressMainNetParams.get(), OmniAddressTestNetParams.get());

static {
// TODO: Maybe we don't want to modify bitcoinj's list of networks unless explicitly configured?
Networks.register(defaultOmniNetworks);
}
public class OmniSegwitAddressConverter {

public static SegwitAddress btcToOmni(SegwitAddress btcAddress) {
NetworkParameters omniParams = btcParamsToOmniParams(btcAddress.getParameters());
OmniNetwork omniNet = btcNetworkToOmniNetwork((BitcoinNetwork) btcAddress.network());
Bech32.Bech32Data btcBech32Data = Bech32.decode(btcAddress.toBech32());
String omniAddressString = Bech32.encode(Bech32.Encoding.BECH32, omniParams.getSegwitAddressHrp(), btcBech32Data.data);
return SegwitAddress.fromBech32(omniParams, omniAddressString);
String omniAddressString = Bech32.encode(Bech32.Encoding.BECH32, omniNet.segwitAddressHrp(), btcBech32Data.data);
return (SegwitAddress) OmniNetwork.addressParser.parseAddress(omniAddressString, omniNet);
}

public static SegwitAddress btcToOmni(String btcAddressString) {
SegwitAddress btcAddress = SegwitAddress.fromBech32(null, btcAddressString);
return btcToOmni(btcAddress);
}

public static SegwitAddress btcToOmni(NetworkParameters btcParams, String btcAddressString) {
SegwitAddress btcAddress = SegwitAddress.fromBech32(btcParams, btcAddressString);
SegwitAddress btcAddress = (SegwitAddress) OmniNetwork.addressParser.parseAddressAnyNetwork(btcAddressString);
return btcToOmni(btcAddress);
}

public static SegwitAddress omniToBtc(SegwitAddress omniAddress) {
NetworkParameters btcParams = omniParamsToBtcParams(omniAddress.getParameters());
BitcoinNetwork btcNet = omniNetworkToBtcNetwork((OmniNetwork) omniAddress.network());
Bech32.Bech32Data btcBech32Data = Bech32.decode(omniAddress.toBech32());
String btcAddressString = Bech32.encode(Bech32.Encoding.BECH32, btcParams.getSegwitAddressHrp(), btcBech32Data.data);
return SegwitAddress.fromBech32(btcParams, btcAddressString);
String btcAddressString = Bech32.encode(Bech32.Encoding.BECH32, btcNet.segwitAddressHrp(), btcBech32Data.data);
return (SegwitAddress) OmniNetwork.addressParser.parseAddress(btcAddressString, btcNet);
}

public static SegwitAddress omniToBtc(String omniAddressString) {
SegwitAddress btcAddress = SegwitAddress.fromBech32(null, omniAddressString);
return omniToBtc(btcAddress);
SegwitAddress omniAddress = (SegwitAddress) OmniNetwork.addressParser.parseAddressAnyNetwork(omniAddressString);
return omniToBtc(omniAddress);
}

public static SegwitAddress omniToBtc(NetworkParameters btcParams, String btcAddressString) {
SegwitAddress btcAddress = SegwitAddress.fromBech32(btcParams, btcAddressString);
return omniToBtc(btcAddress);
}

static private NetworkParameters btcParamsToOmniParams(NetworkParameters btcParams) {
switch (btcParams.getId()) {
case NetworkParameters.ID_MAINNET:
return OmniAddressMainNetParams.get();
case NetworkParameters.ID_TESTNET:
return OmniAddressTestNetParams.get();
case NetworkParameters.ID_REGTEST:
return OmniAddressRegTestParams.get();
static private OmniNetwork btcNetworkToOmniNetwork(BitcoinNetwork network) {
switch (network) {
case MAINNET:
return OmniNetwork.MAINNET;
case TESTNET:
return OmniNetwork.TESTNET;
case REGTEST:
return OmniNetwork.REGTEST;
default:
throw new IllegalArgumentException("Unspported network");
}
}

static private NetworkParameters omniParamsToBtcParams(NetworkParameters omniParams) {
switch (omniParams.getId()) {
case NetworkParameters.ID_MAINNET:
return MainNetParams.get();
case NetworkParameters.ID_TESTNET:
return TestNet3Params.get();
case NetworkParameters.ID_REGTEST:
return RegTestParams.get();
static private BitcoinNetwork omniNetworkToBtcNetwork(OmniNetwork network) {
switch (network) {
case MAINNET:
return BitcoinNetwork.MAINNET;
case TESTNET:
return BitcoinNetwork.TESTNET;
case REGTEST:
return BitcoinNetwork.REGTEST;
default:
throw new IllegalArgumentException("Unspported network");
}
}

// Create an unmodifiable set of NetworkParameters from an array/varargs
private static Set<NetworkParameters> unmodifiableSet(NetworkParameters... ts) {
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ts)));
}

}
2 changes: 1 addition & 1 deletion omnij-core/src/main/java/foundation/omni/net/MoneyMan.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package foundation.omni.net;

import foundation.omni.OmniDivisibleValue;
import org.bitcoinj.core.Coin;
import org.bitcoinj.base.Coin;

/**
* Definitions for MoneyMan address functionality on TestNet and RegTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package foundation.omni.net;

import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.base.exceptions.AddressFormatException;
import org.bitcoinj.params.MainNetParams;

/**
* Omni Protocol parameters for Bitcoin MainNet
*/
public class OmniMainNetParams extends OmniNetworkParameters {
private static final String ExodusAddress = "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P";
public static final Integer FIRST_EXODUS_BLOCK = 249498;
public static final Integer LAST_EXODUS_BLOCK = 255365;
public static final Integer POST_EXODUS_BLOCK = 255366;
Expand All @@ -19,7 +17,7 @@ private OmniMainNetParams() {
super();
params = MainNetParams.get();
try {
exodusAddress = LegacyAddress.fromString(params, ExodusAddress);
exodusAddress = OmniNetwork.MAINNET.exodusAddress();
} catch (AddressFormatException e) {
exodusAddress = null;
}
Expand Down
Loading