Skip to content

add ZEC-t validation #9

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

Merged
merged 1 commit into from
Mar 20, 2018
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
10 changes: 9 additions & 1 deletion src/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ abstract class Validation
protected $address;
protected $addressVersion;
protected $base58PrefixToHexVersion;
protected $length = 50;
protected $lengths = [];

protected function __construct()
{
Expand Down Expand Up @@ -168,7 +170,13 @@ public function validate($address)
}

$hexAddress = self::base58ToHex($this->address);
if (strlen($hexAddress) != 50)
$length = $this->length;
if (!empty($this->lengths[$this->address[0]]))
{
$length = $this->lengths[$this->address[0]];
}

if (strlen($hexAddress) != $length)
{
return false;
}
Expand Down
19 changes: 19 additions & 0 deletions src/Validation/ZEC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Merkeleon\PhpCryptocurrencyAddressValidation\Validation;

use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;

class ZEC extends Validation
{
// more info at https://en.bitcoin.it/wiki/List_of_address_prefixes
protected $base58PrefixToHexVersion = [
't' => '1C',
// 'z' => '16',
];

protected $lengths = [
't' => 52,
'z' => 140
];
}
26 changes: 26 additions & 0 deletions tests/ZECTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests;

use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation\BTC;
use PHPUnit_Framework_TestCase;

class ZECTest extends PHPUnit_Framework_TestCase
{

public function testValidator()
{
$testData = [
['t1ZJQNuop1oytQ7ow4Kq8o9if3astavba5W', true],
['t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd', true],
['zcBqWB8VDjVER7uLKb4oHp2v54v2a1jKd9o4FY7mdgQ3gDfG8MiZLvdQga8JK3t58yjXGjQHzMzkGUxSguSs6ZzqpgTNiZG', false],
];

foreach ($testData as $row) {
$validator = Validation::make('ZEC');
$this->assertEquals($row[1], $validator->validate($row[0]));
}

}
}