Skip to content

Commit

Permalink
Merge pull request #1650 from ripcurlx/create-mono-repository
Browse files Browse the repository at this point in the history
Create mono repository
  • Loading branch information
ripcurlx authored Sep 5, 2018
2 parents 6d1c03b + 4f7161a commit 708d9a4
Show file tree
Hide file tree
Showing 1,933 changed files with 133,155 additions and 154 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/docs
/log
/bin
/out
*/docs
*/log
*/bin
*/out
.idea
!.idea/copyright/bisq_Affero_GPLv3.xml
!.idea/copyright/profiles_settings.xml
Expand Down
38 changes: 38 additions & 0 deletions assets/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'java'
id 'maven'
}

group 'network.bisq'
version '-SNAPSHOT'

sourceCompatibility = 1.8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

javadoc {
options.author = true
options.addStringOption('Xdoclint:none', '-quiet')
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocJar
}

repositories {
jcenter()
maven { url 'https://jitpack.io' }
}

dependencies {
compile project(':common')
compile 'commons-codec:commons-codec:1.9'
testCompile 'junit:junit:4.12'
}
62 changes: 62 additions & 0 deletions assets/src/main/java/bisq/asset/AbstractAsset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset;

import static org.apache.commons.lang3.Validate.notBlank;
import static org.apache.commons.lang3.Validate.notNull;

/**
* Abstract base class for {@link Asset} implementations. Most implementations should not
* extend this class directly, but should rather extend {@link Coin}, {@link Token} or one
* of their subtypes.
*
* @author Chris Beams
* @since 0.7.0
*/
public abstract class AbstractAsset implements Asset {

private final String name;
private final String tickerSymbol;
private final AddressValidator addressValidator;

public AbstractAsset(String name, String tickerSymbol, AddressValidator addressValidator) {
this.name = notBlank(name);
this.tickerSymbol = notBlank(tickerSymbol);
this.addressValidator = notNull(addressValidator);
}

@Override
public final String getName() {
return name;
}

@Override
public final String getTickerSymbol() {
return tickerSymbol;
}

@Override
public final AddressValidationResult validateAddress(String address) {
return addressValidator.validate(address);
}

@Override
public String toString() {
return getClass().getName();
}
}
73 changes: 73 additions & 0 deletions assets/src/main/java/bisq/asset/AddressValidationResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset;

/**
* Value object representing the result of validating an {@link Asset} address. Various
* factory methods are provided for typical use cases.
*
* @author Chris Beams
* @since 0.7.0
* @see Asset#validateAddress(String)
*/
public class AddressValidationResult {

private static AddressValidationResult VALID_ADDRESS = new AddressValidationResult(true, "", "");

private final boolean isValid;
private final String message;
private final String i18nKey;

private AddressValidationResult(boolean isValid, String message, String i18nKey) {
this.isValid = isValid;
this.message = message;
this.i18nKey = i18nKey;
}

public boolean isValid() {
return isValid;
}

public String getI18nKey() {
return i18nKey;
}

public String getMessage() {
return message;
}

public static AddressValidationResult validAddress() {
return VALID_ADDRESS;
}

public static AddressValidationResult invalidAddress(Throwable cause) {
return invalidAddress(cause.getMessage());
}

public static AddressValidationResult invalidAddress(String cause) {
return invalidAddress(cause, "validation.altcoin.invalidAddress");
}

public static AddressValidationResult invalidAddress(String cause, String i18nKey) {
return new AddressValidationResult(false, cause, i18nKey);
}

public static AddressValidationResult invalidStructure() {
return invalidAddress("", "validation.altcoin.wrongStructure");
}
}
29 changes: 29 additions & 0 deletions assets/src/main/java/bisq/asset/AddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset;

/**
* An {@link Asset} address validation function.
*
* @author Chris Beams
* @since 0.7.0
*/
public interface AddressValidator {

AddressValidationResult validate(String address);
}
46 changes: 46 additions & 0 deletions assets/src/main/java/bisq/asset/Asset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset;

/**
* Interface representing a given ("crypto") asset in its most abstract form, having a
* {@link #getName() name}, eg "Bitcoin", a {@link #getTickerSymbol() ticker symbol},
* eg "BTC", and an address validation function. Together, these properties represent
* the minimum information and functionality required to register and trade an asset on
* the Bisq network.
* <p>
* Implementations typically extend either the {@link Coin} or {@link Token} base
* classes, and must be registered in the {@code META-INF/services/bisq.asset.Asset} file
* in order to be available in the {@link AssetRegistry} at runtime.
*
* @author Chris Beams
* @since 0.7.0
* @see AbstractAsset
* @see Coin
* @see Token
* @see Erc20Token
* @see AssetRegistry
*/
public interface Asset {

String getName();

String getTickerSymbol();

AddressValidationResult validateAddress(String address);
}
46 changes: 46 additions & 0 deletions assets/src/main/java/bisq/asset/AssetRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Stream;

/**
* Provides {@link Stream}-based access to {@link Asset} implementations registered in
* the {@code META-INF/services/bisq.asset.Asset} provider-configuration file.
*
* @author Chris Beams
* @since 0.7.0
* @see ServiceLoader
*/
public class AssetRegistry {

private static final List<Asset> registeredAssets = new ArrayList<>();

static {
for (Asset asset : ServiceLoader.load(Asset.class)) {
registeredAssets.add(asset);
}
}

public Stream<Asset> stream() {
return registeredAssets.stream();
}
}
54 changes: 54 additions & 0 deletions assets/src/main/java/bisq/asset/Base58BitcoinAddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.asset;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.params.MainNetParams;

/**
* {@link AddressValidator} for Base58-encoded Bitcoin addresses.
*
* @author Chris Beams
* @since 0.7.0
* @see org.bitcoinj.core.Address#fromBase58(NetworkParameters, String)
*/
public class Base58BitcoinAddressValidator implements AddressValidator {

private final NetworkParameters networkParameters;

public Base58BitcoinAddressValidator() {
this(MainNetParams.get());
}

public Base58BitcoinAddressValidator(NetworkParameters networkParameters) {
this.networkParameters = networkParameters;
}

@Override
public AddressValidationResult validate(String address) {
try {
Address.fromBase58(networkParameters, address);
} catch (AddressFormatException ex) {
return AddressValidationResult.invalidAddress(ex);
}

return AddressValidationResult.validAddress();
}
}
Loading

0 comments on commit 708d9a4

Please sign in to comment.