@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $contentMD5Mode = !is_null($body) ? 'body' : 'url'; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $request = new Request($method, $this->apiEndpoint . $endpointUrl); |
|
| 168 | + $request = new Request($method, $this->apiEndpoint.$endpointUrl); |
|
| 169 | 169 | $uri = $request->getUri(); |
| 170 | 170 | |
| 171 | 171 | if ($queryString) { |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | throw new ObjectNotFound($this->verboseErrors ? $body : Blocktrail::EXCEPTION_OBJECT_NOT_FOUND, $httpResponseCode); |
| 254 | 254 | } |
| 255 | 255 | } elseif ($httpResponseCode == 500) { |
| 256 | - throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR . "\nServer Response: " . $body, $httpResponseCode); |
|
| 256 | + throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR."\nServer Response: ".$body, $httpResponseCode); |
|
| 257 | 257 | } else { |
| 258 | - throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR . "\nServer Response: " . $body, $httpResponseCode); |
|
| 258 | + throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR."\nServer Response: ".$body, $httpResponseCode); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | 'handler' => $handler, |
| 62 | 62 | 'base_uri' => $this->apiEndpoint, |
| 63 | 63 | 'headers' => array( |
| 64 | - 'User-Agent' => Blocktrail::SDK_USER_AGENT . '/' . Blocktrail::SDK_VERSION, |
|
| 64 | + 'User-Agent' => Blocktrail::SDK_USER_AGENT.'/'.Blocktrail::SDK_VERSION, |
|
| 65 | 65 | ), |
| 66 | 66 | 'http_errors' => false, |
| 67 | 67 | 'connect_timeout' => 3, |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | /** |
| 76 | 76 | * normalize network string |
| 77 | 77 | * |
| 78 | - * @param $network |
|
| 78 | + * @param string $network |
|
| 79 | 79 | * @param $testnet |
| 80 | 80 | * @return array |
| 81 | 81 | * @throws \Exception |
@@ -679,6 +679,11 @@ discard block |
||
| 679 | 679 | ]; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | + /** |
|
| 683 | + * @param integer $bits |
|
| 684 | + * |
|
| 685 | + * @return string |
|
| 686 | + */ |
|
| 682 | 687 | public static function randomBits($bits) { |
| 683 | 688 | return self::randomBytes($bits / 8); |
| 684 | 689 | } |
@@ -977,7 +982,7 @@ discard block |
||
| 977 | 982 | * create wallet using the API |
| 978 | 983 | * |
| 979 | 984 | * @param string $identifier the wallet identifier to create |
| 980 | - * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
|
| 985 | + * @param string[] $primaryPublicKey BIP32 extended public key - [key, path] |
|
| 981 | 986 | * @param array $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
| 982 | 987 | * @param string $primaryMnemonic mnemonic to store |
| 983 | 988 | * @param string $checksum checksum to store |
@@ -1005,10 +1010,10 @@ discard block |
||
| 1005 | 1010 | * |
| 1006 | 1011 | * @param string $identifier the wallet identifier to create |
| 1007 | 1012 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
| 1008 | - * @param array $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1009 | - * @param $encryptedPrimarySeed |
|
| 1010 | - * @param $encryptedSecret |
|
| 1011 | - * @param $recoverySecret |
|
| 1013 | + * @param string[] $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1014 | + * @param string|false $encryptedPrimarySeed |
|
| 1015 | + * @param string|false $encryptedSecret |
|
| 1016 | + * @param string|false $recoverySecret |
|
| 1012 | 1017 | * @param string $checksum checksum to store |
| 1013 | 1018 | * @param int $keyIndex account that we expect to use |
| 1014 | 1019 | * @param bool $segwit opt in to segwit |
@@ -1038,9 +1043,9 @@ discard block |
||
| 1038 | 1043 | * |
| 1039 | 1044 | * @param string $identifier the wallet identifier to create |
| 1040 | 1045 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
| 1041 | - * @param array $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1042 | - * @param $encryptedPrimarySeed |
|
| 1043 | - * @param $encryptedSecret |
|
| 1046 | + * @param string[] $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1047 | + * @param string|false $encryptedPrimarySeed |
|
| 1048 | + * @param string|false $encryptedSecret |
|
| 1044 | 1049 | * @param $recoverySecret |
| 1045 | 1050 | * @param string $checksum checksum to store |
| 1046 | 1051 | * @param int $keyIndex account that we expect to use |
@@ -1740,7 +1745,7 @@ discard block |
||
| 1740 | 1745 | * convert a Satoshi value to a BTC value |
| 1741 | 1746 | * |
| 1742 | 1747 | * @param int $satoshi |
| 1743 | - * @return float |
|
| 1748 | + * @return string |
|
| 1744 | 1749 | */ |
| 1745 | 1750 | public static function toBTC($satoshi) { |
| 1746 | 1751 | return bcdiv((int)(string)$satoshi, 100000000, 8); |
@@ -1770,7 +1775,7 @@ discard block |
||
| 1770 | 1775 | * convert a BTC value to a Satoshi value |
| 1771 | 1776 | * |
| 1772 | 1777 | * @param float $btc |
| 1773 | - * @return string |
|
| 1778 | + * @return integer |
|
| 1774 | 1779 | */ |
| 1775 | 1780 | public static function toSatoshi($btc) { |
| 1776 | 1781 | return (int)self::toSatoshiString($btc); |
@@ -1779,7 +1784,7 @@ discard block |
||
| 1779 | 1784 | /** |
| 1780 | 1785 | * json_decode helper that throws exceptions when it fails to decode |
| 1781 | 1786 | * |
| 1782 | - * @param $json |
|
| 1787 | + * @param string $json |
|
| 1783 | 1788 | * @param bool $assoc |
| 1784 | 1789 | * @return mixed |
| 1785 | 1790 | * @throws \Exception |
@@ -1831,6 +1836,9 @@ discard block |
||
| 1831 | 1836 | } |
| 1832 | 1837 | } |
| 1833 | 1838 | |
| 1839 | + /** |
|
| 1840 | + * @param BIP32Key[] $keys |
|
| 1841 | + */ |
|
| 1834 | 1842 | public static function normalizeBIP32KeyArray($keys) { |
| 1835 | 1843 | return Util::arrayMapWithIndex(function ($idx, $key) { |
| 1836 | 1844 | return [$idx, self::normalizeBIP32Key($key)]; |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array[] array containing the response |
| 311 | 311 | */ |
| 312 | 312 | public function transactions($txhashes) { |
| 313 | - $response = $this->client->get("transactions/" . implode(",", $txhashes)); |
|
| 313 | + $response = $this->client->get("transactions/".implode(",", $txhashes)); |
|
| 314 | 314 | return self::jsonDecode($response->body(), true); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | } else { |
| 578 | 578 | // create new primary seed |
| 579 | 579 | /** @var HierarchicalKey $primaryPrivateKey */ |
| 580 | - list($primaryMnemonic, , $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']); |
|
| 580 | + list($primaryMnemonic,, $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']); |
|
| 581 | 581 | if ($storePrimaryMnemonic !== false) { |
| 582 | 582 | $storePrimaryMnemonic = true; |
| 583 | 583 | } |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | $backupPublicKey = null; |
| 617 | 617 | if (!isset($options['backup_mnemonic']) && !isset($options['backup_public_key'])) { |
| 618 | 618 | /** @var HierarchicalKey $backupPrivateKey */ |
| 619 | - list($backupMnemonic, , ) = $this->newBackupSeed(); |
|
| 619 | + list($backupMnemonic,,) = $this->newBackupSeed(); |
|
| 620 | 620 | } else if (isset($options['backup_mnemonic'])) { |
| 621 | 621 | $backupMnemonic = $options['backup_mnemonic']; |
| 622 | 622 | } elseif (isset($options['backup_public_key'])) { |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | ); |
| 649 | 649 | |
| 650 | 650 | // received the blocktrail public keys |
| 651 | - $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) { |
|
| 651 | + $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) { |
|
| 652 | 652 | return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])]; |
| 653 | 653 | }, $data['blocktrail_public_keys']); |
| 654 | 654 | |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | ); |
| 769 | 769 | |
| 770 | 770 | // received the blocktrail public keys |
| 771 | - $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) { |
|
| 771 | + $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) { |
|
| 772 | 772 | return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])]; |
| 773 | 773 | }, $data['blocktrail_public_keys']); |
| 774 | 774 | |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | 'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer($backupSeed)) : null, |
| 803 | 803 | 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($recoveryEncryptedSecret))) : null, |
| 804 | 804 | 'encrypted_secret' => $encryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($encryptedSecret))) : null, |
| 805 | - 'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) { |
|
| 805 | + 'blocktrail_public_keys' => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) { |
|
| 806 | 806 | return [$keyIndex, $pubKey->tuple()]; |
| 807 | 807 | }, $blocktrailPublicKeys), |
| 808 | 808 | ], |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | ); |
| 909 | 909 | |
| 910 | 910 | // received the blocktrail public keys |
| 911 | - $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) { |
|
| 911 | + $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) { |
|
| 912 | 912 | return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])]; |
| 913 | 913 | }, $data['blocktrail_public_keys']); |
| 914 | 914 | |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | 'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic($backupSeed) : null, |
| 943 | 943 | 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? EncryptionMnemonic::encode($recoveryEncryptedSecret) : null, |
| 944 | 944 | 'encrypted_secret' => $encryptedSecret ? EncryptionMnemonic::encode($encryptedSecret) : null, |
| 945 | - 'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) { |
|
| 945 | + 'blocktrail_public_keys' => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) { |
|
| 946 | 946 | return [$keyIndex, $pubKey->tuple()]; |
| 947 | 947 | }, $blocktrailPublicKeys), |
| 948 | 948 | ] |
@@ -1120,10 +1120,7 @@ discard block |
||
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | $identifier = $options['identifier']; |
| 1123 | - $readonly = isset($options['readonly']) ? $options['readonly'] : |
|
| 1124 | - (isset($options['readOnly']) ? $options['readOnly'] : |
|
| 1125 | - (isset($options['read-only']) ? $options['read-only'] : |
|
| 1126 | - false)); |
|
| 1123 | + $readonly = isset($options['readonly']) ? $options['readonly'] : (isset($options['readOnly']) ? $options['readOnly'] : (isset($options['read-only']) ? $options['read-only'] : false)); |
|
| 1127 | 1124 | |
| 1128 | 1125 | // get the wallet data from the server |
| 1129 | 1126 | $data = $this->getWallet($identifier); |
@@ -1806,7 +1803,7 @@ discard block |
||
| 1806 | 1803 | */ |
| 1807 | 1804 | public static function sortMultisigKeys(array $pubKeys) { |
| 1808 | 1805 | $result = array_values($pubKeys); |
| 1809 | - usort($result, function (PublicKeyInterface $a, PublicKeyInterface $b) { |
|
| 1806 | + usort($result, function(PublicKeyInterface $a, PublicKeyInterface $b) { |
|
| 1810 | 1807 | $av = $a->getHex(); |
| 1811 | 1808 | $bv = $b->getHex(); |
| 1812 | 1809 | return $av == $bv ? 0 : $av > $bv ? 1 : -1; |
@@ -1832,7 +1829,7 @@ discard block |
||
| 1832 | 1829 | } |
| 1833 | 1830 | |
| 1834 | 1831 | public static function normalizeBIP32KeyArray($keys) { |
| 1835 | - return Util::arrayMapWithIndex(function ($idx, $key) { |
|
| 1832 | + return Util::arrayMapWithIndex(function($idx, $key) { |
|
| 1836 | 1833 | return [$idx, self::normalizeBIP32Key($key)]; |
| 1837 | 1834 | }, $keys); |
| 1838 | 1835 | } |