File tree 3 files changed +54
-1
lines changed
3 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ abstract class Validation
9
9
protected $ address ;
10
10
protected $ addressVersion ;
11
11
protected $ base58PrefixToHexVersion ;
12
+ protected $ length = 50 ;
13
+ protected $ lengths = [];
12
14
13
15
protected function __construct ()
14
16
{
@@ -168,7 +170,13 @@ public function validate($address)
168
170
}
169
171
170
172
$ 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 )
172
180
{
173
181
return false ;
174
182
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments