This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Redesign asset listing and validation infrastructure #32
Merged
cbeams
merged 106 commits into
bisq-network:master
from
blabno:feature/alt-validator-refactoring
Apr 3, 2018
Merged
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.
856669a
AssetProvider
cb6c579
AssetProviderRegistry
c949a24
Adjust Bch and Ella asset providers names.
695053d
Organize imports
cbeams cab46e2
Redesign asset listing and validation infrastructure
cbeams 9026200
Extract BSQ
cbeams 9fbed62
Extract Litecoin
cbeams c2c7e40
Extract Dogecoin
cbeams bd37996
Extract Dash
cbeams f07e13e
Remove unused imports
cbeams a08ac11
Extract PIVX
cbeams 22cd1b4
Extract Internet of People
cbeams df0931e
Add missing license headers
cbeams 981ca38
Extract Octocoin
cbeams 49b119d
Extract Zcash
db51bf6
Extract Byteball
b516ce3
Extract Nxt
055acf2
Extract Decent
cfb2484
Extract Pranacoin
44fa4b2
Extract Wacoin
267261b
Extract ZenCash
956a5c6
Extract Cryptonite
f43d9fa
Extract Terracoin
0f5c3aa
Extract Internext
da62f3a
Extract Particl
8e67b8b
Extract Madcoin
64c947a
Extract Bitcoin Clashic
15d9376
Extract Bitcoin Gold
0f3bfbb
Extract Cagecoin
7d23f15
Extract Verify
56ec783
Extract Spectrecoin
c263cf5
Extract Wild Token
a33fe9d
Extract DeepOnion
2ee9f13
Extract Creativecoin
c11df7b
Extract Infinity Economics
159e975
Extract Better Betting
648c2e4
Extract Movement
5647b74
Extract RefToken
f79e055
Extract Stellite
f1d84c0
Extract Dai Stablecoin
e750c3f
Extract Yenten
ddc77e7
Extract BitDaric
4f3f151
Extract Obsidian
a0f5b0a
Extract Cassubian Detk
034d62a
Extract DigiMoney
0ad058c
Extract SpeedCash
335496b
Extract SOS Coin
c89fe8a
Extract AchieveCoin
934dbf6
Extract vDinar
731845e
Extract Anglecoin
aa22f58
Extract Dinero
1295c8d
Extract Strayacoin
560c588
Extract ROIcoin
98893f7
Extract WorldMobileCoin
80375e0
Extract Arto
0fc1a38
Extract Koto
97584a7
Extract Ubiq
686d134
Extract Qwark
3c1032a
Extract GeoCoin
d2ee3ec
Extract 10grans
03ed04e
Extract Phore
81f403d
Extract Octocoin
f0d0ab5
Extract Burstcoin
ecd6632
Extract Counterparty
af23a18
Extract DarkNet
ee2b77b
Extract Decred
53931a7
Extract DynamicCoin
1433c45
Extract Espers
b100c10
Extract EtherClassic
a7e2fdc
Extract Gridcoin
04c2e35
Extract LBRY
d84bf70
Extract Lisk
eba4552
Extract MaidSafeCoin
d114c58
Extract Monero
90e8043
Extract MyceliumToken
c22021e
Extract NavCoin
ca8d348
Extract Namecoin
0cecac6
Extract NuBits
9b70137
Extract PascalCoin
0749774
Extract PepeCash
7998747
Extract PostCoin
375a2f0
Extract ReddCoin
fa1e3b3
Extract SafeFileSystemCoin
3bae6ec
Extract Siacoin
239ce5a
Extract Siafund
66f7b51
Extract Sibcoin
e887223
Extract STEEM
1ca2535
Extract Unobtanium
5b061e2
Extract Zcoin
393e090
Fuse sorting into stream for CurrencyUtil.
f49dc8d
Extract Ellaism
0eae155
Add missing license headers
cbeams f8796f7
Remove blank lines between closing braces
cbeams 0551d22
Add blank lines where appropriate
cbeams c1d5aac
Wrap code at 120 characters
cbeams b73fa60
Remove unnecessary else(if) clauses after a return
cbeams 7ad70c3
Simplify BitcoinClashic
cbeams cc5edbe
Improve AbstractAssetTest#testPresenceInAssetRegistry
cbeams 9c7d19e
Sort META-INF/services/bisq.asset.Asset
cbeams e47d59f
Polish Byteball
cbeams 1d040a2
Polish CurrencyUtil
cbeams 9dc5b8d
Polish AltCoinAddressValidator
cbeams d7537ae
Polish AddressValidationResult
cbeams 990070f
Add Javadoc for bisq.asset types
cbeams 2f231d3
Document META-INF/services/bisq.asset.Asset
cbeams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
public static AddressValidationResult invalidAddress(Throwable cause) { | ||
return invalidAddress(cause.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
src/main/java/bisq/asset/Base58BitcoinAddressValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}$"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 specialzAddressesNotSupported
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.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.