Completed
Branch master (95c3c5)
by
unknown
05:09
created
src/BlocktrailSDK.php 2 patches
Doc Comments   +18 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * normalize network string
77 77
      *
78 78
      * @param $network
79
-     * @param $testnet
79
+     * @param boolean $testnet
80 80
      * @return array
81 81
      * @throws \Exception
82 82
      */
@@ -671,6 +671,11 @@  discard block
 block discarded – undo
671 671
         ];
672 672
     }
673 673
 
674
+    /**
675
+     * @param integer $bits
676
+     *
677
+     * @return string
678
+     */
674 679
     public static function randomBits($bits) {
675 680
         return self::randomBytes($bits / 8);
676 681
     }
@@ -941,7 +946,7 @@  discard block
 block discarded – undo
941 946
      * create wallet using the API
942 947
      *
943 948
      * @param string    $identifier             the wallet identifier to create
944
-     * @param array     $primaryPublicKey       BIP32 extended public key - [key, path]
949
+     * @param string[]     $primaryPublicKey       BIP32 extended public key - [key, path]
945 950
      * @param string    $backupPublicKey        plain public key
946 951
      * @param string    $primaryMnemonic        mnemonic to store
947 952
      * @param string    $checksum               checksum to store
@@ -968,9 +973,9 @@  discard block
 block discarded – undo
968 973
      * @param string $identifier       the wallet identifier to create
969 974
      * @param array  $primaryPublicKey BIP32 extended public key - [key, path]
970 975
      * @param string $backupPublicKey  plain public key
971
-     * @param        $encryptedPrimarySeed
972
-     * @param        $encryptedSecret
973
-     * @param        $recoverySecret
976
+     * @param        string|false $encryptedPrimarySeed
977
+     * @param        string|false $encryptedSecret
978
+     * @param        string|false $recoverySecret
974 979
      * @param string $checksum         checksum to store
975 980
      * @param int    $keyIndex         account that we expect to use
976 981
      * @return mixed
@@ -999,8 +1004,8 @@  discard block
 block discarded – undo
999 1004
      * @param string $identifier       the wallet identifier to create
1000 1005
      * @param array  $primaryPublicKey BIP32 extended public key - [key, path]
1001 1006
      * @param string $backupPublicKey  plain public key
1002
-     * @param        $encryptedPrimarySeed
1003
-     * @param        $encryptedSecret
1007
+     * @param        string|false $encryptedPrimarySeed
1008
+     * @param        string|false $encryptedSecret
1004 1009
      * @param        $recoverySecret
1005 1010
      * @param string $checksum         checksum to store
1006 1011
      * @param int    $keyIndex         account that we expect to use
@@ -1648,7 +1653,7 @@  discard block
 block discarded – undo
1648 1653
      * convert a Satoshi value to a BTC value
1649 1654
      *
1650 1655
      * @param int       $satoshi
1651
-     * @return float
1656
+     * @return string
1652 1657
      */
1653 1658
     public static function toBTC($satoshi) {
1654 1659
         return bcdiv((int)(string)$satoshi, 100000000, 8);
@@ -1678,7 +1683,7 @@  discard block
 block discarded – undo
1678 1683
      * convert a BTC value to a Satoshi value
1679 1684
      *
1680 1685
      * @param float     $btc
1681
-     * @return string
1686
+     * @return integer
1682 1687
      */
1683 1688
     public static function toSatoshi($btc) {
1684 1689
         return (int)self::toSatoshiString($btc);
@@ -1687,7 +1692,7 @@  discard block
 block discarded – undo
1687 1692
     /**
1688 1693
      * json_decode helper that throws exceptions when it fails to decode
1689 1694
      *
1690
-     * @param      $json
1695
+     * @param      string $json
1691 1696
      * @param bool $assoc
1692 1697
      * @return mixed
1693 1698
      * @throws \Exception
@@ -1739,6 +1744,9 @@  discard block
 block discarded – undo
1739 1744
         }
1740 1745
     }
1741 1746
 
1747
+    /**
1748
+     * @param BIP32Key[] $keys
1749
+     */
1742 1750
     public static function normalizeBIP32KeyArray($keys) {
1743 1751
         return Util::arrayMapWithIndex(function ($idx, $key) {
1744 1752
             return [$idx, self::normalizeBIP32Key($key)];
Please login to merge, or discard this patch.
Spacing   +10 added lines, -13 removed lines patch added patch discarded remove patch
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
             } else {
579 579
                 // create new primary seed
580 580
                 /** @var HierarchicalKey $primaryPrivateKey */
581
-                list($primaryMnemonic, , $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']);
581
+                list($primaryMnemonic,, $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']);
582 582
                 if ($storePrimaryMnemonic !== false) {
583 583
                     $storePrimaryMnemonic = true;
584 584
                 }
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
         $backupPublicKey = null;
618 618
         if (!isset($options['backup_mnemonic']) && !isset($options['backup_public_key'])) {
619 619
             /** @var HierarchicalKey $backupPrivateKey */
620
-            list($backupMnemonic, , ) = $this->newBackupSeed();
620
+            list($backupMnemonic,,) = $this->newBackupSeed();
621 621
         } else if (isset($options['backup_mnemonic'])) {
622 622
             $backupMnemonic = $options['backup_mnemonic'];
623 623
         } elseif (isset($options['backup_public_key'])) {
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
         $data = $this->storeNewWalletV1($options['identifier'], $primaryPublicKey->tuple(), $backupPublicKey->tuple(), $primaryMnemonic, $checksum, $options['key_index']);
642 642
 
643 643
         // received the blocktrail public keys
644
-        $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) {
644
+        $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) {
645 645
             return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])];
646 646
         }, $data['blocktrail_public_keys']);
647 647
 
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
         );
760 760
 
761 761
         // received the blocktrail public keys
762
-        $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) {
762
+        $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) {
763 763
             return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])];
764 764
         }, $data['blocktrail_public_keys']);
765 765
 
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
                 'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer($backupSeed)) : null,
793 793
                 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($recoveryEncryptedSecret))) : null,
794 794
                 'encrypted_secret' => $encryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($encryptedSecret))) : null,
795
-                'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) {
795
+                'blocktrail_public_keys' => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) {
796 796
                     return [$keyIndex, $pubKey->tuple()];
797 797
                 }, $blocktrailPublicKeys),
798 798
             ],
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
         );
898 898
 
899 899
         // received the blocktrail public keys
900
-        $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) {
900
+        $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) {
901 901
             return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])];
902 902
         }, $data['blocktrail_public_keys']);
903 903
 
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
                 'backup_seed'               => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic($backupSeed) : null,
931 931
                 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? Mnemonic::encode($recoveryEncryptedSecret) : null,
932 932
                 'encrypted_secret'          => $encryptedSecret ? Mnemonic::encode($encryptedSecret) : null,
933
-                'blocktrail_public_keys'    => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) {
933
+                'blocktrail_public_keys'    => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) {
934 934
                     return [$keyIndex, $pubKey->tuple()];
935 935
                 }, $blocktrailPublicKeys),
936 936
             ]
@@ -1066,10 +1066,7 @@  discard block
 block discarded – undo
1066 1066
         }
1067 1067
 
1068 1068
         $identifier = $options['identifier'];
1069
-        $readonly = isset($options['readonly']) ? $options['readonly'] :
1070
-                    (isset($options['readOnly']) ? $options['readOnly'] :
1071
-                        (isset($options['read-only']) ? $options['read-only'] :
1072
-                            false));
1069
+        $readonly = isset($options['readonly']) ? $options['readonly'] : (isset($options['readOnly']) ? $options['readOnly'] : (isset($options['read-only']) ? $options['read-only'] : false));
1073 1070
 
1074 1071
         // get the wallet data from the server
1075 1072
         $data = $this->getWallet($identifier);
@@ -1714,7 +1711,7 @@  discard block
 block discarded – undo
1714 1711
      */
1715 1712
     public static function sortMultisigKeys(array $pubKeys) {
1716 1713
         $result = array_values($pubKeys);
1717
-        usort($result, function (PublicKeyInterface $a, PublicKeyInterface $b) {
1714
+        usort($result, function(PublicKeyInterface $a, PublicKeyInterface $b) {
1718 1715
             $av = $a->getHex();
1719 1716
             $bv = $b->getHex();
1720 1717
             return $av == $bv ? 0 : $av > $bv ? 1 : -1;
@@ -1740,7 +1737,7 @@  discard block
 block discarded – undo
1740 1737
     }
1741 1738
 
1742 1739
     public static function normalizeBIP32KeyArray($keys) {
1743
-        return Util::arrayMapWithIndex(function ($idx, $key) {
1740
+        return Util::arrayMapWithIndex(function($idx, $key) {
1744 1741
             return [$idx, self::normalizeBIP32Key($key)];
1745 1742
         }, $keys);
1746 1743
     }
Please login to merge, or discard this patch.
src/Wallet.php 2 patches
Doc Comments   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     }
260 260
 
261 261
     /**
262
-     * @param string|BIP32Path  $path
262
+     * @param BIP32Path  $path
263 263
      * @return BIP32Key|false
264 264
      * @throws \Exception
265 265
      *
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
     /**
287 287
      * get address for the specified path
288 288
      *
289
-     * @param string|BIP32Path  $path
289
+     * @param string  $path
290 290
      * @return string
291 291
      */
292 292
     public function getAddressByPath($path) {
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
     }
361 361
 
362 362
     /**
363
-     * @param string|BIP32Path  $path
363
+     * @param BIP32Path  $path
364 364
      * @return BIP32Key
365 365
      * @throws \Exception
366 366
      */
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
      * 'fund' the txBuilder with UTXOs (modified in place)
509 509
      *
510 510
      * @param TransactionBuilder    $txBuilder
511
-     * @param bool|true             $lockUTXOs
511
+     * @param boolean             $lockUTXOs
512 512
      * @param bool|false            $allowZeroConf
513 513
      * @param null|int              $forceFee
514 514
      * @return TransactionBuilder
@@ -629,6 +629,10 @@  discard block
 block discarded – undo
629 629
         return [$txb->get(), $signInfo];
630 630
     }
631 631
 
632
+    /**
633
+     * @param integer $optimalFeePerKB
634
+     * @param integer $lowPriorityFeePerKB
635
+     */
632 636
     public function determineFeeAndChange(TransactionBuilder $txBuilder, $optimalFeePerKB, $lowPriorityFeePerKB) {
633 637
         $send = $txBuilder->getOutputs();
634 638
         $utxos = $txBuilder->getUtxos();
@@ -736,7 +740,7 @@  discard block
 block discarded – undo
736 740
      *
737 741
      * @param int $utxoCnt      number of unspent inputs in transaction
738 742
      * @param int $outputCnt    number of outputs in transaction
739
-     * @return float
743
+     * @return integer
740 744
      * @access public           reminder that people might use this!
741 745
      */
742 746
     public static function estimateFee($utxoCnt, $outputCnt) {
@@ -758,7 +762,7 @@  discard block
 block discarded – undo
758 762
     /**
759 763
      * @param int $txinSize
760 764
      * @param int $txoutSize
761
-     * @return float
765
+     * @return integer
762 766
      */
763 767
     public static function estimateSize($txinSize, $txoutSize) {
764 768
         return 4 + 4 + $txinSize + 4 + $txoutSize + 4; // version + txinVarInt + txin + txoutVarInt + txout + locktime
@@ -768,7 +772,7 @@  discard block
 block discarded – undo
768 772
      * only supports estimating size for P2PKH/P2SH outputs
769 773
      *
770 774
      * @param int $outputCnt    number of outputs in transaction
771
-     * @return float
775
+     * @return integer
772 776
      */
773 777
     public static function estimateSizeOutputs($outputCnt) {
774 778
         return ($outputCnt * 34);
@@ -822,7 +826,7 @@  discard block
 block discarded – undo
822 826
      *
823 827
      * @param UTXO[]  $utxos
824 828
      * @param array[] $outputs
825
-     * @param         $feeStrategy
829
+     * @param         string $feeStrategy
826 830
      * @param         $optimalFeePerKB
827 831
      * @param         $lowPriorityFeePerKB
828 832
      * @return int
@@ -921,8 +925,8 @@  discard block
 block discarded – undo
921 925
      * @param \array[] $outputs
922 926
      * @param bool $lockUTXO
923 927
      * @param bool $allowZeroConf
924
-     * @param int|null|string $feeStrategy
925
-     * @param null $forceFee
928
+     * @param string $feeStrategy
929
+     * @param null|integer $forceFee
926 930
      * @return array
927 931
      */
928 932
     public function coinSelection($outputs, $lockUTXO = true, $allowZeroConf = false, $feeStrategy = self::FEE_STRATEGY_OPTIMAL, $forceFee = null) {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      * @return array[]      [ [xpub, path] ]
174 174
      */
175 175
     public function getBlocktrailPublicKeys() {
176
-        return array_map(function (BIP32Key $key) {
176
+        return array_map(function(BIP32Key $key) {
177 177
             return $key->tuple();
178 178
         }, $this->blocktrailPublicKeys);
179 179
     }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     public function getAddressByPath($path) {
293 293
         $path = (string)BIP32Path::path($path)->privatePath();
294 294
         if (!isset($this->derivations[$path])) {
295
-            list($address, ) = $this->getRedeemScriptByPath($path);
295
+            list($address,) = $this->getRedeemScriptByPath($path);
296 296
 
297 297
             $this->derivations[$path] = $address;
298 298
             $this->derivationsByAddress[$address] = $path;
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
         }
585 585
 
586 586
         if (array_sum(array_map(
587
-            function (UTXO $utxo) { return $utxo->value; },
587
+            function(UTXO $utxo) { return $utxo->value; },
588 588
             $utxos
589 589
         )) < array_sum(array_column($send, 'value'))) {
590 590
             throw new \Exception("Atempting to spend more than sum of UTXOs");
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
             throw new \Exception("Wallet needs to be unlocked to pay");
717 717
         }
718 718
 
719
-        assert(Util::all(function ($signInfo) {
719
+        assert(Util::all(function($signInfo) {
720 720
             return $signInfo instanceof SignInfo;
721 721
         }, $signInfo), '$signInfo should be SignInfo[]');
722 722
 
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         $signed = $this->signTransaction($tx, $signInfo);
725 725
 
726 726
         // send the transaction
727
-        $finished = $this->sendTransaction($signed->getHex(), array_map(function (SignInfo $r) {
727
+        $finished = $this->sendTransaction($signed->getHex(), array_map(function(SignInfo $r) {
728 728
             return $r->path;
729 729
         }, $signInfo), $apiCheckFee);
730 730
 
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
     public static function estimateSizeUTXOs($utxoCnt) {
784 784
         $txinSize = 0;
785 785
 
786
-        for ($i=0; $i<$utxoCnt; $i++) {
786
+        for ($i = 0; $i < $utxoCnt; $i++) {
787 787
             // @TODO: proper size calculation, we only do multisig right now so it's hardcoded and then we guess the size ...
788 788
             $multisig = "2of3";
789 789
 
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
      * @return int
869 869
      */
870 870
     protected function determineChange($utxos, $outputs, $fee) {
871
-        $inputsTotal = array_sum(array_map(function (UTXO $utxo) {
871
+        $inputsTotal = array_sum(array_map(function(UTXO $utxo) {
872 872
             return $utxo->value;
873 873
         }, $utxos));
874 874
         $outputsTotal = array_sum(array_column($outputs, 'value'));
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
     protected function signTransaction(Transaction $tx, array $signInfo) {
888 888
         $signer = new Signer($tx, Bitcoin::getEcAdapter());
889 889
 
890
-        assert(Util::all(function ($signInfo) {
890
+        assert(Util::all(function($signInfo) {
891 891
             return $signInfo instanceof SignInfo;
892 892
         }, $signInfo), '$signInfo should be SignInfo[]');
893 893
 
Please login to merge, or discard this patch.
src/V3Crypt/Encryption.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         $sLB = $parser->readBytes(1);
37 37
         $salt = $parser->readBytes($sLB->getInt());
38 38
         $itB = $parser->readBytes(4);
39
-        $header = new Buffer($sLB->getBinary() . $salt->getBinary() . $itB->getBinary());
39
+        $header = new Buffer($sLB->getBinary().$salt->getBinary().$itB->getBinary());
40 40
 
41 41
         $iv = $parser->readBytes(16);
42 42
         $act = $parser->readBytes($ct->getSize() - $parser->getPosition());
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             throw new \RuntimeException('IV must be exactly 16 bytes');
68 68
         }
69 69
 
70
-        $header = new Buffer(pack('c', $salt->getSize()) . $salt->getBinary() . pack('V', $iterations));
70
+        $header = new Buffer(pack('c', $salt->getSize()).$salt->getBinary().pack('V', $iterations));
71 71
 
72 72
         list ($ct, $tag) = AESGCM::encrypt(
73 73
             KeyDerivation::compute($pw, $salt, $iterations)->getBinary(),
@@ -76,6 +76,6 @@  discard block
 block discarded – undo
76 76
             $header->getBinary()
77 77
         );
78 78
 
79
-        return Buffertools::concat($header, new Buffer($iv->getBinary() . $ct . $tag));
79
+        return Buffertools::concat($header, new Buffer($iv->getBinary().$ct.$tag));
80 80
     }
81 81
 }
Please login to merge, or discard this patch.
src/V3Crypt/Mnemonic.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
      */
31 31
     public static function encode(BufferInterface $data) {
32 32
         $bip39 = MnemonicFactory::bip39();
33
-        $mnemonic = $bip39->entropyToMnemonic(new Buffer(self::derivePadding($data->getBinary()) . $data->getBinary()));
33
+        $mnemonic = $bip39->entropyToMnemonic(new Buffer(self::derivePadding($data->getBinary()).$data->getBinary()));
34 34
 
35 35
         try {
36 36
             $bip39->mnemonicToEntropy($mnemonic);
Please login to merge, or discard this patch.