Completed
Pull Request — master (#89)
by thomas
20:32
created
src/BlocktrailSDKInterface.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace Blocktrail\SDK;
4 4
 
5
-use BitWasp\Bitcoin\Network\NetworkInterface;
6 5
 use Blocktrail\SDK\Connection\RestClient;
7 6
 
8 7
 /**
Please login to merge, or discard this patch.
src/TransactionBuilder.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 use BitWasp\Bitcoin\Address\AddressInterface;
7 7
 use BitWasp\Bitcoin\Address\SegwitAddress;
8 8
 use BitWasp\Bitcoin\Network\NetworkInterface;
9
-use BitWasp\Bitcoin\Script\Script;
10 9
 use BitWasp\Bitcoin\Script\ScriptFactory;
11 10
 use BitWasp\Bitcoin\Script\ScriptInterface;
12 11
 use BitWasp\Buffertools\Buffer;
Please login to merge, or discard this patch.
src/Wallet.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use BitWasp\Bitcoin\Address\AddressFactory;
6 6
 use BitWasp\Bitcoin\Bitcoin;
7
-use BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeyFactory;
8 7
 use BitWasp\Bitcoin\MessageSigner\MessageSigner;
9 8
 use BitWasp\Bitcoin\Network\NetworkInterface;
10 9
 use BitWasp\Bitcoin\Script\P2shScript;
Please login to merge, or discard this patch.
src/WalletSweeper.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @param array               $blocktrailPublicKeys =
73 73
      * @param UnspentOutputFinder $utxoFinder
74 74
      * @param string $network
75
-     * @param bool $testnet
75
+     * @param bool $tesnet
76 76
      * @throws \Exception
77 77
      */
78 78
     public function __construct(BufferInterface $primarySeed, BufferInterface $backupSeed, array $blocktrailPublicKeys, UnspentOutputFinder $utxoFinder, $network, $tesnet = false) {
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     /**
111 111
      * generate multisig address for given path
112 112
      *
113
-     * @param string|BIP32Path $path
113
+     * @param string $path
114 114
      * @return array[string, ScriptInterface]                 [address, redeemScript]
115 115
      * @throws \Exception
116 116
      */
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     /**
140 140
      * create a batch of multisig addresses
141 141
      *
142
-     * @param $start
143
-     * @param $count
142
+     * @param integer $start
143
+     * @param integer $count
144 144
      * @param $keyIndex
145 145
      * @return array
146 146
      */
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     /**
171 171
      * gets the blocktrail pub key for the given path from the stored array of pub keys
172 172
      *
173
-     * @param string|BIP32Path  $path
173
+     * @param BIP32Path  $path
174 174
      * @return BIP32Key
175 175
      * @throws \Exception
176 176
      */
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
     }
289 289
 
290 290
     /**
291
-     * @param $destinationAddress
291
+     * @param string $destinationAddress
292 292
      * @return TransactionInterface
293 293
      */
294 294
     protected function createTransaction($destinationAddress) {
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,6 @@
 block discarded – undo
5 5
 use BitWasp\Bitcoin\Address\AddressFactory;
6 6
 use BitWasp\Bitcoin\Bitcoin;
7 7
 use BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeyFactory;
8
-use BitWasp\Bitcoin\Network\NetworkFactory;
9
-use BitWasp\Bitcoin\Network\NetworkInterface;
10 8
 use BitWasp\Bitcoin\Script\P2shScript;
11 9
 use BitWasp\Bitcoin\Script\ScriptFactory;
12 10
 use BitWasp\Bitcoin\Script\WitnessScript;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
             $this->getBlocktrailPublicKey($path)->buildKey($path)->publicKey()
124 124
         ]), false);
125 125
 
126
-        if ($this->networkParams->getName() !== "bitcoincash" && (int) $path[2] === 2) {
126
+        if ($this->networkParams->getName() !== "bitcoincash" && (int)$path[2] === 2) {
127 127
             $witnessScript = new WitnessScript($multisig);
128 128
             $redeemScript = new P2shScript($witnessScript);
129 129
             $address = $redeemScript->getAddress()->getAddress($this->networkParams->getNetwork());
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 
150 150
         for ($i = 0; $i < $count; $i++) {
151 151
             //create a path subsequent address
152
-            $path = (string)WalletPath::create($keyIndex, $_chain = 0, $start+$i)->path()->publicPath();
152
+            $path = (string)WalletPath::create($keyIndex, $_chain = 0, $start + $i)->path()->publicPath();
153 153
             list($address, $redeem, $witness) = $this->createAddress($path);
154 154
             $addresses[$address] = array(
155 155
                 //'address' => $address,
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
         $totalUTXOs = 0;
199 199
         $totalAddressesGenerated = 0;
200 200
 
201
-        $addressUTXOs = array();    //addresses and their utxos, paths and redeem scripts
201
+        $addressUTXOs = array(); //addresses and their utxos, paths and redeem scripts
202 202
 
203 203
         //for each blocktrail pub key, do fund discovery on batches of addresses
204 204
         foreach ($this->blocktrailPublicKeys as $keyIndex => $blocktrailPubKey) {
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
                     }
235 235
 
236 236
                     $addressUTXOs[$address]['utxos'][] = $utxo;
237
-                    $totalUTXOs ++;
237
+                    $totalUTXOs++;
238 238
 
239 239
                     //add up the total utxo value for all addresses
240 240
                     $totalBalance += $utxo['value'];
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
             $signer->redeemBitcoinCash(true);
350 350
         }
351 351
 
352
-        assert(Util::all(function ($signInfo) {
352
+        assert(Util::all(function($signInfo) {
353 353
             return $signInfo instanceof SignInfo;
354 354
         }, $signInfo), '$signInfo should be SignInfo[]');
355 355
 
Please login to merge, or discard this patch.
src/BlocktrailSDK.php 2 patches
Spacing   +9 added lines, -12 removed lines patch added patch discarded remove patch
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @return array[]            array containing the response
292 292
      */
293 293
     public function transactions($txhashes) {
294
-        $response = $this->client->get("transactions/" . implode(",", $txhashes));
294
+        $response = $this->client->get("transactions/".implode(",", $txhashes));
295 295
         return self::jsonDecode($response->body(), true);
296 296
     }
297 297
     
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
     }
543 543
 
544 544
     private function formatBlocktrailKeys(NetworkInterface $network, array $blocktrailPublicKeys) {
545
-        return Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) use ($network) {
545
+        return Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) use ($network) {
546 546
             return [$keyIndex, BIP32Key::create($network, HierarchicalKeyFactory::fromExtended($pubKeyTuple[0], $network), $pubKeyTuple[1])];
547 547
         }, $blocktrailPublicKeys);
548 548
     }
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
             } else {
565 565
                 // create new primary seed
566 566
                 /** @var HierarchicalKey $primaryPrivateKey */
567
-                list($primaryMnemonic, , $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']);
567
+                list($primaryMnemonic,, $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']);
568 568
                 if ($storePrimaryMnemonic !== false) {
569 569
                     $storePrimaryMnemonic = true;
570 570
                 }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
         $backupPublicKey = null;
605 605
         if (!isset($options['backup_mnemonic']) && !isset($options['backup_public_key'])) {
606 606
             /** @var HierarchicalKey $backupPrivateKey */
607
-            list($backupMnemonic, , ) = $this->newBackupSeed();
607
+            list($backupMnemonic,,) = $this->newBackupSeed();
608 608
         } else if (isset($options['backup_mnemonic'])) {
609 609
             $backupMnemonic = $options['backup_mnemonic'];
610 610
         } elseif (isset($options['backup_public_key'])) {
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
                 'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer($backupSeed)) : null,
775 775
                 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($recoveryEncryptedSecret))) : null,
776 776
                 'encrypted_secret' => $encryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($encryptedSecret))) : null,
777
-                'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) {
777
+                'blocktrail_public_keys' => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) {
778 778
                     return [$keyIndex, $pubKey->tuple()];
779 779
                 }, $blocktrailPublicKeys),
780 780
             ],
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
                 'backup_seed'               => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic($backupSeed) : null,
911 911
                 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? EncryptionMnemonic::encode($recoveryEncryptedSecret) : null,
912 912
                 'encrypted_secret'          => $encryptedSecret ? EncryptionMnemonic::encode($encryptedSecret) : null,
913
-                'blocktrail_public_keys'    => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) {
913
+                'blocktrail_public_keys'    => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) {
914 914
                     return [$keyIndex, $pubKey->tuple()];
915 915
                 }, $blocktrailPublicKeys),
916 916
             ]
@@ -1082,10 +1082,7 @@  discard block
 block discarded – undo
1082 1082
         }
1083 1083
 
1084 1084
         $identifier = $options['identifier'];
1085
-        $readonly = isset($options['readonly']) ? $options['readonly'] :
1086
-                    (isset($options['readOnly']) ? $options['readOnly'] :
1087
-                        (isset($options['read-only']) ? $options['read-only'] :
1088
-                            false));
1085
+        $readonly = isset($options['readonly']) ? $options['readonly'] : (isset($options['readOnly']) ? $options['readOnly'] : (isset($options['read-only']) ? $options['read-only'] : false));
1089 1086
 
1090 1087
         // get the wallet data from the server
1091 1088
         $data = $this->getWallet($identifier);
@@ -1762,7 +1759,7 @@  discard block
 block discarded – undo
1762 1759
      */
1763 1760
     public static function sortMultisigKeys(array $pubKeys) {
1764 1761
         $result = array_values($pubKeys);
1765
-        usort($result, function (PublicKeyInterface $a, PublicKeyInterface $b) {
1762
+        usort($result, function(PublicKeyInterface $a, PublicKeyInterface $b) {
1766 1763
             $av = $a->getHex();
1767 1764
             $bv = $b->getHex();
1768 1765
             return $av == $bv ? 0 : $av > $bv ? 1 : -1;
@@ -1788,7 +1785,7 @@  discard block
 block discarded – undo
1788 1785
     }
1789 1786
 
1790 1787
     public static function normalizeBIP32KeyArray($keys, NetworkInterface $network) {
1791
-        return Util::arrayMapWithIndex(function ($idx, $key) use ($network) {
1788
+        return Util::arrayMapWithIndex(function($idx, $key) use ($network) {
1792 1789
             return [$idx, self::normalizeBIP32Key($key, $network)];
1793 1790
         }, $keys);
1794 1791
     }
Please login to merge, or discard this patch.
Doc Comments   +19 added lines, -11 removed lines patch added patch discarded remove patch
@@ -663,6 +663,11 @@  discard block
 block discarded – undo
663 663
         ];
664 664
     }
665 665
 
666
+    /**
667
+     * @param integer $bits
668
+     *
669
+     * @return string
670
+     */
666 671
     public static function randomBits($bits) {
667 672
         return self::randomBytes($bits / 8);
668 673
     }
@@ -955,7 +960,7 @@  discard block
 block discarded – undo
955 960
      * create wallet using the API
956 961
      *
957 962
      * @param string    $identifier             the wallet identifier to create
958
-     * @param array     $primaryPublicKey       BIP32 extended public key - [key, path]
963
+     * @param string[]     $primaryPublicKey       BIP32 extended public key - [key, path]
959 964
      * @param array     $backupPublicKey        BIP32 extended public key - [backup key, path "M"]
960 965
      * @param string    $primaryMnemonic        mnemonic to store
961 966
      * @param string    $checksum               checksum to store
@@ -983,10 +988,10 @@  discard block
 block discarded – undo
983 988
      *
984 989
      * @param string $identifier       the wallet identifier to create
985 990
      * @param array  $primaryPublicKey BIP32 extended public key - [key, path]
986
-     * @param array  $backupPublicKey  BIP32 extended public key - [backup key, path "M"]
987
-     * @param        $encryptedPrimarySeed
988
-     * @param        $encryptedSecret
989
-     * @param        $recoverySecret
991
+     * @param string[]  $backupPublicKey  BIP32 extended public key - [backup key, path "M"]
992
+     * @param        string|false $encryptedPrimarySeed
993
+     * @param        string|false $encryptedSecret
994
+     * @param        string|false $recoverySecret
990 995
      * @param string $checksum         checksum to store
991 996
      * @param int    $keyIndex         account that we expect to use
992 997
      * @param bool   $segwit           opt in to segwit
@@ -1016,9 +1021,9 @@  discard block
 block discarded – undo
1016 1021
      *
1017 1022
      * @param string $identifier       the wallet identifier to create
1018 1023
      * @param array  $primaryPublicKey BIP32 extended public key - [key, path]
1019
-     * @param array  $backupPublicKey  BIP32 extended public key - [backup key, path "M"]
1020
-     * @param        $encryptedPrimarySeed
1021
-     * @param        $encryptedSecret
1024
+     * @param string[]  $backupPublicKey  BIP32 extended public key - [backup key, path "M"]
1025
+     * @param        string|false $encryptedPrimarySeed
1026
+     * @param        string|false $encryptedSecret
1022 1027
      * @param        $recoverySecret
1023 1028
      * @param string $checksum         checksum to store
1024 1029
      * @param int    $keyIndex         account that we expect to use
@@ -1712,7 +1717,7 @@  discard block
 block discarded – undo
1712 1717
      * convert a Satoshi value to a BTC value
1713 1718
      *
1714 1719
      * @param int       $satoshi
1715
-     * @return float
1720
+     * @return string
1716 1721
      */
1717 1722
     public static function toBTC($satoshi) {
1718 1723
         return bcdiv((int)(string)$satoshi, 100000000, 8);
@@ -1742,7 +1747,7 @@  discard block
 block discarded – undo
1742 1747
      * convert a BTC value to a Satoshi value
1743 1748
      *
1744 1749
      * @param float     $btc
1745
-     * @return string
1750
+     * @return integer
1746 1751
      */
1747 1752
     public static function toSatoshi($btc) {
1748 1753
         return (int)self::toSatoshiString($btc);
@@ -1751,7 +1756,7 @@  discard block
 block discarded – undo
1751 1756
     /**
1752 1757
      * json_decode helper that throws exceptions when it fails to decode
1753 1758
      *
1754
-     * @param      $json
1759
+     * @param      string $json
1755 1760
      * @param bool $assoc
1756 1761
      * @return mixed
1757 1762
      * @throws \Exception
@@ -1803,6 +1808,9 @@  discard block
 block discarded – undo
1803 1808
         }
1804 1809
     }
1805 1810
 
1811
+    /**
1812
+     * @param BIP32Key[] $keys
1813
+     */
1806 1814
     public static function normalizeBIP32KeyArray($keys, NetworkInterface $network) {
1807 1815
         return Util::arrayMapWithIndex(function ($idx, $key) use ($network) {
1808 1816
             return [$idx, self::normalizeBIP32Key($key, $network)];
Please login to merge, or discard this patch.
src/BackupGenerator.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
             define('DOMPDF_ENABLE_AUTOLOAD', false);
62 62
 
63 63
             //try the different possible locations for the config file, depending on if the sdk is included as a dependency or is the main project itself
64
-            (@include_once __DIR__ . '/../../../dompdf/dompdf/dompdf_config.inc.php') || @include_once __DIR__ . '/../vendor/dompdf/dompdf/dompdf_config.inc.php';
64
+            (@include_once __DIR__.'/../../../dompdf/dompdf/dompdf_config.inc.php') || @include_once __DIR__.'/../vendor/dompdf/dompdf/dompdf_config.inc.php';
65 65
         }
66 66
 
67 67
         //set the fonts path
68
-        $this->fontsPath = dirname(__FILE__) . '/../resources/fonts';
68
+        $this->fontsPath = dirname(__FILE__).'/../resources/fonts';
69 69
 
70 70
         $this->network = $network;
71 71
         $this->identifier = $identifier;
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
             $qrCode = new QrCode();
90 90
             $qrCode
91 91
                 ->setText($key->key()->toExtendedKey())
92
-                ->setSize(self::QR_CODE_SIZE-20)
92
+                ->setSize(self::QR_CODE_SIZE - 20)
93 93
                 ->setPadding(10)
94 94
                 ->setErrorCorrection('high')
95 95
                 ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             $passwordEncryptedSecret = $this->backupInfo['encrypted_secret'];
131 131
         }
132 132
 
133
-        $html = self::renderTemplate(__DIR__ . "/../resources/templates/recovery_sheet.html.php", [
133
+        $html = self::renderTemplate(__DIR__."/../resources/templates/recovery_sheet.html.php", [
134 134
             'identifier' => $this->identifier,
135 135
             'totalPubKeys' => $totalPubKeys,
136 136
             'pubKeysHtml' => $pubKeysHtml,
Please login to merge, or discard this patch.