diff --git a/.github/coverage.svg b/.github/coverage.svg
new file mode 100644
index 0000000..95327c6
--- /dev/null
+++ b/.github/coverage.svg
@@ -0,0 +1,21 @@
+
+
\ No newline at end of file
diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml
new file mode 100644
index 0000000..0b8676f
--- /dev/null
+++ b/.github/workflows/codecoverage.yml
@@ -0,0 +1,82 @@
+name: Code Coverage
+
+# Runs PHPUnit with code coverage enabled, commits the html report to
+# GitHub Pages, generates a README badge with the coverage percentage.
+#
+# Requires a gh-pages branch already created.
+#
+# git checkout --orphan gh-pages
+# touch index.html
+# git add index.html
+# git commit -m 'Set up gh-pages branch' index.html
+# git push origin gh-pages
+# git checkout master
+#
+# @author BrianHenryIE
+
+on:
+ push:
+ branches:
+ - master
+
+jobs:
+ tests:
+ runs-on: ubuntu-latest
+
+ steps:
+
+ - name: Git checkout
+ uses: actions/checkout@v2
+
+ - name: Install PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '7.4'
+ coverage: xdebug
+
+# - name: Checkout GitHub Pages branch for code coverage report
+# uses: actions/checkout@v2
+# with:
+# ref: gh-pages
+# path: tests/_reports/html
+
+ - name: Install dependencies
+ run: composer install --prefer-dist --no-suggest --no-progress
+
+# - name: Clear previous code coverage
+# run: |
+# cd tests/_reports/html
+# rm -rf *
+# cd ../../..
+
+ - name: Run tests with code coverage
+ run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-clover tests/_reports/clover.xml --coverage-html tests/_reports/html
+
+# - name: Edit phpcov html output to work with gh-pages
+# run: |
+# cd tests/_reports/html
+# mv _css css; find . -depth -name '*.html' -exec sed -i "s/_css\//css\//" {} +
+# mv _icons icons; find . -depth -name '*.html' -exec sed -i "s/_icons\//icons\//" {} +
+# mv _js js; find . -depth -name '*.html' -exec sed -i "s/_js\//js\//" {} +
+# git add *
+# cd ../../..
+
+# - name: Commit code coverage to gh-pages
+# uses: stefanzweifel/git-auto-commit-action@v4.1.1
+# with:
+# repository: tests/_reports/html
+# branch: gh-pages
+# commit_message: "🤖 Commit code coverage to gh-pages"
+# commit_options:
+# env:
+# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
+
+ - name: Update README badge
+ run: vendor/bin/php-coverage-badger tests/_reports/clover.xml .github/coverage.svg
+
+ - name: Commit code coverage badge
+ uses: stefanzweifel/git-auto-commit-action@v4.1.1
+ with:
+ commit_message: "🤖 Commit code coverage badge"
+
+
diff --git a/.gitignore b/.gitignore
index 2c750c4..34e851f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.idea
.phpunit.*
/vendor
-composer.lock
\ No newline at end of file
+composer.lock
+tests/_reports/
\ No newline at end of file
diff --git a/README.md b/README.md
index 907e245..9d82836 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+[]() [](https://www.php-fig.org/psr/psr-12/) [](https://brianhenryie.github.io/bh-php-monero-explorer/) [](https://phpstan.org/)
+
## PHP Bitcoin Address
A simple P2PK, P2PKH, P2SH, P2WPKH, P2WSH, P2TR output script/address parser/generator/validator.
diff --git a/composer.json b/composer.json
index 6d2a827..e885d70 100644
--- a/composer.json
+++ b/composer.json
@@ -22,7 +22,10 @@
"shanecurran/phpecc": "^0.0.1"
},
"require-dev": {
- "phpunit/phpunit": ">=5.7"
+ "dealerdirect/phpcodesniffer-composer-installer": "*",
+ "phpstan/phpstan": "^1.10",
+ "phpunit/phpunit": ">=5.7",
+ "squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
@@ -33,5 +36,24 @@
"psr-4": {
"AndKom\\Bitcoin\\Address\\Tests\\": "tests/"
}
+ },
+ "config": {
+ "sort-packages": true,
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true
+ }
+ },
+ "scripts": {
+ "test": [
+ "phpunit"
+ ],
+ "test-coverage":[
+ "phpunit --coverage-text --coverage-clover tests/_reports/clover.xml --coverage-html tests/_reports/html"
+ ],
+ "lint": [
+ "phpcbf || true",
+ "phpcs || true",
+ "phpstan"
+ ]
}
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..f797aba
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,14 @@
+
+
+
+ PHPCS configuration file.
+
+ src
+ tests
+
+
+
+ tests/_reports
+ tests/_data
+
+
\ No newline at end of file
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..0ac5e16
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,8 @@
+parameters:
+ level: 9
+ paths:
+ - src
+ - tests
+ excludePaths:
+ - tests/_reports
+ treatPhpDocTypesAsCertain: false
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index ff0ea7c..f8d6d24 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -11,4 +11,9 @@
./src
-
+
+
+ ./src
+
+
+
\ No newline at end of file
diff --git a/src/Ecc/Point.php b/src/Ecc/Point.php
index eb11431..22f2c95 100644
--- a/src/Ecc/Point.php
+++ b/src/Ecc/Point.php
@@ -16,7 +16,7 @@
class Point extends \Mdanter\Ecc\Primitives\Point
{
/**
- * @return $this
+ * @return Point
* @throws Exception
*/
public function liftX(): self
@@ -50,24 +50,28 @@ public function liftX(): self
$curve->getPrime()
);
- if ($adapter->cmp(
+ if (
+ $adapter->cmp(
$c,
$adapter->powmod(
$y,
gmp_init(2, 10),
$curve->getPrime()
)
- ) !== 0) {
+ ) !== 0
+ ) {
throw new Exception('C is not equal to point Y^2.');
}
- if ($adapter->cmp(
+ if (
+ $adapter->cmp(
$adapter->mod(
$y,
gmp_init(2, 10)
),
gmp_init(0, 10)
- ) === 0) {
+ ) === 0
+ ) {
$point = new Point($adapter, $curve, $x, $y);
} else {
$point = new Point($adapter, $curve, $x, $adapter->sub($curve->getPrime(), $y));
@@ -91,6 +95,6 @@ static function fromPubKey(GmpMathInterface $adapter, CurveFpInterface $curve, s
$y = $curve->recoverYfromX($prefix === '03', $x);
}
- return new static($adapter, $curve, $x, $y);
+ return new Point($adapter, $curve, $x, $y);
}
}
diff --git a/src/Exception.php b/src/Exception.php
index 34b30d5..2f5be19 100644
--- a/src/Exception.php
+++ b/src/Exception.php
@@ -10,4 +10,4 @@
*/
class Exception extends \Exception
{
-}
\ No newline at end of file
+}
diff --git a/src/Network/NetworkFactory.php b/src/Network/NetworkFactory.php
index e35582b..aa5535a 100644
--- a/src/Network/NetworkFactory.php
+++ b/src/Network/NetworkFactory.php
@@ -27,9 +27,9 @@
class NetworkFactory
{
/**
- * @var array
+ * @var string[]
*/
- static protected $networks = [
+ protected static $networks = [
'bitcoin',
'bitcoinTestnet',
'bitcoinCash',
@@ -49,12 +49,12 @@ class NetworkFactory
/**
* @var NetworkInterface
*/
- static protected $defaultNetwork;
+ protected static $defaultNetwork;
/**
* @param NetworkInterface $network
*/
- static public function setDefaultNetwork(NetworkInterface $network)
+ public static function setDefaultNetwork(NetworkInterface $network): void
{
static::$defaultNetwork = $network;
}
@@ -62,14 +62,14 @@ static public function setDefaultNetwork(NetworkInterface $network)
/**
* @return NetworkInterface
*/
- static public function getDefaultNetwork(): NetworkInterface
+ public static function getDefaultNetwork(): NetworkInterface
{
return static::$defaultNetwork ?: static::bitcoin();
}
/**
* @param string $name
- * @param array $arguments
+ * @param array $arguments
* @return NetworkInterface
* @throws Exception
*/
@@ -81,27 +81,33 @@ public function createNetwork(string $name, array $arguments): NetworkInterface
$class = 'AndKom\\Bitcoin\\Address\\Network\\Networks\\' . ucfirst($name);
- return new $class(...$arguments);
+ $network = new $class(...$arguments);
+
+ if (! $network instanceof NetworkInterface) {
+ throw new Exception("{$class} was not a NetworkInterface");
+ }
+
+ return $network;
}
/**
- * @param $name
- * @param $arguments
+ * @param string $name
+ * @param array $arguments
* @return NetworkInterface
* @throws Exception
*/
- public function __call($name, $arguments)
+ public function __call(string $name, array $arguments)
{
return $this->createNetwork($name, $arguments);
}
/**
- * @param $name
- * @param $arguments
+ * @param string $name
+ * @param array $arguments
* @return NetworkInterface
*/
- public static function __callStatic($name, $arguments)
+ public static function __callStatic(string $name, array $arguments)
{
- return (new static)->createNetwork($name, $arguments);
+ return (new NetworkFactory())->createNetwork($name, $arguments);
}
-}
\ No newline at end of file
+}
diff --git a/src/Network/NetworkInterface.php b/src/Network/NetworkInterface.php
index 8f6707f..975e7f6 100644
--- a/src/Network/NetworkInterface.php
+++ b/src/Network/NetworkInterface.php
@@ -53,4 +53,4 @@ public function decodeAddress(string $address): OutputInterface;
* @return bool
*/
public function validateAddress(string $address): bool;
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/Bitcoin.php b/src/Network/Networks/Bitcoin.php
index df15e53..b22a106 100644
--- a/src/Network/Networks/Bitcoin.php
+++ b/src/Network/Networks/Bitcoin.php
@@ -19,4 +19,4 @@ class Bitcoin extends BitcoinAbstract
* @var bool
*/
protected $hasTaproot = true;
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/BitcoinAbstract.php b/src/Network/Networks/BitcoinAbstract.php
index e56af2a..8af2b8b 100644
--- a/src/Network/Networks/BitcoinAbstract.php
+++ b/src/Network/Networks/BitcoinAbstract.php
@@ -15,8 +15,10 @@
use AndKom\Bitcoin\Address\Utils;
use AndKom\Bitcoin\Address\Validate;
use BrooksYang\Bech32m\Exception\Bech32mException;
+
use function BrooksYang\Bech32m\decodeSegwit;
use function BrooksYang\Bech32m\encodeSegwit;
+
use const BrooksYang\Bech32m\BECH32;
use const BrooksYang\Bech32m\BECH32M;
@@ -26,8 +28,8 @@
*/
abstract class BitcoinAbstract implements NetworkInterface
{
- const VERSION_SEGWIT = 0;
- const VERSION_TAPROOT = 1;
+ public const VERSION_SEGWIT = 0;
+ public const VERSION_TAPROOT = 1;
/**
* @var string
@@ -185,4 +187,4 @@ public function validateAddress(string $address): bool
return false;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/BitcoinCash.php b/src/Network/Networks/BitcoinCash.php
index faf68ca..639c515 100644
--- a/src/Network/Networks/BitcoinCash.php
+++ b/src/Network/Networks/BitcoinCash.php
@@ -59,8 +59,10 @@ public function getAddressP2sh(string $scriptHash): string
*/
public function decodeAddress(string $address): OutputInterface
{
- if (strpos($address, $this->prefixP2pkh) !== 0 ||
- strpos($address, $this->prefixP2sh) !== 0) {
+ if (
+ strpos($address, $this->prefixP2pkh) !== 0 ||
+ strpos($address, $this->prefixP2sh) !== 0
+ ) {
throw new Exception('Cannot decode address.');
}
@@ -72,4 +74,4 @@ public function decodeAddress(string $address): OutputInterface
return new P2sh($hash);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/BitcoinGold.php b/src/Network/Networks/BitcoinGold.php
index 2ca53a3..c224e42 100644
--- a/src/Network/Networks/BitcoinGold.php
+++ b/src/Network/Networks/BitcoinGold.php
@@ -29,4 +29,4 @@ class BitcoinGold extends Bitcoin
* @var bool
*/
protected $hasTaproot = false;
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/BitcoinTestnet.php b/src/Network/Networks/BitcoinTestnet.php
index 206eb18..aee67fd 100644
--- a/src/Network/Networks/BitcoinTestnet.php
+++ b/src/Network/Networks/BitcoinTestnet.php
@@ -24,4 +24,4 @@ class BitcoinTestnet extends Bitcoin
* @var string
*/
protected $prefixBech32 = 'tb';
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/Dash.php b/src/Network/Networks/Dash.php
index c88fe38..c4379bb 100644
--- a/src/Network/Networks/Dash.php
+++ b/src/Network/Networks/Dash.php
@@ -19,4 +19,4 @@ class Dash extends BitcoinAbstract
* @var string
*/
protected $prefixP2sh = "\x10";
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/DashTestnet.php b/src/Network/Networks/DashTestnet.php
index 2d1a88f..7388931 100644
--- a/src/Network/Networks/DashTestnet.php
+++ b/src/Network/Networks/DashTestnet.php
@@ -19,4 +19,4 @@ class DashTestnet extends Dash
* @var string
*/
protected $prefixP2sh = "\x13";
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/Dogecoin.php b/src/Network/Networks/Dogecoin.php
index 3479996..23b8289 100644
--- a/src/Network/Networks/Dogecoin.php
+++ b/src/Network/Networks/Dogecoin.php
@@ -19,4 +19,4 @@ class Dogecoin extends BitcoinAbstract
* @var string
*/
protected $prefixP2sh = "\x16";
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/DogecoinTestnet.php b/src/Network/Networks/DogecoinTestnet.php
index a428edb..26f9caf 100644
--- a/src/Network/Networks/DogecoinTestnet.php
+++ b/src/Network/Networks/DogecoinTestnet.php
@@ -19,4 +19,4 @@ class DogecoinTestnet extends Dogecoin
* @var string
*/
protected $prefixP2sh = "\xc4";
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/Litecoin.php b/src/Network/Networks/Litecoin.php
index 4c11212..a7e01d7 100644
--- a/src/Network/Networks/Litecoin.php
+++ b/src/Network/Networks/Litecoin.php
@@ -24,4 +24,4 @@ class Litecoin extends Bitcoin
* @var string
*/
protected $prefixBech32 = 'ltc';
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/LitecoinTestnet.php b/src/Network/Networks/LitecoinTestnet.php
index 080516b..bc9d6f8 100644
--- a/src/Network/Networks/LitecoinTestnet.php
+++ b/src/Network/Networks/LitecoinTestnet.php
@@ -24,4 +24,4 @@ class LitecoinTestnet extends Litecoin
* @var string
*/
protected $prefixBech32 = 'tltc';
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/Viacoin.php b/src/Network/Networks/Viacoin.php
index 471e53d..d519c13 100644
--- a/src/Network/Networks/Viacoin.php
+++ b/src/Network/Networks/Viacoin.php
@@ -29,4 +29,4 @@ class Viacoin extends Bitcoin
* @var bool
*/
protected $hasTaproot = false;
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/ViacoinTestnet.php b/src/Network/Networks/ViacoinTestnet.php
index 5a83d02..9aa687d 100644
--- a/src/Network/Networks/ViacoinTestnet.php
+++ b/src/Network/Networks/ViacoinTestnet.php
@@ -24,4 +24,4 @@ class ViacoinTestnet extends Viacoin
* @var string
*/
protected $prefixBech32 = 'tvia';
-}
\ No newline at end of file
+}
diff --git a/src/Network/Networks/Zcash.php b/src/Network/Networks/Zcash.php
index 20bdb4d..2723ae8 100644
--- a/src/Network/Networks/Zcash.php
+++ b/src/Network/Networks/Zcash.php
@@ -19,4 +19,4 @@ class Zcash extends BitcoinAbstract
* @var string
*/
protected $prefixP2sh = "\x1c\xbd";
-}
\ No newline at end of file
+}
diff --git a/src/Output/AbstractOutput.php b/src/Output/AbstractOutput.php
index 8a3f01c..972a459 100644
--- a/src/Output/AbstractOutput.php
+++ b/src/Output/AbstractOutput.php
@@ -53,7 +53,7 @@ protected function network(NetworkInterface $network = null): NetworkInterface
* @return OutputInterface
* @throws Exception
*/
- static public function fromHex(string $hex): OutputInterface
+ public static function fromHex(string $hex): OutputInterface
{
$script = hex2bin($hex);
@@ -63,4 +63,4 @@ static public function fromHex(string $hex): OutputInterface
return static::fromScript($script);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Op.php b/src/Output/Op.php
index f5cdf1f..f67540d 100644
--- a/src/Output/Op.php
+++ b/src/Output/Op.php
@@ -10,10 +10,10 @@
*/
interface Op
{
- const DUP = "\x76";
- const EQUAL = "\x87";
- const EQUALVERIFY = "\x88";
- const HASH160 = "\xa9";
- const CHECKSIG = "\xac";
- const CHECKMULTISIG = "\xae";
-}
\ No newline at end of file
+ public const DUP = "\x76";
+ public const EQUAL = "\x87";
+ public const EQUALVERIFY = "\x88";
+ public const HASH160 = "\xa9";
+ public const CHECKSIG = "\xac";
+ public const CHECKMULTISIG = "\xae";
+}
diff --git a/src/Output/OutputFactory.php b/src/Output/OutputFactory.php
index fdc9589..5f1b3e6 100644
--- a/src/Output/OutputFactory.php
+++ b/src/Output/OutputFactory.php
@@ -25,7 +25,7 @@ class OutputFactory
* @return OutputInterface
* @throws Exception
*/
- static public function p2pk(string $pubKey): OutputInterface
+ public static function p2pk(string $pubKey): OutputInterface
{
return new P2pk($pubKey);
}
@@ -35,18 +35,18 @@ static public function p2pk(string $pubKey): OutputInterface
* @return OutputInterface
* @throws Exception
*/
- static public function p2pkh(string $pubKeyHash): OutputInterface
+ public static function p2pkh(string $pubKeyHash): OutputInterface
{
return new P2pkh($pubKeyHash);
}
/**
* @param int $m
- * @param array $pubKeys
+ * @param string[] $pubKeys
* @return OutputInterface
* @throws Exception
*/
- static public function p2ms(int $m, array $pubKeys): OutputInterface
+ public static function p2ms(int $m, array $pubKeys): OutputInterface
{
return new P2ms($m, $pubKeys);
}
@@ -56,7 +56,7 @@ static public function p2ms(int $m, array $pubKeys): OutputInterface
* @return OutputInterface
* @throws Exception
*/
- static public function p2sh(OutputInterface $output): OutputInterface
+ public static function p2sh(OutputInterface $output): OutputInterface
{
return new P2sh($output);
}
@@ -66,7 +66,7 @@ static public function p2sh(OutputInterface $output): OutputInterface
* @return OutputInterface
* @throws Exception
*/
- static public function p2wpkh(string $pubKeyHash): OutputInterface
+ public static function p2wpkh(string $pubKeyHash): OutputInterface
{
return new P2wpkh($pubKeyHash);
}
@@ -76,7 +76,7 @@ static public function p2wpkh(string $pubKeyHash): OutputInterface
* @return OutputInterface
* @throws Exception
*/
- static public function p2wsh(OutputInterface $output): OutputInterface
+ public static function p2wsh(OutputInterface $output): OutputInterface
{
return new P2wsh($output);
}
@@ -85,7 +85,7 @@ static public function p2wsh(OutputInterface $output): OutputInterface
* @param string $taprootPubKey
* @return OutputInterface
*/
- static public function p2tr(string $taprootPubKey): OutputInterface
+ public static function p2tr(string $taprootPubKey): OutputInterface
{
return new P2tr($taprootPubKey);
}
@@ -95,7 +95,7 @@ static public function p2tr(string $taprootPubKey): OutputInterface
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
$map = [
P2pk::COMPRESSED_SCRIPT_LEN => P2pk::class,
@@ -114,7 +114,7 @@ static public function fromScript(string $script): OutputInterface
$class = P2wpkh::class;
} elseif (P2wsh::SCRIPT_LEN === $scriptLen && P2wsh::WITNESS_VERSION === $script[0]) {
$class = P2wsh::class;
- } else if (P2wsh::SCRIPT_LEN === $scriptLen && P2tr::WITNESS_VERSION === $script[0]) {
+ } elseif (P2wsh::SCRIPT_LEN === $scriptLen && P2tr::WITNESS_VERSION === $script[0]) {
$class = P2tr::class;
} else {
throw new Exception('Unknown script type.');
@@ -128,8 +128,8 @@ static public function fromScript(string $script): OutputInterface
* @return OutputInterface
* @throws Exception
*/
- static public function fromHex(string $hex): OutputInterface
+ public static function fromHex(string $hex): OutputInterface
{
return static::fromScript(Utils::hex2bin($hex));
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/OutputInterface.php b/src/Output/OutputInterface.php
index 502ccd3..c9b3099 100644
--- a/src/Output/OutputInterface.php
+++ b/src/Output/OutputInterface.php
@@ -54,17 +54,17 @@ public function address(NetworkInterface $network = null): string;
* @return void
* @throws Exception
*/
- static public function validateScript(string $script);
+ public static function validateScript(string $script);
/**
* @param string $script
* @return OutputInterface
*/
- static public function fromScript(string $script): OutputInterface;
+ public static function fromScript(string $script): OutputInterface;
/**
* @param string $hex
* @return OutputInterface
*/
- static public function fromHex(string $hex): OutputInterface;
-}
\ No newline at end of file
+ public static function fromHex(string $hex): OutputInterface;
+}
diff --git a/src/Output/Outputs/P2ms.php b/src/Output/Outputs/P2ms.php
index 6146f91..3aeb548 100644
--- a/src/Output/Outputs/P2ms.php
+++ b/src/Output/Outputs/P2ms.php
@@ -18,7 +18,7 @@
*/
class P2ms extends AbstractOutput
{
- const MIN_SCRIPT_LEN = 37;
+ public const MIN_SCRIPT_LEN = 37;
/**
* Number of signatures
@@ -35,7 +35,7 @@ class P2ms extends AbstractOutput
/**
* P2ms constructor.
* @param int $m Number of signatures
- * @param array $pubKeys
+ * @param string[] $pubKeys
* @throws Exception
*/
public function __construct(int $m, array $pubKeys)
@@ -127,7 +127,7 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
$scriptLen = strlen($script);
@@ -145,8 +145,10 @@ static public function validateScript(string $script)
for ($i = 1, $c = 0; $i < $scriptLen - 2; $c++) {
$pubKeyLen = ord($script[$i]);
- if (Validate::COMPRESSED_PUBKEY_LEN != $pubKeyLen &&
- Validate::UNCOMPRESSED_PUBKEY_LEN != $pubKeyLen) {
+ if (
+ Validate::COMPRESSED_PUBKEY_LEN != $pubKeyLen &&
+ Validate::UNCOMPRESSED_PUBKEY_LEN != $pubKeyLen
+ ) {
throw new Exception('Invalid pubkey length.');
}
@@ -163,7 +165,7 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
@@ -177,6 +179,6 @@ static public function fromScript(string $script): OutputInterface
$i += $pubKeyLen + 1;
}
- return new static($m, $pubKeys);
+ return new P2ms($m, $pubKeys);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Outputs/P2pk.php b/src/Output/Outputs/P2pk.php
index 1cddc8f..6b7c016 100644
--- a/src/Output/Outputs/P2pk.php
+++ b/src/Output/Outputs/P2pk.php
@@ -19,8 +19,8 @@
*/
class P2pk extends AbstractOutput
{
- const COMPRESSED_SCRIPT_LEN = 35;
- const UNCOMPRESSED_SCRIPT_LEN = 67;
+ public const COMPRESSED_SCRIPT_LEN = 35;
+ public const UNCOMPRESSED_SCRIPT_LEN = 67;
/**
* @var string
@@ -82,12 +82,14 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
$scriptLen = strlen($script);
- if (static::COMPRESSED_SCRIPT_LEN != $scriptLen &&
- static::UNCOMPRESSED_SCRIPT_LEN != $scriptLen) {
+ if (
+ static::COMPRESSED_SCRIPT_LEN != $scriptLen &&
+ static::UNCOMPRESSED_SCRIPT_LEN != $scriptLen
+ ) {
throw new Exception('Invalid P2PK script length.');
}
@@ -101,12 +103,12 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
$pubKey = substr($script, 1, -1);
- return new static($pubKey);
+ return new P2pk($pubKey);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Outputs/P2pkh.php b/src/Output/Outputs/P2pkh.php
index 8edeb31..2304e05 100644
--- a/src/Output/Outputs/P2pkh.php
+++ b/src/Output/Outputs/P2pkh.php
@@ -18,7 +18,7 @@
*/
class P2pkh extends AbstractOutput
{
- const SCRIPT_LEN = 25;
+ public const SCRIPT_LEN = 25;
/**
* @var string
@@ -80,13 +80,14 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
if (static::SCRIPT_LEN != strlen($script)) {
throw new Exception('Invalid P2PKH script length.');
}
- if (Op::DUP != $script[0] ||
+ if (
+ Op::DUP != $script[0] ||
Op::HASH160 != $script[1] ||
"\x14" != $script[2] ||
Op::EQUALVERIFY != $script[-2] ||
@@ -101,12 +102,12 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
$pubKeyHash = substr($script, 3, 20);
- return new static($pubKeyHash);
+ return new P2pkh($pubKeyHash);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Outputs/P2sh.php b/src/Output/Outputs/P2sh.php
index b1fd842..05ec85d 100644
--- a/src/Output/Outputs/P2sh.php
+++ b/src/Output/Outputs/P2sh.php
@@ -18,7 +18,7 @@
*/
class P2sh extends AbstractOutput
{
- const SCRIPT_LEN = 23;
+ public const SCRIPT_LEN = 23;
/**
* @var string
@@ -85,15 +85,17 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
if (static::SCRIPT_LEN != strlen($script)) {
throw new Exception('Invalid P2SH script length.');
}
- if (Op::HASH160 != $script[0] ||
+ if (
+ Op::HASH160 != $script[0] ||
"\x14" != $script[1] ||
- Op::EQUAL != $script[-1]) {
+ Op::EQUAL != $script[-1]
+ ) {
throw new Exception('Invalid P2SH script format.');
}
}
@@ -103,12 +105,12 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
$scriptHash = substr($script, 2, -1);
- return new static($scriptHash);
+ return new P2sh($scriptHash);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Outputs/P2tr.php b/src/Output/Outputs/P2tr.php
index 8350567..f2e94d9 100644
--- a/src/Output/Outputs/P2tr.php
+++ b/src/Output/Outputs/P2tr.php
@@ -16,8 +16,8 @@
*/
class P2tr extends AbstractOutput
{
- const SCRIPT_LEN = 34;
- const WITNESS_VERSION = "\x51";
+ public const SCRIPT_LEN = 34;
+ public const WITNESS_VERSION = "\x51";
/**
* @var string
@@ -78,14 +78,16 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
if (static::SCRIPT_LEN != strlen($script)) {
throw new Exception('Invalid P2TR script length.');
}
- if (static::WITNESS_VERSION != $script[0] ||
- "\x20" != $script[1]) {
+ if (
+ static::WITNESS_VERSION != $script[0] ||
+ "\x20" != $script[1]
+ ) {
throw new Exception('Invalid P2TR script format.');
}
}
@@ -95,12 +97,12 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
$taprootPubKey = substr($script, 2, 32);
- return new static($taprootPubKey);
+ return new P2tr($taprootPubKey);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Outputs/P2wpkh.php b/src/Output/Outputs/P2wpkh.php
index 8ad379a..42c406b 100644
--- a/src/Output/Outputs/P2wpkh.php
+++ b/src/Output/Outputs/P2wpkh.php
@@ -17,8 +17,8 @@
*/
class P2wpkh extends AbstractOutput
{
- const SCRIPT_LEN = 22;
- const WITNESS_VERSION = "\x00";
+ public const SCRIPT_LEN = 22;
+ public const WITNESS_VERSION = "\x00";
/**
* @var string
@@ -80,14 +80,16 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
if (static::SCRIPT_LEN != strlen($script)) {
throw new Exception('Invalid P2WPKH script length.');
}
- if (static::WITNESS_VERSION != $script[0] ||
- "\x14" != $script[1]) {
+ if (
+ static::WITNESS_VERSION != $script[0] ||
+ "\x14" != $script[1]
+ ) {
throw new Exception('Invalid P2WPKH script format.');
}
}
@@ -97,12 +99,12 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
$pubKeyHash = substr($script, 2, 20);
- return new static($pubKeyHash);
+ return new P2wpkh($pubKeyHash);
}
-}
\ No newline at end of file
+}
diff --git a/src/Output/Outputs/P2wsh.php b/src/Output/Outputs/P2wsh.php
index 1b0323d..40261cf 100644
--- a/src/Output/Outputs/P2wsh.php
+++ b/src/Output/Outputs/P2wsh.php
@@ -17,8 +17,8 @@
*/
class P2wsh extends AbstractOutput
{
- const SCRIPT_LEN = 34;
- const WITNESS_VERSION = "\x00";
+ public const SCRIPT_LEN = 34;
+ public const WITNESS_VERSION = "\x00";
/**
* @var string
@@ -84,14 +84,16 @@ public function address(NetworkInterface $network = null): string
* @param string $script
* @throws Exception
*/
- static public function validateScript(string $script)
+ public static function validateScript(string $script)
{
if (static::SCRIPT_LEN != strlen($script)) {
throw new Exception('Invalid P2WSH script length.');
}
- if (static::WITNESS_VERSION != $script[0] ||
- "\x20" != $script[1]) {
+ if (
+ static::WITNESS_VERSION != $script[0] ||
+ "\x20" != $script[1]
+ ) {
throw new Exception('Invalid P2WSH script format.');
}
}
@@ -101,12 +103,12 @@ static public function validateScript(string $script)
* @return OutputInterface
* @throws Exception
*/
- static public function fromScript(string $script): OutputInterface
+ public static function fromScript(string $script): OutputInterface
{
static::validateScript($script);
$witnessHash = substr($script, 2, 32);
- return new static($witnessHash);
+ return new P2wsh($witnessHash);
}
-}
\ No newline at end of file
+}
diff --git a/src/Taproot.php b/src/Taproot.php
index f401fb5..bcfd637 100644
--- a/src/Taproot.php
+++ b/src/Taproot.php
@@ -17,10 +17,9 @@ class Taproot
/**
* @param string $pubKey
* @param string $merkleRoot
- * @return PointInterface
* @throws Exception
*/
- static public function construct(string $pubKey, string $merkleRoot = ''): string
+ public static function construct(string $pubKey, string $merkleRoot = ''): string
{
$generator = EccFactory::getSecgCurves()->generator256k1();
$adapter = $generator->getAdapter();
diff --git a/src/Utils.php b/src/Utils.php
index a6112f0..5692266 100644
--- a/src/Utils.php
+++ b/src/Utils.php
@@ -16,7 +16,7 @@ class Utils
* @param string $data
* @return string
*/
- static public function sha256(string $data): string
+ public static function sha256(string $data): string
{
return hash('sha256', $data, true);
}
@@ -25,7 +25,7 @@ static public function sha256(string $data): string
* @param string $data
* @return string
*/
- static public function hash256(string $data): string
+ public static function hash256(string $data): string
{
return static::sha256(static::sha256($data));
}
@@ -34,7 +34,7 @@ static public function hash256(string $data): string
* @param string $data
* @return string
*/
- static public function hash160(string $data): string
+ public static function hash160(string $data): string
{
return hash('ripemd160', static::sha256($data), true);
}
@@ -44,7 +44,7 @@ static public function hash160(string $data): string
* @return string
* @throws Exception
*/
- static public function hex2bin(string $hex): string
+ public static function hex2bin(string $hex): string
{
$bin = @hex2bin($hex);
@@ -61,7 +61,7 @@ static public function hex2bin(string $hex): string
* @return string
* @throws \Exception
*/
- static public function base58encode(string $hash, string $prefix = "\x00"): string
+ public static function base58encode(string $hash, string $prefix = "\x00"): string
{
$payload = $prefix . Validate::pubKeyHash($hash);
$checksum = substr(static::hash256($payload), 0, 4);
@@ -72,10 +72,10 @@ static public function base58encode(string $hash, string $prefix = "\x00"): stri
/**
* @param string $base58
- * @return array
+ * @return string[]
* @throws \Exception
*/
- static public function base58decode(string $base58): array
+ public static function base58decode(string $base58): array
{
$address = (new Base58())->decode($base58);
$addressLen = strlen($address);
@@ -103,9 +103,9 @@ static public function base58decode(string $base58): array
* @param string $data
* @return string
*/
- static public function taggedHash(string $tag, string $data): string
+ public static function taggedHash(string $tag, string $data): string
{
$tagHash = static::sha256($tag);
return static::sha256($tagHash . $tagHash . $data);
}
-}
\ No newline at end of file
+}
diff --git a/src/Validate.php b/src/Validate.php
index 3574d35..4cbdb5d 100644
--- a/src/Validate.php
+++ b/src/Validate.php
@@ -10,20 +10,20 @@
*/
class Validate
{
- const COMPRESSED_PUBKEY_LEN = 33;
- const COMPRESSED_PUBKEY_PREFIXES = ["\x02", "\x03"];
- const UNCOMPRESSED_PUBKEY_LEN = 65;
- const UNCOMRPESSED_PUBKEY_PREFIX = "\04";
- const PUBKEY_HASH_LEN = 20;
- const SCRIPT_HASH_LEN = 20;
- const WITNESS_HASH_LEN = 32;
+ public const COMPRESSED_PUBKEY_LEN = 33;
+ public const COMPRESSED_PUBKEY_PREFIXES = ["\x02", "\x03"];
+ public const UNCOMPRESSED_PUBKEY_LEN = 65;
+ public const UNCOMRPESSED_PUBKEY_PREFIX = "\04";
+ public const PUBKEY_HASH_LEN = 20;
+ public const SCRIPT_HASH_LEN = 20;
+ public const WITNESS_HASH_LEN = 32;
/**
* @param string $pubKey
* @return string
* @throws Exception
*/
- static public function pubKey(string $pubKey): string
+ public static function pubKey(string $pubKey): string
{
$len = strlen($pubKey);
@@ -48,7 +48,7 @@ static public function pubKey(string $pubKey): string
* @return string
* @throws Exception
*/
- static public function pubKeyHash(string $pubKeyHash): string
+ public static function pubKeyHash(string $pubKeyHash): string
{
if (static::PUBKEY_HASH_LEN != strlen($pubKeyHash)) {
throw new Exception(sprintf('Invalid pubkey hash: %s.', bin2hex($pubKeyHash)));
@@ -62,7 +62,7 @@ static public function pubKeyHash(string $pubKeyHash): string
* @return string
* @throws Exception
*/
- static public function scriptHash(string $scriptHash): string
+ public static function scriptHash(string $scriptHash): string
{
if (static::SCRIPT_HASH_LEN != strlen($scriptHash)) {
throw new Exception(sprintf('Invalid script hash: %s.', bin2hex($scriptHash)));
@@ -76,7 +76,7 @@ static public function scriptHash(string $scriptHash): string
* @return string
* @throws Exception
*/
- static public function witnessHash(string $witnessHash): string
+ public static function witnessHash(string $witnessHash): string
{
if (static::WITNESS_HASH_LEN != strlen($witnessHash)) {
throw new Exception(sprintf('Invalid witness hash: %s.', bin2hex($witnessHash)));
@@ -84,4 +84,4 @@ static public function witnessHash(string $witnessHash): string
return $witnessHash;
}
-}
\ No newline at end of file
+}
diff --git a/tests/BitcoinCashTest.php b/tests/BitcoinCashTest.php
index 2ececb6..becb2a8 100644
--- a/tests/BitcoinCashTest.php
+++ b/tests/BitcoinCashTest.php
@@ -15,13 +15,19 @@
*/
class BitcoinCashTest extends TestCase
{
- public function testDecodeP2PKH()
+ public function testDecodeP2PKH(): void
{
- $this->assertInstanceOf(P2pkh::class, NetworkFactory::bitcoinCash()->decodeAddress('bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h'));
+ $this->assertInstanceOf(
+ P2pkh::class,
+ NetworkFactory::bitcoinCash()->decodeAddress('bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h')
+ );
}
- public function testDecodeP2SH()
+ public function testDecodeP2SH(): void
{
- $this->assertInstanceOf(P2sh::class, NetworkFactory::bitcoinCash()->decodeAddress('bitcoincash:pzp7awma0x4p6wyw8v9vvkuc43vqcndqrg9umkmd8g'));
+ $this->assertInstanceOf(
+ P2sh::class,
+ NetworkFactory::bitcoinCash()->decodeAddress('bitcoincash:pzp7awma0x4p6wyw8v9vvkuc43vqcndqrg9umkmd8g')
+ );
}
-}
\ No newline at end of file
+}
diff --git a/tests/BitcoinTest.php b/tests/BitcoinTest.php
index d3e889e..47947c2 100644
--- a/tests/BitcoinTest.php
+++ b/tests/BitcoinTest.php
@@ -18,53 +18,78 @@
*/
class BitcoinTest extends TestCase
{
- public function testDecodeP2PKH()
+ public function testDecodeP2PKH(): void
{
- $this->assertInstanceOf(P2pkh::class, NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'));
+ $this->assertInstanceOf(
+ P2pkh::class,
+ NetworkFactory::bitcoin()->decodeAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')
+ );
}
- public function testDecodeP2SH()
+ public function testDecodeP2SH(): void
{
- $this->assertInstanceOf(P2sh::class, NetworkFactory::bitcoin()->decodeAddress('3DicS6C8JZm59RsrgXr56iVHzYdQngiehV'));
+ $this->assertInstanceOf(
+ P2sh::class,
+ NetworkFactory::bitcoin()->decodeAddress('3DicS6C8JZm59RsrgXr56iVHzYdQngiehV')
+ );
}
- public function testDecodeP2WPKH()
+ public function testDecodeP2WPKH(): void
{
- $this->assertInstanceOf(P2wpkh::class, NetworkFactory::bitcoin()->decodeAddress('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'));
+ $this->assertInstanceOf(
+ P2wpkh::class,
+ NetworkFactory::bitcoin()->decodeAddress('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4')
+ );
}
- public function testDecodeP2WSH()
+ public function testDecodeP2WSH(): void
{
- $this->assertInstanceOf(P2wsh::class, NetworkFactory::bitcoin()->decodeAddress('bc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4plngs'));
+ $this->assertInstanceOf(
+ P2wsh::class,
+ NetworkFactory::bitcoin()->decodeAddress('bc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4plngs')
+ );
}
- public function testDecodeP2TR()
+ public function testDecodeP2TR(): void
{
- $this->assertInstanceOf(P2tr::class, NetworkFactory::bitcoin()->decodeAddress('bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr'));
+ $this->assertInstanceOf(
+ P2tr::class,
+ NetworkFactory::bitcoin()->decodeAddress(
+ 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr'
+ )
+ );
}
- public function testValidateAddress()
+ public function testValidateAddress(): void
{
$this->assertFalse(NetworkFactory::bitcoin()->validateAddress('some'));
}
- public function testValidateAddressP2PKH()
+ public function testValidateAddressP2PKH(): void
{
$this->assertTrue(NetworkFactory::bitcoin()->validateAddress('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'));
}
- public function testValidateAddressP2SH()
+ public function testValidateAddressP2SH(): void
{
$this->assertTrue(NetworkFactory::bitcoin()->validateAddress('3DicS6C8JZm59RsrgXr56iVHzYdQngiehV'));
}
- public function testValidateAddressP2WSH()
+ public function testValidateAddressP2WSH(): void
{
- $this->assertTrue(NetworkFactory::bitcoin()->validateAddress('bc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4plngs'));
+ $this->assertTrue(
+ NetworkFactory::bitcoin()->validateAddress(
+ 'bc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4plngs'
+ )
+ );
}
- public function testValidateAddressP2TR()
+ public function testValidateAddressP2TR(): void
{
- $this->assertTrue(NetworkFactory::bitcoin()->validateAddress('bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr'));
+ $this->assertTrue(
+ NetworkFactory::bitcoin()->validateAddress(
+ 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr'
+ )
+ );
}
-}
\ No newline at end of file
+}
diff --git a/tests/OutputFactoryTest.php b/tests/OutputFactoryTest.php
index aa9fbb6..9d3811a 100644
--- a/tests/OutputFactoryTest.php
+++ b/tests/OutputFactoryTest.php
@@ -24,18 +24,21 @@ class OutputFactoryTest extends TestCase
/**
* @throws Exception
*/
- public function testFromHexP2PK()
+ public function testFromHexP2PK(): void
{
$output = OutputFactory::fromHex('210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac');
$this->assertInstanceOf(P2pk::class, $output);
- $this->assertEquals($output->getPubKey(), hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'));
+ $this->assertEquals(
+ $output->getPubKey(),
+ hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
+ );
$this->assertEquals($output->type(), 'p2pk');
}
/**
* @throws Exception
*/
- public function testFromHexP2PKH()
+ public function testFromHexP2PKH(): void
{
$output = OutputFactory::fromHex('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac');
$this->assertInstanceOf(P2pkh::class, $output);
@@ -46,11 +49,14 @@ public function testFromHexP2PKH()
/**
* @throws Exception
*/
- public function testFromHexP2MS()
+ public function testFromHexP2MS(): void
{
$output = OutputFactory::fromHex('51210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179851ae');
$this->assertInstanceOf(P2ms::class, $output);
- $this->assertEquals($output->getPubKeys(), [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')]);
+ $this->assertEquals(
+ $output->getPubKeys(),
+ [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')]
+ );
$this->assertEquals($output->getSigCount(), 1);
$this->assertEquals($output->type(), 'p2ms');
}
@@ -58,7 +64,7 @@ public function testFromHexP2MS()
/**
* @throws Exception
*/
- public function testFromHexP2SH()
+ public function testFromHexP2SH(): void
{
$output = OutputFactory::fromHex('a91483eebb7d79aa1d388e3b0ac65b98ac580c4da01a87');
$this->assertInstanceOf(P2sh::class, $output);
@@ -69,7 +75,7 @@ public function testFromHexP2SH()
/**
* @throws Exception
*/
- public function testFromHexP2WPKH()
+ public function testFromHexP2WPKH(): void
{
$output = OutputFactory::fromHex('0014751e76e8199196d454941c45d1b3a323f1433bd6');
$this->assertInstanceOf(P2wpkh::class, $output);
@@ -80,22 +86,28 @@ public function testFromHexP2WPKH()
/**
* @throws Exception
*/
- public function testFromHexP2WSH()
+ public function testFromHexP2WSH(): void
{
$output = OutputFactory::fromHex('002028205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f');
$this->assertInstanceOf(P2wsh::class, $output);
- $this->assertEquals($output->getWitnessHash(), hex2bin('28205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f'));
+ $this->assertEquals(
+ $output->getWitnessHash(),
+ hex2bin('28205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f')
+ );
$this->assertEquals($output->type(), 'p2wsh');
}
/**
* @throws Exception
*/
- public function testFromHexP2TR()
+ public function testFromHexP2TR(): void
{
$output = OutputFactory::fromHex('5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c');
$this->assertInstanceOf(P2tr::class, $output);
- $this->assertEquals($output->getTaprootPubKey(), hex2bin('a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c'));
+ $this->assertEquals(
+ $output->getTaprootPubKey(),
+ hex2bin('a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c')
+ );
$this->assertEquals($output->type(), 'p2tr');
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2msTest.php b/tests/P2msTest.php
index f3222e0..bb45c02 100644
--- a/tests/P2msTest.php
+++ b/tests/P2msTest.php
@@ -22,31 +22,40 @@ class P2msTest extends TestCase
*/
protected function getOutput(): OutputInterface
{
- return OutputFactory::p2ms(1, [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')]);
+ return OutputFactory::p2ms(
+ 1,
+ [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798') ?: '']
+ );
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('51210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179851ae', $this->getOutput()->hex());
+ $this->assertEquals(
+ '51210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179851ae',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('1 PUSHDATA(33)[0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798] 1 CHECKMULTISIG', $this->getOutput()->asm());
+ $this->assertEquals(
+ '1 PUSHDATA(33)[0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798] 1 CHECKMULTISIG',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2ms::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2pkTest.php b/tests/P2pkTest.php
index 89e0526..08ee378 100644
--- a/tests/P2pkTest.php
+++ b/tests/P2pkTest.php
@@ -21,31 +21,37 @@ class P2pkTest extends P2pkhTest
*/
protected function getOutput(): OutputInterface
{
- return OutputFactory::p2pk(hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'));
+ return OutputFactory::p2pk(hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798') ?: '');
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac', $this->getOutput()->hex());
+ $this->assertEquals(
+ '210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('PUSHDATA(33)[0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798] CHECKSIG', $this->getOutput()->asm());
+ $this->assertEquals(
+ 'PUSHDATA(33)[0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798] CHECKSIG',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2pk::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2pkhTest.php b/tests/P2pkhTest.php
index 1987118..dd054dc 100644
--- a/tests/P2pkhTest.php
+++ b/tests/P2pkhTest.php
@@ -23,133 +23,178 @@ class P2pkhTest extends TestCase
*/
protected function getOutput(): OutputInterface
{
- return OutputFactory::p2pkh(hex2bin('751e76e8199196d454941c45d1b3a323f1433bd6'));
+ return OutputFactory::p2pkh(hex2bin('751e76e8199196d454941c45d1b3a323f1433bd6') ?: '');
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac', $this->getOutput()->hex());
+ $this->assertEquals(
+ '76a914751e76e8199196d454941c45d1b3a323f1433bd688ac',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('DUP HASH160 PUSHDATA(20)[751e76e8199196d454941c45d1b3a323f1433bd6] EQUALVERIFY CHECKSIG', $this->getOutput()->asm());
+ $this->assertEquals(
+ 'DUP HASH160 PUSHDATA(20)[751e76e8199196d454941c45d1b3a323f1433bd6] EQUALVERIFY CHECKSIG',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoin()
+ public function testAddressBitcoin(): void
{
- $this->assertEquals('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH', $this->getOutput()->address());
+ $this->assertEquals(
+ '1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH',
+ $this->getOutput()->address()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinTestnet()
+ public function testAddressBitcoinTestnet(): void
{
- $this->assertEquals('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', $this->getOutput()->address(NetworkFactory::bitcoinTestnet()));
+ $this->assertEquals(
+ 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r',
+ $this->getOutput()->address(NetworkFactory::bitcoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinCash()
+ public function testAddressBitcoinCash(): void
{
- $this->assertEquals('bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h', $this->getOutput()->address(NetworkFactory::bitcoinCash()));
+ $this->assertEquals(
+ 'bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h',
+ $this->getOutput()->address(NetworkFactory::bitcoinCash())
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinGold()
+ public function testAddressBitcoinGold(): void
{
- $this->assertEquals('GUXByHDZLvU4DnVH9imSFckt3HEQ5cFgE5', $this->getOutput()->address(NetworkFactory::bitcoinGold()));
+ $this->assertEquals(
+ 'GUXByHDZLvU4DnVH9imSFckt3HEQ5cFgE5',
+ $this->getOutput()->address(NetworkFactory::bitcoinGold())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoin()
+ public function testAddressLitecoin(): void
{
- $this->assertEquals('LVuDpNCSSj6pQ7t9Pv6d6sUkLKoqDEVUnJ', $this->getOutput()->address(NetworkFactory::litecoin()));
+ $this->assertEquals(
+ 'LVuDpNCSSj6pQ7t9Pv6d6sUkLKoqDEVUnJ',
+ $this->getOutput()->address(NetworkFactory::litecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoinTestnet()
+ public function testAddressLitecoinTestnet(): void
{
- $this->assertEquals('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', $this->getOutput()->address(NetworkFactory::litecoinTestnet()));
+ $this->assertEquals(
+ 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r',
+ $this->getOutput()->address(NetworkFactory::litecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDogecoin()
+ public function testAddressDogecoin(): void
{
- $this->assertEquals('DFpN6QqFfUm3gKNaxN6tNcab1FArL9cZLE', $this->getOutput()->address(NetworkFactory::dogecoin()));
+ $this->assertEquals(
+ 'DFpN6QqFfUm3gKNaxN6tNcab1FArL9cZLE',
+ $this->getOutput()->address(NetworkFactory::dogecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDogecoinTestnet()
+ public function testAddressDogecoinTestnet(): void
{
- $this->assertEquals('nesRpRaAbTDmZHwmzBkLd2AtF7Z9L9z5S2', $this->getOutput()->address(NetworkFactory::dogecoinTestnet()));
+ $this->assertEquals(
+ 'nesRpRaAbTDmZHwmzBkLd2AtF7Z9L9z5S2',
+ $this->getOutput()->address(NetworkFactory::dogecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoin()
+ public function testAddressViacoin(): void
{
- $this->assertEquals('Vkg6Ts44mskyD668xZkxFkjqovjXX9yUzZ', $this->getOutput()->address(NetworkFactory::viacoin()));
+ $this->assertEquals(
+ 'Vkg6Ts44mskyD668xZkxFkjqovjXX9yUzZ',
+ $this->getOutput()->address(NetworkFactory::viacoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoinTestnet()
+ public function testAddressViacoinTestnet(): void
{
- $this->assertEquals('tHbsbwkCXyi31MtzL4QoQmyu4BAMJz8hS6', $this->getOutput()->address(NetworkFactory::viacoinTestnet()));
+ $this->assertEquals(
+ 'tHbsbwkCXyi31MtzL4QoQmyu4BAMJz8hS6',
+ $this->getOutput()->address(NetworkFactory::viacoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDash()
+ public function testAddressDash(): void
{
- $this->assertEquals('XmN7PQYWKn5MJFna5fRYgP6mxT2F7xpekE', $this->getOutput()->address(NetworkFactory::dash()));
+ $this->assertEquals(
+ 'XmN7PQYWKn5MJFna5fRYgP6mxT2F7xpekE',
+ $this->getOutput()->address(NetworkFactory::dash())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDashTestnet()
+ public function testAddressDashTestnet(): void
{
- $this->assertEquals('y7f7RFKf49GYpZa2d6QdEHFLcEFfuoNcer', $this->getOutput()->address(NetworkFactory::dashTestnet()));
+ $this->assertEquals(
+ 'y7f7RFKf49GYpZa2d6QdEHFLcEFfuoNcer',
+ $this->getOutput()->address(NetworkFactory::dashTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressZcash()
+ public function testAddressZcash(): void
{
- $this->assertEquals('t1UYsZVJkLPeMjxEtACvSxfWuNmddpWfxzs', $this->getOutput()->address(NetworkFactory::zcash()));
+ $this->assertEquals(
+ 't1UYsZVJkLPeMjxEtACvSxfWuNmddpWfxzs',
+ $this->getOutput()->address(NetworkFactory::zcash())
+ );
}
/**
* @throws Exception
*/
- public function testAddressClams()
+ public function testAddressClams(): void
{
$this->assertEquals('xJyuT2j5dnLoBhHraFjzG2hmMDjnS3fefx', $this->getOutput()->address(NetworkFactory::clams()));
}
@@ -157,9 +202,9 @@ public function testAddressClams()
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2pkh::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2shTest.php b/tests/P2shTest.php
index 243590d..00b16cd 100644
--- a/tests/P2shTest.php
+++ b/tests/P2shTest.php
@@ -24,30 +24,39 @@ class P2shTest extends TestCase
protected function getOutput(): OutputInterface
{
$factory = new OutputFactory();
- $p2ms = $factory->p2ms(1, [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')]);
+ $p2ms = $factory->p2ms(
+ 1,
+ [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798') ?: '']
+ );
return $factory->p2sh($p2ms);
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('a91483eebb7d79aa1d388e3b0ac65b98ac580c4da01a87', $this->getOutput()->hex());
+ $this->assertEquals(
+ 'a91483eebb7d79aa1d388e3b0ac65b98ac580c4da01a87',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('HASH160 PUSHDATA(20)[83eebb7d79aa1d388e3b0ac65b98ac580c4da01a] EQUAL', $this->getOutput()->asm());
+ $this->assertEquals(
+ 'HASH160 PUSHDATA(20)[83eebb7d79aa1d388e3b0ac65b98ac580c4da01a] EQUAL',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoin()
+ public function testAddressBitcoin(): void
{
$this->assertEquals('3DicS6C8JZm59RsrgXr56iVHzYdQngiehV', $this->getOutput()->address());
}
@@ -55,103 +64,139 @@ public function testAddressBitcoin()
/**
* @throws Exception
*/
- public function testAddressBitcoinTestnet()
+ public function testAddressBitcoinTestnet(): void
{
- $this->assertEquals('2N5GpVq89v2GRMDWQMfTwifUZCtqaczC6Y7', $this->getOutput()->address(NetworkFactory::bitcoinTestnet()));
+ $this->assertEquals(
+ '2N5GpVq89v2GRMDWQMfTwifUZCtqaczC6Y7',
+ $this->getOutput()->address(NetworkFactory::bitcoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinCash()
+ public function testAddressBitcoinCash(): void
{
- $this->assertEquals('bitcoincash:pzp7awma0x4p6wyw8v9vvkuc43vqcndqrg9umkmd8g', $this->getOutput()->address(NetworkFactory::bitcoinCash()));
+ $this->assertEquals(
+ 'bitcoincash:pzp7awma0x4p6wyw8v9vvkuc43vqcndqrg9umkmd8g',
+ $this->getOutput()->address(NetworkFactory::bitcoinCash())
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinGold()
+ public function testAddressBitcoinGold(): void
{
- $this->assertEquals('AToUA3ZK5p6qsEPR85qopyPTKdGPaUNd9V', $this->getOutput()->address(NetworkFactory::bitcoinGold()));
+ $this->assertEquals(
+ 'AToUA3ZK5p6qsEPR85qopyPTKdGPaUNd9V',
+ $this->getOutput()->address(NetworkFactory::bitcoinGold())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoin()
+ public function testAddressLitecoin(): void
{
- $this->assertEquals('MKvkjyc6FgcVww9knQqQvMjhKFDrpERUsa', $this->getOutput()->address(NetworkFactory::litecoin()));
+ $this->assertEquals(
+ 'MKvkjyc6FgcVww9knQqQvMjhKFDrpERUsa',
+ $this->getOutput()->address(NetworkFactory::litecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoinTestnet()
+ public function testAddressLitecoinTestnet(): void
{
- $this->assertEquals('QYdacqzPw8KWVQGSymVxoMuzMHHQYBayi6', $this->getOutput()->address(NetworkFactory::litecoinTestnet()));
+ $this->assertEquals(
+ 'QYdacqzPw8KWVQGSymVxoMuzMHHQYBayi6',
+ $this->getOutput()->address(NetworkFactory::litecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDogecoin()
+ public function testAddressDogecoin(): void
{
- $this->assertEquals('A4TsAwG2Nddy3oFL6fWVLr7fh81SuuSoLQ', $this->getOutput()->address(NetworkFactory::dogecoin()));
+ $this->assertEquals(
+ 'A4TsAwG2Nddy3oFL6fWVLr7fh81SuuSoLQ',
+ $this->getOutput()->address(NetworkFactory::dogecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDogecoinTestnet()
+ public function testAddressDogecoinTestnet(): void
{
- $this->assertEquals('2N5GpVq89v2GRMDWQMfTwifUZCtqaczC6Y7', $this->getOutput()->address(NetworkFactory::dogecoinTestnet()));
+ $this->assertEquals(
+ '2N5GpVq89v2GRMDWQMfTwifUZCtqaczC6Y7',
+ $this->getOutput()->address(NetworkFactory::dogecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoin()
+ public function testAddressViacoin(): void
{
- $this->assertEquals('EVBW18YCBcjc3ZnHNHAzgE7KcfqpgPjScU', $this->getOutput()->address(NetworkFactory::viacoin()));
+ $this->assertEquals(
+ 'EVBW18YCBcjc3ZnHNHAzgE7KcfqpgPjScU',
+ $this->getOutput()->address(NetworkFactory::viacoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoinTestnet()
+ public function testAddressViacoinTestnet(): void
{
- $this->assertEquals('2N5GpVq89v2GRMDWQMfTwifUZCtqaczC6Y7', $this->getOutput()->address(NetworkFactory::viacoinTestnet()));
+ $this->assertEquals(
+ '2N5GpVq89v2GRMDWQMfTwifUZCtqaczC6Y7',
+ $this->getOutput()->address(NetworkFactory::viacoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDash()
+ public function testAddressDash(): void
{
- $this->assertEquals('7eSFGHUJ7Yri9CQox9WaS6Uwv6TngFDeEa', $this->getOutput()->address(NetworkFactory::dash()));
+ $this->assertEquals(
+ '7eSFGHUJ7Yri9CQox9WaS6Uwv6TngFDeEa',
+ $this->getOutput()->address(NetworkFactory::dash())
+ );
}
/**
* @throws Exception
*/
- public function testAddressDashTestnet()
+ public function testAddressDashTestnet(): void
{
- $this->assertEquals('8rT4DcNAF6FLbVq52QWXtUJJocEcmYMNRG', $this->getOutput()->address(NetworkFactory::dashTestnet()));
+ $this->assertEquals(
+ '8rT4DcNAF6FLbVq52QWXtUJJocEcmYMNRG',
+ $this->getOutput()->address(NetworkFactory::dashTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressZcash()
+ public function testAddressZcash(): void
{
- $this->assertEquals('t3WbDSRcGGtYfk4vkcxfCEXbDFCpVZxhxKh', $this->getOutput()->address(NetworkFactory::zcash()));
+ $this->assertEquals(
+ 't3WbDSRcGGtYfk4vkcxfCEXbDFCpVZxhxKh',
+ $this->getOutput()->address(NetworkFactory::zcash())
+ );
}
/**
* @throws Exception
*/
- public function testAddressClams()
+ public function testAddressClams(): void
{
$this->assertEquals('6SRSJxaRz1U5gtzYstWcyifb2agxWxnFiW', $this->getOutput()->address(NetworkFactory::clams()));
}
@@ -159,9 +204,9 @@ public function testAddressClams()
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2sh::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2trTest.php b/tests/P2trTest.php
index 83a79ba..c636774 100644
--- a/tests/P2trTest.php
+++ b/tests/P2trTest.php
@@ -24,64 +24,84 @@ class P2trTest extends TestCase
*/
protected function getOutput(): OutputInterface
{
- $taprootPubKey = Taproot::construct(hex2bin('03cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115'));
+ $taprootPubKey = Taproot::construct(
+ hex2bin('03cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115') ?: ''
+ );
return OutputFactory::p2tr($taprootPubKey);
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c', $this->getOutput()->hex());
+ $this->assertEquals(
+ '5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('1 PUSHDATA(32)[a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c]', $this->getOutput()->asm());
+ $this->assertEquals(
+ '1 PUSHDATA(32)[a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c]',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoin()
+ public function testAddressBitcoin(): void
{
- $this->assertEquals('bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr', $this->getOutput()->address());
+ $this->assertEquals(
+ 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr',
+ $this->getOutput()->address()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinTestnet()
+ public function testAddressBitcoinTestnet(): void
{
- $this->assertEquals('tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv', $this->getOutput()->address(NetworkFactory::bitcoinTestnet()));
+ $this->assertEquals(
+ 'tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv',
+ $this->getOutput()->address(NetworkFactory::bitcoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoin()
+ public function testAddressLitecoin(): void
{
- $this->assertEquals('ltc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxq4arnzx', $this->getOutput()->address(NetworkFactory::litecoin()));
+ $this->assertEquals(
+ 'ltc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxq4arnzx',
+ $this->getOutput()->address(NetworkFactory::litecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoinTestnet()
+ public function testAddressLitecoinTestnet(): void
{
- $this->assertEquals('tltc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxq7j8dan', $this->getOutput()->address(NetworkFactory::litecoinTestnet()));
+ $this->assertEquals(
+ 'tltc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxq7j8dan',
+ $this->getOutput()->address(NetworkFactory::litecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2tr::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2wpkhTest.php b/tests/P2wpkhTest.php
index 639b3ea..734d753 100644
--- a/tests/P2wpkhTest.php
+++ b/tests/P2wpkhTest.php
@@ -23,79 +23,103 @@ class P2wpkhTest extends TestCase
*/
protected function getOutput(): OutputInterface
{
- return OutputFactory::p2wpkh(hex2bin('751e76e8199196d454941c45d1b3a323f1433bd6'));
+ return OutputFactory::p2wpkh(hex2bin('751e76e8199196d454941c45d1b3a323f1433bd6') ?: '');
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('0014751e76e8199196d454941c45d1b3a323f1433bd6', $this->getOutput()->hex());
+ $this->assertEquals(
+ '0014751e76e8199196d454941c45d1b3a323f1433bd6',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('0 PUSHDATA(20)[751e76e8199196d454941c45d1b3a323f1433bd6]', $this->getOutput()->asm());
+ $this->assertEquals(
+ '0 PUSHDATA(20)[751e76e8199196d454941c45d1b3a323f1433bd6]',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoin()
+ public function testAddressBitcoin(): void
{
- $this->assertEquals('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4', $this->getOutput()->address());
+ $this->assertEquals(
+ 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
+ $this->getOutput()->address()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinTestnet()
+ public function testAddressBitcoinTestnet(): void
{
- $this->assertEquals('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', $this->getOutput()->address(NetworkFactory::bitcoinTestnet()));
+ $this->assertEquals(
+ 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
+ $this->getOutput()->address(NetworkFactory::bitcoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoin()
+ public function testAddressLitecoin(): void
{
- $this->assertEquals('ltc1qw508d6qejxtdg4y5r3zarvary0c5xw7kgmn4n9', $this->getOutput()->address(NetworkFactory::litecoin()));
+ $this->assertEquals(
+ 'ltc1qw508d6qejxtdg4y5r3zarvary0c5xw7kgmn4n9',
+ $this->getOutput()->address(NetworkFactory::litecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoinTestnet()
+ public function testAddressLitecoinTestnet(): void
{
- $this->assertEquals('tltc1qw508d6qejxtdg4y5r3zarvary0c5xw7klfsuq0', $this->getOutput()->address(NetworkFactory::litecoinTestnet()));
+ $this->assertEquals(
+ 'tltc1qw508d6qejxtdg4y5r3zarvary0c5xw7klfsuq0',
+ $this->getOutput()->address(NetworkFactory::litecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoin()
+ public function testAddressViacoin(): void
{
- $this->assertEquals('via1qw508d6qejxtdg4y5r3zarvary0c5xw7kxzdzsn', $this->getOutput()->address(NetworkFactory::viacoin()));
+ $this->assertEquals(
+ 'via1qw508d6qejxtdg4y5r3zarvary0c5xw7kxzdzsn',
+ $this->getOutput()->address(NetworkFactory::viacoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoinTestnet()
+ public function testAddressViacoinTestnet(): void
{
- $this->assertEquals('tvia1qw508d6qejxtdg4y5r3zarvary0c5xw7k3swtre', $this->getOutput()->address(NetworkFactory::viacoinTestnet()));
+ $this->assertEquals(
+ 'tvia1qw508d6qejxtdg4y5r3zarvary0c5xw7k3swtre',
+ $this->getOutput()->address(NetworkFactory::viacoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2wpkh::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/P2wshTest.php b/tests/P2wshTest.php
index 2caf16d..b177538 100644
--- a/tests/P2wshTest.php
+++ b/tests/P2wshTest.php
@@ -24,80 +24,107 @@ class P2wshTest extends TestCase
protected function getOutput(): OutputInterface
{
$factory = new OutputFactory();
- $p2ms = $factory->p2ms(1, [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')]);
+ $p2ms = $factory->p2ms(
+ 1,
+ [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798') ?: '']
+ );
return $factory->p2wsh($p2ms);
}
/**
* @throws Exception
*/
- public function testHex()
+ public function testHex(): void
{
- $this->assertEquals('002028205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f', $this->getOutput()->hex());
+ $this->assertEquals(
+ '002028205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f',
+ $this->getOutput()->hex()
+ );
}
/**
* @throws Exception
*/
- public function testAsm()
+ public function testAsm(): void
{
- $this->assertEquals('0 PUSHDATA(32)[28205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f]', $this->getOutput()->asm());
+ $this->assertEquals(
+ '0 PUSHDATA(32)[28205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f]',
+ $this->getOutput()->asm()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoin()
+ public function testAddressBitcoin(): void
{
- $this->assertEquals('bc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4plngs', $this->getOutput()->address());
+ $this->assertEquals(
+ 'bc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4plngs',
+ $this->getOutput()->address()
+ );
}
/**
* @throws Exception
*/
- public function testAddressBitcoinTestnet()
+ public function testAddressBitcoinTestnet(): void
{
- $this->assertEquals('tb1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8szffujl', $this->getOutput()->address(NetworkFactory::bitcoinTestnet()));
+ $this->assertEquals(
+ 'tb1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8szffujl',
+ $this->getOutput()->address(NetworkFactory::bitcoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoin()
+ public function testAddressLitecoin(): void
{
- $this->assertEquals('ltc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8sk93rj4', $this->getOutput()->address(NetworkFactory::litecoin()));
+ $this->assertEquals(
+ 'ltc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8sk93rj4',
+ $this->getOutput()->address(NetworkFactory::litecoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressLitecoinTestnet()
+ public function testAddressLitecoinTestnet(): void
{
- $this->assertEquals('tltc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8sa24adq', $this->getOutput()->address(NetworkFactory::litecoinTestnet()));
+ $this->assertEquals(
+ 'tltc1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8sa24adq',
+ $this->getOutput()->address(NetworkFactory::litecoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoin()
+ public function testAddressViacoin(): void
{
- $this->assertEquals('via1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s7ulzpx', $this->getOutput()->address(NetworkFactory::viacoin()));
+ $this->assertEquals(
+ 'via1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s7ulzpx',
+ $this->getOutput()->address(NetworkFactory::viacoin())
+ );
}
/**
* @throws Exception
*/
- public function testAddressViacoinTestnet()
+ public function testAddressViacoinTestnet(): void
{
- $this->assertEquals('tvia1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4nmu7n', $this->getOutput()->address(NetworkFactory::viacoinTestnet()));
+ $this->assertEquals(
+ 'tvia1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8s4nmu7n',
+ $this->getOutput()->address(NetworkFactory::viacoinTestnet())
+ );
}
/**
* @throws Exception
*/
- public function testFromScript()
+ public function testFromScript(): void
{
$output = $this->getOutput();
$this->assertEquals($output->script(), P2wsh::fromScript($output->script())->script());
}
-}
\ No newline at end of file
+}
diff --git a/tests/TaprootTest.php b/tests/TaprootTest.php
index a11460e..a76d53b 100644
--- a/tests/TaprootTest.php
+++ b/tests/TaprootTest.php
@@ -15,22 +15,26 @@
*/
class TaprootTest extends TestCase
{
- function testAddress()
+ public function testAddress(): void
{
$pubKeys = [
- '026f7b861432127845aac3f0685f03359d73c5009929cfa88920aaba8419e0d3fc' => 'tb1pw9d6svmf4zsl27qnz76fcmz9yxpeqsz0xqsed59pdh68lr4ud5vsjk506u',
- '02be3a48320efd83fb3c80c961a06b25c3049f63a0b0d9009c27ecbbca80fb2d85' => 'tb1p8969s4chlgj6jncd0qyqv77cha00uk7v6nnm4pzpr67u7p4jkgsqemy6yq',
- '03ee397d520b5a9e59b0813eed5f84274af42ba2fa074cd5c68ad01b1b1521ecb1' => 'tb1pk9v0nuu0cr78c9lmrl22crdjwtxhsr0ekjuv9p8hkjquwtnknxdqprjpjh',
- '0367ca30afae9d9b5374c9d34b0dc684044bf04a19c9a299b1d68bd6da173c9ccb' => 'tb1pyxakgvcv6cq2zakm599zuxs7mljfww0fj9k00w3z9e5g8uf4gujqxwws6a',
+ '026f7b861432127845aac3f0685f03359d73c5009929cfa88920aaba8419e0d3fc'
+ => 'tb1pw9d6svmf4zsl27qnz76fcmz9yxpeqsz0xqsed59pdh68lr4ud5vsjk506u',
+ '02be3a48320efd83fb3c80c961a06b25c3049f63a0b0d9009c27ecbbca80fb2d85'
+ => 'tb1p8969s4chlgj6jncd0qyqv77cha00uk7v6nnm4pzpr67u7p4jkgsqemy6yq',
+ '03ee397d520b5a9e59b0813eed5f84274af42ba2fa074cd5c68ad01b1b1521ecb1'
+ => 'tb1pk9v0nuu0cr78c9lmrl22crdjwtxhsr0ekjuv9p8hkjquwtnknxdqprjpjh',
+ '0367ca30afae9d9b5374c9d34b0dc684044bf04a19c9a299b1d68bd6da173c9ccb'
+ => 'tb1pyxakgvcv6cq2zakm599zuxs7mljfww0fj9k00w3z9e5g8uf4gujqxwws6a',
];
$network = NetworkFactory::bitcoinTestnet();
foreach ($pubKeys as $pubKey => $address) {
$this->assertEquals(
- OutputFactory::p2tr(Taproot::construct(hex2bin($pubKey)))->address($network),
+ OutputFactory::p2tr(Taproot::construct(hex2bin($pubKey) ?: ''))->address($network),
$address
);
}
}
-}
\ No newline at end of file
+}