Skip to content

Commit ad4f9c9

Browse files
authored
Merge pull request #9 from androzd/master
add ZEC-t validation
2 parents 5d8416b + d7bc82c commit ad4f9c9

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/Validation.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ abstract class Validation
99
protected $address;
1010
protected $addressVersion;
1111
protected $base58PrefixToHexVersion;
12+
protected $length = 50;
13+
protected $lengths = [];
1214

1315
protected function __construct()
1416
{
@@ -168,7 +170,13 @@ public function validate($address)
168170
}
169171

170172
$hexAddress = self::base58ToHex($this->address);
171-
if (strlen($hexAddress) != 50)
173+
$length = $this->length;
174+
if (!empty($this->lengths[$this->address[0]]))
175+
{
176+
$length = $this->lengths[$this->address[0]];
177+
}
178+
179+
if (strlen($hexAddress) != $length)
172180
{
173181
return false;
174182
}

src/Validation/ZEC.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
4+
5+
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
6+
7+
class ZEC extends Validation
8+
{
9+
// more info at https://en.bitcoin.it/wiki/List_of_address_prefixes
10+
protected $base58PrefixToHexVersion = [
11+
't' => '1C',
12+
// 'z' => '16',
13+
];
14+
15+
protected $lengths = [
16+
't' => 52,
17+
'z' => 140
18+
];
19+
}

tests/ZECTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
6+
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation\BTC;
7+
use PHPUnit_Framework_TestCase;
8+
9+
class ZECTest extends PHPUnit_Framework_TestCase
10+
{
11+
12+
public function testValidator()
13+
{
14+
$testData = [
15+
['t1ZJQNuop1oytQ7ow4Kq8o9if3astavba5W', true],
16+
['t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd', true],
17+
['zcBqWB8VDjVER7uLKb4oHp2v54v2a1jKd9o4FY7mdgQ3gDfG8MiZLvdQga8JK3t58yjXGjQHzMzkGUxSguSs6ZzqpgTNiZG', false],
18+
];
19+
20+
foreach ($testData as $row) {
21+
$validator = Validation::make('ZEC');
22+
$this->assertEquals($row[1], $validator->validate($row[0]));
23+
}
24+
25+
}
26+
}

0 commit comments

Comments
 (0)