Skip to content

Commit 20b4118

Browse files
authored
refactor: add default contract addresses (#143)
1 parent dafd3f4 commit 20b4118

27 files changed

+148
-147
lines changed

src/Enums/ContractAddresses.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ArkEcosystem\Crypto\Enums;
6+
7+
enum ContractAddresses: string
8+
{
9+
case CONSENSUS = '0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1';
10+
case MULTIPAYMENT = '0x83769BeEB7e5405ef0B7dc3C66C43E3a51A6d27f';
11+
case USERNAMES = '0x2c1DE3b4Dbb4aDebEbB5dcECAe825bE2a9fc6eb6';
12+
}

src/Identities/Address.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ArkEcosystem\Crypto\Identities;
66

7-
use ArkEcosystem\Crypto\Networks\AbstractNetwork;
87
use ArkEcosystem\Crypto\Utils\Address as AddressUtils;
98
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PrivateKey as EccPrivateKey;
109
use Elliptic\EC;
@@ -91,7 +90,6 @@ public static function fromPrivateKey(EccPrivateKey $privateKey): string
9190
* Validate the given address.
9291
*
9392
* @param string $address
94-
* @param AbstractNetwork|int|null $network
9593
*
9694
* @return bool
9795
*/

src/Identities/PrivateKey.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ArkEcosystem\Crypto\Identities;
66

7-
use ArkEcosystem\Crypto\Networks\AbstractNetwork;
87
use BitWasp\Bitcoin\Bitcoin;
98
use BitWasp\Bitcoin\Crypto\EcAdapter\EcAdapterFactory;
109
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PrivateKey as EcPrivateKey;
@@ -53,18 +52,17 @@ public static function fromHex($privateKey): EcPrivateKey
5352
/**
5453
* Derive the private key for the given WIF.
5554
*
56-
* @param string $wif
57-
* @param AbstractNetwork|null $network
55+
* @param string $wif
5856
*
5957
* @return EcPrivateKey
6058
*/
61-
public static function fromWif(string $wif, AbstractNetwork $network = null): EcPrivateKey
59+
public static function fromWif(string $wif): EcPrivateKey
6260
{
6361
return (new PrivateKeyFactory(
6462
EcAdapterFactory::getPhpEcc(
6563
Bitcoin::getMath(),
6664
Bitcoin::getGenerator()
6765
)
68-
))->fromWif($wif, $network);
66+
))->fromWif($wif);
6967
}
7068
}

src/Identities/WIF.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44

55
namespace ArkEcosystem\Crypto\Identities;
66

7-
use ArkEcosystem\Crypto\Networks\AbstractNetwork;
8-
97
class WIF
108
{
119
/**
1210
* Derive the WIF from the given passphrase.
1311
*
14-
* @param string $passphrase
15-
* @param AbstractNetwork|null $network
12+
* @param string $passphrase
1613
*
1714
* @return string
1815
*/
19-
public static function fromPassphrase(string $passphrase, AbstractNetwork $network = null): string
16+
public static function fromPassphrase(string $passphrase): string
2017
{
21-
return PrivateKey::fromPassphrase($passphrase)->toWif($network);
18+
return PrivateKey::fromPassphrase($passphrase)->toWif();
2219
}
2320
}

src/Networks/Testnet.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Transactions/Builder/UnvoteBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
namespace ArkEcosystem\Crypto\Transactions\Builder;
66

7+
use ArkEcosystem\Crypto\Enums\ContractAddresses;
78
use ArkEcosystem\Crypto\Transactions\Types\AbstractTransaction;
89
use ArkEcosystem\Crypto\Transactions\Types\Unvote;
910

1011
class UnvoteBuilder extends AbstractTransactionBuilder
1112
{
13+
public function __construct(?array $data = null)
14+
{
15+
parent::__construct($data);
16+
17+
$this->recipientAddress(ContractAddresses::CONSENSUS->value);
18+
}
19+
1220
protected function getTransactionInstance(?array $data = []): AbstractTransaction
1321
{
1422
return new Unvote($data);

src/Transactions/Builder/UsernameRegistrationBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44

55
namespace ArkEcosystem\Crypto\Transactions\Builder;
66

7+
use ArkEcosystem\Crypto\Enums\ContractAddresses;
78
use ArkEcosystem\Crypto\Helpers;
89
use ArkEcosystem\Crypto\Transactions\Types\AbstractTransaction;
910
use ArkEcosystem\Crypto\Transactions\Types\UsernameRegistration;
1011

1112
class UsernameRegistrationBuilder extends AbstractTransactionBuilder
1213
{
14+
public function __construct(?array $data = null)
15+
{
16+
parent::__construct($data);
17+
18+
$this->recipientAddress(ContractAddresses::USERNAMES->value);
19+
}
20+
1321
public function username(string $username): self
1422
{
1523
Helpers::isValidUsername($username);

src/Transactions/Builder/UsernameResignationBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
namespace ArkEcosystem\Crypto\Transactions\Builder;
66

7+
use ArkEcosystem\Crypto\Enums\ContractAddresses;
78
use ArkEcosystem\Crypto\Transactions\Types\AbstractTransaction;
89
use ArkEcosystem\Crypto\Transactions\Types\UsernameResignation;
910

1011
class UsernameResignationBuilder extends AbstractTransactionBuilder
1112
{
13+
public function __construct(?array $data = null)
14+
{
15+
parent::__construct($data);
16+
17+
$this->recipientAddress(ContractAddresses::USERNAMES->value);
18+
}
19+
1220
protected function getTransactionInstance(?array $data = []): AbstractTransaction
1321
{
1422
return new UsernameResignation($data);

src/Transactions/Builder/ValidatorRegistrationBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
namespace ArkEcosystem\Crypto\Transactions\Builder;
66

7+
use ArkEcosystem\Crypto\Enums\ContractAddresses;
78
use ArkEcosystem\Crypto\Transactions\Types\AbstractTransaction;
89
use ArkEcosystem\Crypto\Transactions\Types\ValidatorRegistration;
910

1011
class ValidatorRegistrationBuilder extends AbstractTransactionBuilder
1112
{
13+
public function __construct(?array $data = null)
14+
{
15+
parent::__construct($data);
16+
17+
$this->recipientAddress(ContractAddresses::CONSENSUS->value);
18+
}
19+
1220
public function validatorPublicKey(string $validatorPublicKey): self
1321
{
1422
$this->transaction->data['validatorPublicKey'] = $validatorPublicKey;

src/Transactions/Builder/ValidatorResignationBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
namespace ArkEcosystem\Crypto\Transactions\Builder;
66

7+
use ArkEcosystem\Crypto\Enums\ContractAddresses;
78
use ArkEcosystem\Crypto\Transactions\Types\AbstractTransaction;
89
use ArkEcosystem\Crypto\Transactions\Types\ValidatorResignation;
910

1011
class ValidatorResignationBuilder extends AbstractTransactionBuilder
1112
{
13+
public function __construct(?array $data = null)
14+
{
15+
parent::__construct($data);
16+
17+
$this->recipientAddress(ContractAddresses::CONSENSUS->value);
18+
}
19+
1220
protected function getTransactionInstance(?array $data = []): AbstractTransaction
1321
{
1422
return new ValidatorResignation($data);

0 commit comments

Comments
 (0)