Skip to content

Commit 7efbad2

Browse files
authored
fix: add pubKeyHash and use it as network identifier (#97)
1 parent 0b7bf54 commit 7efbad2

File tree

13 files changed

+55
-9
lines changed

13 files changed

+55
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ composer.lock
22
phpunit.xml
33
vendor
44
clover.xml
5+
.php_cs.cache
6+
.phpunit.result.cache

.php_cs.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Networks/AbstractNetwork.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public function version(): int
6464
return hexdec($this->getAddressByte());
6565
}
6666

67-
/**
68-
* Create a new network instance.
69-
*
70-
* @return string
71-
*/
67+
abstract public function pubKeyHash(): int;
68+
7269
abstract public function epoch(): string;
7370
}

src/Networks/Devnet.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class Devnet extends AbstractNetwork
4141
self::BIP32_PREFIX_XPRV => '46089520',
4242
];
4343

44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function pubKeyHash(): int
48+
{
49+
return 30;
50+
}
51+
4452
/**
4553
* {@inheritdoc}
4654
*/

src/Networks/Mainnet.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class Mainnet extends AbstractNetwork
4141
self::BIP32_PREFIX_XPRV => '46089520',
4242
];
4343

44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function pubKeyHash(): int
48+
{
49+
return 23;
50+
}
51+
4452
/**
4553
* {@inheritdoc}
4654
*/

src/Networks/Testnet.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class Testnet extends AbstractNetwork
4141
self::BIP32_PREFIX_XPRV => '70615956',
4242
];
4343

44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function pubKeyHash(): int
48+
{
49+
return 23;
50+
}
51+
4452
/**
4553
* {@inheritdoc}
4654
*/

src/Transactions/Builder/AbstractTransactionBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ArkEcosystem\Crypto\Transactions\Builder;
1515

1616
use ArkEcosystem\Crypto\Configuration\Fee;
17+
use ArkEcosystem\Crypto\Configuration\Network;
1718
use ArkEcosystem\Crypto\Identities\PrivateKey;
1819
use ArkEcosystem\Crypto\Transactions\Types\Transaction;
1920

@@ -36,7 +37,7 @@ public function __construct()
3637
$this->transaction->data['amount'] = '0';
3738
$this->transaction->data['fee'] = $this->getFee();
3839
$this->transaction->data['version'] = 2;
39-
$this->transaction->data['network'] = 23;
40+
$this->transaction->data['network'] = Network::get()->pubKeyHash();
4041
}
4142

4243
/**

tests/Identities/AddressTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace ArkEcosystem\Tests\Crypto\Identities;
1515

16+
use ArkEcosystem\Crypto\Configuration\Network;
1617
use ArkEcosystem\Crypto\Identities\Address as TestClass;
1718
use ArkEcosystem\Crypto\Identities\PrivateKey;
19+
use ArkEcosystem\Crypto\Networks\Devnet;
1820
use ArkEcosystem\Tests\Crypto\TestCase;
1921

2022
/**
@@ -25,6 +27,13 @@
2527
*/
2628
class AddressTest extends TestCase
2729
{
30+
protected function setUp(): void
31+
{
32+
parent::setUp();
33+
34+
Network::set(Devnet::new());
35+
}
36+
2837
/** @test */
2938
public function it_should_get_the_address_from_passphrase()
3039
{

tests/Networks/DevnetTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class DevnetTest extends NetworkTestCase
2626
{
2727
protected $epoch = '2017-03-21T13:00:00.000Z';
2828

29+
protected $pubKeyHash = 30;
30+
2931
public function getTestSubject()
3032
{
3133
return Devnet::new();

tests/Networks/MainnetTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class MainnetTest extends NetworkTestCase
2626
{
2727
protected $epoch = '2017-03-21T13:00:00.000Z';
2828

29+
protected $pubKeyHash = 23;
30+
2931
public function getTestSubject()
3032
{
3133
return Mainnet::new();

0 commit comments

Comments
 (0)