Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Redesign asset listing and validation infrastructure #32

Merged
merged 106 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
ba4ac0f
Move altcoin address validators to separate classes.
Mar 23, 2018
856669a
AssetProvider
Mar 23, 2018
cb6c579
AssetProviderRegistry
Mar 23, 2018
c949a24
Adjust Bch and Ella asset providers names.
Mar 23, 2018
695053d
Organize imports
cbeams Mar 26, 2018
cab46e2
Redesign asset listing and validation infrastructure
cbeams Mar 26, 2018
9026200
Extract BSQ
cbeams Mar 27, 2018
9fbed62
Extract Litecoin
cbeams Mar 27, 2018
c2c7e40
Extract Dogecoin
cbeams Mar 27, 2018
bd37996
Extract Dash
cbeams Mar 27, 2018
f07e13e
Remove unused imports
cbeams Mar 27, 2018
a08ac11
Extract PIVX
cbeams Mar 27, 2018
22cd1b4
Extract Internet of People
cbeams Mar 27, 2018
df0931e
Add missing license headers
cbeams Mar 27, 2018
981ca38
Extract Octocoin
cbeams Mar 27, 2018
49b119d
Extract Zcash
Mar 28, 2018
db51bf6
Extract Byteball
Mar 28, 2018
b516ce3
Extract Nxt
Mar 28, 2018
055acf2
Extract Decent
Mar 28, 2018
cfb2484
Extract Pranacoin
Mar 28, 2018
44fa4b2
Extract Wacoin
Mar 28, 2018
267261b
Extract ZenCash
Mar 28, 2018
956a5c6
Extract Cryptonite
Mar 28, 2018
f43d9fa
Extract Terracoin
Mar 28, 2018
0f5c3aa
Extract Internext
Mar 28, 2018
da62f3a
Extract Particl
Mar 28, 2018
8e67b8b
Extract Madcoin
Mar 28, 2018
64c947a
Extract Bitcoin Clashic
Mar 28, 2018
15d9376
Extract Bitcoin Gold
Mar 28, 2018
0f3bfbb
Extract Cagecoin
Mar 28, 2018
7d23f15
Extract Verify
Mar 28, 2018
56ec783
Extract Spectrecoin
Mar 28, 2018
c263cf5
Extract Wild Token
Mar 28, 2018
a33fe9d
Extract DeepOnion
Mar 28, 2018
2ee9f13
Extract Creativecoin
Mar 28, 2018
c11df7b
Extract Infinity Economics
Mar 28, 2018
159e975
Extract Better Betting
Mar 28, 2018
648c2e4
Extract Movement
Mar 28, 2018
5647b74
Extract RefToken
Mar 28, 2018
f79e055
Extract Stellite
Mar 28, 2018
f1d84c0
Extract Dai Stablecoin
Mar 28, 2018
e750c3f
Extract Yenten
Mar 28, 2018
ddc77e7
Extract BitDaric
Mar 28, 2018
4f3f151
Extract Obsidian
Mar 28, 2018
a0f5b0a
Extract Cassubian Detk
Mar 28, 2018
034d62a
Extract DigiMoney
Mar 28, 2018
0ad058c
Extract SpeedCash
Mar 28, 2018
335496b
Extract SOS Coin
Mar 28, 2018
c89fe8a
Extract AchieveCoin
Mar 28, 2018
934dbf6
Extract vDinar
Mar 29, 2018
731845e
Extract Anglecoin
Mar 29, 2018
aa22f58
Extract Dinero
Mar 29, 2018
1295c8d
Extract Strayacoin
Mar 29, 2018
560c588
Extract ROIcoin
Mar 29, 2018
98893f7
Extract WorldMobileCoin
Mar 29, 2018
80375e0
Extract Arto
Mar 29, 2018
0fc1a38
Extract Koto
Mar 29, 2018
97584a7
Extract Ubiq
Mar 29, 2018
686d134
Extract Qwark
Mar 29, 2018
3c1032a
Extract GeoCoin
Mar 29, 2018
d2ee3ec
Extract 10grans
Mar 29, 2018
03ed04e
Extract Phore
Mar 29, 2018
81f403d
Extract Octocoin
Mar 29, 2018
f0d0ab5
Extract Burstcoin
Mar 29, 2018
ecd6632
Extract Counterparty
Mar 29, 2018
af23a18
Extract DarkNet
Mar 29, 2018
ee2b77b
Extract Decred
Mar 29, 2018
53931a7
Extract DynamicCoin
Mar 29, 2018
1433c45
Extract Espers
Mar 29, 2018
b100c10
Extract EtherClassic
Mar 29, 2018
a7e2fdc
Extract Gridcoin
Mar 29, 2018
04c2e35
Extract LBRY
Mar 29, 2018
d84bf70
Extract Lisk
Mar 29, 2018
eba4552
Extract MaidSafeCoin
Mar 29, 2018
d114c58
Extract Monero
Mar 29, 2018
90e8043
Extract MyceliumToken
Mar 29, 2018
c22021e
Extract NavCoin
Mar 29, 2018
ca8d348
Extract Namecoin
Mar 29, 2018
0cecac6
Extract NuBits
Mar 29, 2018
9b70137
Extract PascalCoin
Mar 29, 2018
0749774
Extract PepeCash
Mar 29, 2018
7998747
Extract PostCoin
Mar 29, 2018
375a2f0
Extract ReddCoin
Mar 29, 2018
fa1e3b3
Extract SafeFileSystemCoin
Mar 29, 2018
3bae6ec
Extract Siacoin
Mar 29, 2018
239ce5a
Extract Siafund
Mar 29, 2018
66f7b51
Extract Sibcoin
Mar 29, 2018
e887223
Extract STEEM
Mar 29, 2018
1ca2535
Extract Unobtanium
Mar 29, 2018
5b061e2
Extract Zcoin
Mar 29, 2018
393e090
Fuse sorting into stream for CurrencyUtil.
Mar 29, 2018
f49dc8d
Extract Ellaism
Mar 29, 2018
0eae155
Add missing license headers
cbeams Apr 3, 2018
f8796f7
Remove blank lines between closing braces
cbeams Apr 3, 2018
0551d22
Add blank lines where appropriate
cbeams Apr 3, 2018
c1d5aac
Wrap code at 120 characters
cbeams Apr 3, 2018
b73fa60
Remove unnecessary else(if) clauses after a return
cbeams Apr 3, 2018
7ad70c3
Simplify BitcoinClashic
cbeams Apr 3, 2018
cc5edbe
Improve AbstractAssetTest#testPresenceInAssetRegistry
cbeams Apr 3, 2018
9c7d19e
Sort META-INF/services/bisq.asset.Asset
cbeams Apr 3, 2018
e47d59f
Polish Byteball
cbeams Apr 3, 2018
1d040a2
Polish CurrencyUtil
cbeams Apr 3, 2018
9dc5b8d
Polish AltCoinAddressValidator
cbeams Apr 3, 2018
d7537ae
Polish AddressValidationResult
cbeams Apr 3, 2018
990070f
Add Javadoc for bisq.asset types
cbeams Apr 3, 2018
2f231d3
Document META-INF/services/bisq.asset.Asset
cbeams Apr 3, 2018
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
2 changes: 2 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/main/java/bisq/asset/AbstractAsset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package bisq.asset;

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

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);
}
}
65 changes: 65 additions & 0 deletions src/main/java/bisq/asset/AddressValidationResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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;

public class AddressValidationResult {

public static AddressValidationResult VALID = new AddressValidationResult(true);

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

private AddressValidationResult(boolean isValid) {
this.isValid = isValid;
}

private AddressValidationResult(boolean isValid, String message, String i18nKey) {
this(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;
}

public static AddressValidationResult invalidStructure() {
return new AddressValidationResult(false, "", "validation.altcoin.wrongStructure");
}

public static AddressValidationResult invalidAddress(String cause) {
return new AddressValidationResult(false, cause, "validation.altcoin.invalidAddress");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually want to avoid exposing the i18nKey as much as possible. I knew this would come up with the special zAddressesNotSupported key, and it's fine if you leave this here for now, but in general, I want to get internationalization stuff out of the picture at this low level. It requires some more thinking about exactly how to do this, though, so again, no worries, and you can just leave this for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove the translation from properties files next time I hit something like this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's the thing. We want to perfectly preserve the i18n behavior that's in place right now, but (ideally) remove any awareness of these keys from the low-level bisq.asset package. So you can leave everything as-is. It is definitely important for the moment, that these i18n keys do continue to get propagated up to the desktop layer in the meantime, though.


public static AddressValidationResult invalidAddress(Throwable cause) {
return invalidAddress(cause.getMessage());
}
}
23 changes: 23 additions & 0 deletions src/main/java/bisq/asset/AddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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;

public interface AddressValidator {

AddressValidationResult validate(String address);
}
10 changes: 10 additions & 0 deletions src/main/java/bisq/asset/Asset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package bisq.asset;

public interface Asset {

String getName();

String getTickerSymbol();

AddressValidationResult validateAddress(String address);
}
38 changes: 38 additions & 0 deletions src/main/java/bisq/asset/AssetRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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;

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();
}
}
47 changes: 47 additions & 0 deletions src/main/java/bisq/asset/Base58BitcoinAddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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;

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();
}
}
38 changes: 38 additions & 0 deletions src/main/java/bisq/asset/Coin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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;

public abstract class Coin extends AbstractAsset {

public enum Network { MAINNET, TESTNET, REGTEST }

private final Network network;

public Coin(String name, String tickerSymbol, AddressValidator addressValidator) {
this(name, tickerSymbol, addressValidator, Network.MAINNET);
}

public Coin(String name, String tickerSymbol, AddressValidator addressValidator, Network network) {
super(name, tickerSymbol, addressValidator);
this.network = network;
}

public Network getNetwork() {
return network;
}
}
25 changes: 25 additions & 0 deletions src/main/java/bisq/asset/Erc20Token.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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;

public abstract class Erc20Token extends Token {

public Erc20Token(String name, String tickerSymbol) {
super(name, tickerSymbol, new EtherAddressValidator());
}
}
26 changes: 26 additions & 0 deletions src/main/java/bisq/asset/EtherAddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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;

public class EtherAddressValidator extends RegexAddressValidator {

public EtherAddressValidator() {
// https://github.com/ethereum/web3.js/blob/master/lib/utils/utils.js#L403
super("^(0x)?[0-9a-fA-F]{40}$");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment.validation.params;
package bisq.asset;

import org.bitcoinj.core.BitcoinSerializer;
import org.bitcoinj.core.Block;
Expand All @@ -27,26 +27,8 @@
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.utils.MonetaryFormat;

public class ICHParams extends NetworkParameters {
public abstract class NetworkParametersAdapter extends NetworkParameters {

private static ICHParams instance;

public static synchronized ICHParams get() {
if (instance == null) {
instance = new ICHParams();
}
return instance;
}

// We only use the properties needed for address validation
public ICHParams() {
super();
addressHeader = 23;
p2shHeader = 13;
acceptableAddressCodes = new int[]{addressHeader, p2shHeader};
}

// default dummy implementations, not used...
@Override
public String getPaymentProtocolId() {
return PAYMENT_PROTOCOL_ID_MAINNET;
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/bisq/asset/RegexAddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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;

public class RegexAddressValidator implements AddressValidator {

private final String regex;

public RegexAddressValidator(String regex) {
this.regex = regex;
}

@Override
public AddressValidationResult validate(String address) {
if (!address.matches(regex))
return AddressValidationResult.invalidStructure();

return AddressValidationResult.validAddress();
}
}
Loading