Skip to content

Commit

Permalink
Update Horizen (ZEN)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Tarren committed Sep 5, 2018
1 parent 708d9a4 commit 4a4e488
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
69 changes: 69 additions & 0 deletions assets/src/main/java/bisq/asset/coins/Horizen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.coins;

import bisq.asset.AddressValidationResult;
import bisq.asset.AddressValidator;
import bisq.asset.Coin;

import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;

public class Horizen extends Coin {

public Horizen() {
super("Horizen", "ZEN", new HorizenAddressValidator());
}


public static class HorizenAddressValidator implements AddressValidator {

@Override
public AddressValidationResult validate(String address) {
byte[] byteAddress;
try {
// Get the non Base58 form of the address and the bytecode of the first two bytes
byteAddress = Base58.decodeChecked(address);
} catch (AddressFormatException e) {
// Unhandled Exception (probably a checksum error)
return AddressValidationResult.invalidAddress(e);
}
int version0 = byteAddress[0] & 0xFF;
int version1 = byteAddress[1] & 0xFF;

// We only support public ("zn" (0x20,0x89), "t1" (0x1C,0xB8))
// and multisig ("zs" (0x20,0x96), "t3" (0x1C,0xBD)) addresses

// Fail for private addresses
if (version0 == 0x16 && version1 == 0x9A)
// Address starts with "zc"
return AddressValidationResult.invalidAddress("", "validation.altcoin.zAddressesNotSupported");

if (version0 == 0x1C && (version1 == 0xB8 || version1 == 0xBD))
// "t1" or "t3" address
return AddressValidationResult.validAddress();

if (version0 == 0x20 && (version1 == 0x89 || version1 == 0x96))
// "zn" or "zs" address
return AddressValidationResult.validAddress();

// Unknown Type
return AddressValidationResult.invalidStructure();
}
}
}
45 changes: 45 additions & 0 deletions assets/src/test/java/bisq/asset/coins/HorizenTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.coins;

import bisq.asset.AbstractAssetTest;

import org.junit.Test;

public class HorizenTest extends AbstractAssetTest {

public HorizenTest() {
super(new Horizen());
}

@Test
public void testValidAddresses() {
assertValidAddress("znk62Ey7ptTyHgYLaLDTEwhLF6uN1DXTBfa");
assertValidAddress("znTqzi5rTXf6KJnX5tLaC5CMGHfeWJwy1c7");
assertValidAddress("t1V9h2P9n4sYg629Xn4jVDPySJJxGmPb1HK");
assertValidAddress("t3Ut4KUq2ZSMTPNE67pBU5LqYCi2q36KpXQ");
}

@Test
public void testInvalidAddresses() {
assertInvalidAddress("zcKffBrza1cirFY47aKvXiV411NZMscf7zUY5bD1HwvkoQvKHgpxLYUHtMCLqBAeif1VwHmMjrMAKNrdCknCVqCzRNizHUq");
assertInvalidAddress("AFTqzi5rTXf6KJnX5tLaC5CMGHfeWJwy1c7");
assertInvalidAddress("zig-zag");
assertInvalidAddress("0123456789");
}
}

0 comments on commit 4a4e488

Please sign in to comment.