Completed
Pull Request — master (#85)
by thomas
69:21
created
src/SizeEstimation.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
     /**
67 67
      * @param array $vectorSizes
68
-     * @return int|mixed
68
+     * @return integer
69 69
      */
70 70
     public static function getLengthOfVector(array $vectorSizes)
71 71
     {
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
     }
125 125
 
126 126
     /**
127
-     * @param array $stackSizes - array of integer size of a value (for scriptSig or witness)
127
+     * @param integer[] $stackSizes - array of integer size of a value (for scriptSig or witness)
128 128
      * @param bool $isWitness
129 129
      * @param ScriptInterface $redeemScript
130 130
      * @param ScriptInterface $witnessScript
131
-     * @return array
131
+     * @return integer[]
132 132
      */
133 133
     public static function estimateSizeForStack(array $stackSizes, $isWitness, ScriptInterface $redeemScript = null, ScriptInterface $witnessScript = null)
134 134
     {
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      * @param ScriptInterface|null $redeemScript
178 178
      * @param ScriptInterface $witnessScript
179 179
      * @param bool $isWitness
180
-     * @return array
180
+     * @return integer[]
181 181
      */
182 182
     public static function estimateInputFromScripts(ScriptInterface $script, ScriptInterface $redeemScript = null, ScriptInterface $witnessScript = null, $isWitness)
183 183
     {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -184,12 +184,12 @@
 block discarded – undo
184 184
         assert($witnessScript === null || $isWitness);
185 185
         $classifier = new OutputClassifier();
186 186
         if ($classifier->isMultisig($script)) {
187
-            list ($stackSizes, ) = SizeEstimation::estimateMultisigStackSize(new Multisig($script));
187
+            list ($stackSizes,) = SizeEstimation::estimateMultisigStackSize(new Multisig($script));
188 188
         } else if ($classifier->isPayToPublicKey($script)) {
189
-            list ($stackSizes, ) = SizeEstimation::estimateP2PKStackSize(new PayToPubKey($script));
189
+            list ($stackSizes,) = SizeEstimation::estimateP2PKStackSize(new PayToPubKey($script));
190 190
         } else if ($classifier->isPayToPublicKeyHash($script)) {
191 191
             // defaults to compressed, tough luck
192
-            list ($stackSizes, ) = SizeEstimation::estimateP2PKHStackSize();
192
+            list ($stackSizes,) = SizeEstimation::estimateP2PKHStackSize();
193 193
         } else {
194 194
             throw new \InvalidArgumentException("Unsupported script type");
195 195
         }
Please login to merge, or discard this patch.
src/Wallet.php 3 patches
Doc Comments   +16 added lines, -12 removed lines patch added patch discarded remove patch
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     }
309 309
 
310 310
     /**
311
-     * @param string|BIP32Path  $path
311
+     * @param BIP32Path  $path
312 312
      * @return BIP32Key|false
313 313
      * @throws \Exception
314 314
      *
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
     /**
336 336
      * get address for the specified path
337 337
      *
338
-     * @param string|BIP32Path  $path
338
+     * @param string  $path
339 339
      * @return string
340 340
      */
341 341
     public function getAddressByPath($path) {
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     }
433 433
 
434 434
     /**
435
-     * @param string|BIP32Path  $path
435
+     * @param BIP32Path  $path
436 436
      * @return BIP32Key
437 437
      * @throws \Exception
438 438
      */
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
      * 'fund' the txBuilder with UTXOs (modified in place)
582 582
      *
583 583
      * @param TransactionBuilder    $txBuilder
584
-     * @param bool|true             $lockUTXOs
584
+     * @param boolean             $lockUTXOs
585 585
      * @param bool|false            $allowZeroConf
586 586
      * @param null|int              $forceFee
587 587
      * @return TransactionBuilder
@@ -703,6 +703,10 @@  discard block
 block discarded – undo
703 703
         return [$txb->get(), $signInfo];
704 704
     }
705 705
 
706
+    /**
707
+     * @param integer $optimalFeePerKB
708
+     * @param integer $lowPriorityFeePerKB
709
+     */
706 710
     public function determineFeeAndChange(TransactionBuilder $txBuilder, $optimalFeePerKB, $lowPriorityFeePerKB) {
707 711
         $send = $txBuilder->getOutputs();
708 712
         $utxos = $txBuilder->getUtxos();
@@ -816,7 +820,7 @@  discard block
 block discarded – undo
816 820
      * @todo: mark this as deprecated, insist on the utxo's or qualified scripts.
817 821
      * @param int $utxoCnt      number of unspent inputs in transaction
818 822
      * @param int $outputCnt    number of outputs in transaction
819
-     * @return float
823
+     * @return integer
820 824
      * @access public           reminder that people might use this!
821 825
      */
822 826
     public static function estimateFee($utxoCnt, $outputCnt) {
@@ -838,7 +842,7 @@  discard block
 block discarded – undo
838 842
     /**
839 843
      * @param int $txinSize
840 844
      * @param int $txoutSize
841
-     * @return float
845
+     * @return integer
842 846
      */
843 847
     public static function estimateSize($txinSize, $txoutSize) {
844 848
         return 4 + 4 + $txinSize + 4 + $txoutSize + 4; // version + txinVarInt + txin + txoutVarInt + txout + locktime
@@ -848,7 +852,7 @@  discard block
 block discarded – undo
848 852
      * only supports estimating size for P2PKH/P2SH outputs
849 853
      *
850 854
      * @param int $outputCnt    number of outputs in transaction
851
-     * @return float
855
+     * @return integer
852 856
      */
853 857
     public static function estimateSizeOutputs($outputCnt) {
854 858
         return ($outputCnt * 34);
@@ -936,8 +940,8 @@  discard block
 block discarded – undo
936 940
     }
937 941
 
938 942
     /**
939
-     * @param array $utxos
940
-     * @param $outputSize
943
+     * @param UTXO[] $utxos
944
+     * @param integer $outputSize
941 945
      * @return int
942 946
      */
943 947
     public function estimateVsize(array $utxos, $outputSize) {
@@ -950,7 +954,7 @@  discard block
 block discarded – undo
950 954
      *
951 955
      * @param UTXO[]  $utxos
952 956
      * @param array[] $outputs
953
-     * @param         $feeStrategy
957
+     * @param         string $feeStrategy
954 958
      * @param         $optimalFeePerKB
955 959
      * @param         $lowPriorityFeePerKB
956 960
      * @return int
@@ -1061,8 +1065,8 @@  discard block
 block discarded – undo
1061 1065
      * @param \array[] $outputs
1062 1066
      * @param bool $lockUTXO
1063 1067
      * @param bool $allowZeroConf
1064
-     * @param int|null|string $feeStrategy
1065
-     * @param null $forceFee
1068
+     * @param string $feeStrategy
1069
+     * @param null|integer $forceFee
1066 1070
      * @return array
1067 1071
      */
1068 1072
     public function coinSelection($outputs, $lockUTXO = true, $allowZeroConf = false, $feeStrategy = self::FEE_STRATEGY_OPTIMAL, $forceFee = null) {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
7 7
 use BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeyFactory;
8 8
 use BitWasp\Bitcoin\MessageSigner\MessageSigner;
9 9
 use BitWasp\Bitcoin\Script\P2shScript;
10
-use BitWasp\Bitcoin\Script\Classifier\OutputClassifier;
11 10
 use BitWasp\Bitcoin\Script\ScriptFactory;
12 11
 use BitWasp\Bitcoin\Script\ScriptInterface;
13 12
 use BitWasp\Bitcoin\Script\WitnessScript;
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 
156 156
         $this->identifier = $identifier;
157 157
         $this->backupPublicKey = BlocktrailSDK::normalizeBIP32Key($backupPublicKey);
158
-        $this->primaryPublicKeys = BlocktrailSDK::normalizeBIP32KeyArray($primaryPublicKeys);;
158
+        $this->primaryPublicKeys = BlocktrailSDK::normalizeBIP32KeyArray($primaryPublicKeys); ;
159 159
         $this->blocktrailPublicKeys = BlocktrailSDK::normalizeBIP32KeyArray($blocktrailPublicKeys);
160 160
 
161 161
         $this->network = $network;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      * @return array[]      [ [xpub, path] ]
219 219
      */
220 220
     public function getBlocktrailPublicKeys() {
221
-        return array_map(function (BIP32Key $key) {
221
+        return array_map(function(BIP32Key $key) {
222 222
             return $key->tuple();
223 223
         }, $this->blocktrailPublicKeys);
224 224
     }
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
     public function getAddressByPath($path) {
342 342
         $path = (string)BIP32Path::path($path)->privatePath();
343 343
         if (!isset($this->derivations[$path])) {
344
-            list($address, ) = $this->getRedeemScriptByPath($path);
344
+            list($address,) = $this->getRedeemScriptByPath($path);
345 345
 
346 346
             $this->derivations[$path] = $address;
347 347
             $this->derivationsByAddress[$address] = $path;
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
             $signInfo[] = new SignInfo($utxo->path, $utxo->redeemScript, $utxo->witnessScript, new TransactionOutput($utxo->value, $utxo->scriptPubKey));
658 658
         }
659 659
 
660
-        $utxoSum = array_sum(array_map(function (UTXO $utxo) {
660
+        $utxoSum = array_sum(array_map(function(UTXO $utxo) {
661 661
             return $utxo->value;
662 662
         }, $utxos));
663 663
         if ($utxoSum < array_sum(array_column($send, 'value'))) {
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
             throw new \Exception("Wallet needs to be unlocked to pay");
791 791
         }
792 792
 
793
-        assert(Util::all(function ($signInfo) {
793
+        assert(Util::all(function($signInfo) {
794 794
             return $signInfo instanceof SignInfo;
795 795
         }, $signInfo), '$signInfo should be SignInfo[]');
796 796
 
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         ];
804 804
 
805 805
         // send the transaction
806
-        $finished = $this->sendTransaction($txs, array_map(function (SignInfo $r) {
806
+        $finished = $this->sendTransaction($txs, array_map(function(SignInfo $r) {
807 807
             return (string)$r->path;
808 808
         }, $signInfo), $apiCheckFee);
809 809
 
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
     public static function estimateSizeUTXOs($utxoCnt) {
864 864
         $txinSize = 0;
865 865
 
866
-        for ($i=0; $i<$utxoCnt; $i++) {
866
+        for ($i = 0; $i < $utxoCnt; $i++) {
867 867
             // @TODO: proper size calculation, we only do multisig right now so it's hardcoded and then we guess the size ...
868 868
             $multisig = "2of3";
869 869
 
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
      * @return int
942 942
      */
943 943
     public function estimateVsize(array $utxos, $outputSize) {
944
-        return (int) ceil(self::estimateWeight($utxos, $outputSize) / 4);
944
+        return (int)ceil(self::estimateWeight($utxos, $outputSize) / 4);
945 945
     }
946 946
 
947 947
     /**
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
      * @return int
997 997
      */
998 998
     protected function determineChange($utxos, $outputs, $fee) {
999
-        $inputsTotal = array_sum(array_map(function (UTXO $utxo) {
999
+        $inputsTotal = array_sum(array_map(function(UTXO $utxo) {
1000 1000
             return $utxo->value;
1001 1001
         }, $utxos));
1002 1002
         $outputsTotal = array_sum(array_column($outputs, 'value'));
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
     protected function signTransaction(Transaction $tx, array $signInfo) {
1016 1016
         $signer = new Signer($tx, Bitcoin::getEcAdapter());
1017 1017
 
1018
-        assert(Util::all(function ($signInfo) {
1018
+        assert(Util::all(function($signInfo) {
1019 1019
             return $signInfo instanceof SignInfo;
1020 1020
         }, $signInfo), '$signInfo should be SignInfo[]');
1021 1021
 
Please login to merge, or discard this patch.
src/Connection/RestClient.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
             'handler' => $handler,
102 102
             'base_uri' => $this->apiEndpoint,
103 103
             'headers' => array(
104
-                'User-Agent' => Blocktrail::SDK_USER_AGENT . '/' . Blocktrail::SDK_VERSION,
104
+                'User-Agent' => Blocktrail::SDK_USER_AGENT.'/'.Blocktrail::SDK_VERSION,
105 105
             ),
106 106
             'http_errors' => false,
107 107
             'connect_timeout' => 3,
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
             $contentMD5Mode = !is_null($body) ? 'body' : 'url';
247 247
         }
248 248
 
249
-        $request = new Request($method, $this->apiEndpoint . $endpointUrl);
249
+        $request = new Request($method, $this->apiEndpoint.$endpointUrl);
250 250
         $uri = $request->getUri();
251 251
 
252 252
         if ($queryString) {
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
                 throw new ObjectNotFound($this->verboseErrors ? $body : Blocktrail::EXCEPTION_OBJECT_NOT_FOUND, $httpResponseCode);
342 342
             }
343 343
         } elseif ($httpResponseCode == 500) {
344
-            throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR . "\nServer Response: " . $body, $httpResponseCode);
344
+            throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR."\nServer Response: ".$body, $httpResponseCode);
345 345
         } else {
346
-            throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR . "\nServer Response: " . $body, $httpResponseCode);
346
+            throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR."\nServer Response: ".$body, $httpResponseCode);
347 347
         }
348 348
     }
349 349
 
Please login to merge, or discard this patch.
src/WalletScript.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
      * @param bool $setting
54 54
      */
55 55
     public static function enforceScriptChecks($setting) {
56
-        static::$checkScripts = (bool) $setting;
56
+        static::$checkScripts = (bool)$setting;
57 57
     }
58 58
 
59 59
     /**
Please login to merge, or discard this patch.
src/TransactionBuilder.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         }
108 108
 
109 109
         if ($value <= Blocktrail::DUST) {
110
-            throw new \Exception("Values should be more than dust (" . Blocktrail::DUST . ")");
110
+            throw new \Exception("Values should be more than dust (".Blocktrail::DUST.")");
111 111
         }
112 112
 
113 113
         if ($object instanceof SegwitAddress) {
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         }
163 163
 
164 164
         if ($value <= Blocktrail::DUST) {
165
-            throw new \Exception("Values should be more than dust (" . Blocktrail::DUST . ")");
165
+            throw new \Exception("Values should be more than dust (".Blocktrail::DUST.")");
166 166
         }
167 167
 
168 168
         if (!isset($this->outputs[$idx])) {
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      * @return array
209 209
      */
210 210
     public function getOutputs($json = false) {
211
-        return array_map(function ($output) use ($json) {
211
+        return array_map(function($output) use ($json) {
212 212
             $result = $output;
213 213
 
214 214
             if ($json) {
Please login to merge, or discard this patch.
src/WalletSweeper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             $this->getBlocktrailPublicKey($path)->buildKey($path)->publicKey()
164 164
         ]), false);
165 165
 
166
-        if ($this->network !== "bitcoincash" && (int) $path[2] === 2) {
166
+        if ($this->network !== "bitcoincash" && (int)$path[2] === 2) {
167 167
             $witnessScript = new WitnessScript($multisig);
168 168
             $redeemScript = new P2shScript($witnessScript);
169 169
             $address = $redeemScript->getAddress()->getAddress();
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
         for ($i = 0; $i < $count; $i++) {
191 191
             //create a path subsequent address
192
-            $path = (string)WalletPath::create($keyIndex, $_chain = 0, $start+$i)->path()->publicPath();
192
+            $path = (string)WalletPath::create($keyIndex, $_chain = 0, $start + $i)->path()->publicPath();
193 193
             list($address, $redeem, $witness) = $this->createAddress($path);
194 194
             $addresses[$address] = array(
195 195
                 //'address' => $address,
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         $totalUTXOs = 0;
239 239
         $totalAddressesGenerated = 0;
240 240
 
241
-        $addressUTXOs = array();    //addresses and their utxos, paths and redeem scripts
241
+        $addressUTXOs = array(); //addresses and their utxos, paths and redeem scripts
242 242
 
243 243
         //for each blocktrail pub key, do fund discovery on batches of addresses
244 244
         foreach ($this->blocktrailPublicKeys as $keyIndex => $blocktrailPubKey) {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                     }
275 275
 
276 276
                     $addressUTXOs[$address]['utxos'][] = $utxo;
277
-                    $totalUTXOs ++;
277
+                    $totalUTXOs++;
278 278
 
279 279
                     //add up the total utxo value for all addresses
280 280
                     $totalBalance += $utxo['value'];
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
             $signer->redeemBitcoinCash(true);
390 390
         }
391 391
 
392
-        assert(Util::all(function ($signInfo) {
392
+        assert(Util::all(function($signInfo) {
393 393
             return $signInfo instanceof SignInfo;
394 394
         }, $signInfo), '$signInfo should be SignInfo[]');
395 395
 
Please login to merge, or discard this patch.