@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | /** |
| 111 | 111 | * normalize network string |
| 112 | 112 | * |
| 113 | - * @param $network |
|
| 113 | + * @param string $network |
|
| 114 | 114 | * @param $testnet |
| 115 | 115 | * @return array |
| 116 | 116 | * @throws \Exception |
@@ -746,6 +746,11 @@ discard block |
||
| 746 | 746 | ]; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | + /** |
|
| 750 | + * @param integer $bits |
|
| 751 | + * |
|
| 752 | + * @return string |
|
| 753 | + */ |
|
| 749 | 754 | public static function randomBits($bits) { |
| 750 | 755 | return self::randomBytes($bits / 8); |
| 751 | 756 | } |
@@ -1048,7 +1053,7 @@ discard block |
||
| 1048 | 1053 | * create wallet using the API |
| 1049 | 1054 | * |
| 1050 | 1055 | * @param string $identifier the wallet identifier to create |
| 1051 | - * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
|
| 1056 | + * @param string[] $primaryPublicKey BIP32 extended public key - [key, path] |
|
| 1052 | 1057 | * @param array $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
| 1053 | 1058 | * @param string $primaryMnemonic mnemonic to store |
| 1054 | 1059 | * @param string $checksum checksum to store |
@@ -1076,10 +1081,10 @@ discard block |
||
| 1076 | 1081 | * |
| 1077 | 1082 | * @param string $identifier the wallet identifier to create |
| 1078 | 1083 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
| 1079 | - * @param array $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1080 | - * @param $encryptedPrimarySeed |
|
| 1081 | - * @param $encryptedSecret |
|
| 1082 | - * @param $recoverySecret |
|
| 1084 | + * @param string[] $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1085 | + * @param string|false $encryptedPrimarySeed |
|
| 1086 | + * @param string|false $encryptedSecret |
|
| 1087 | + * @param string|false $recoverySecret |
|
| 1083 | 1088 | * @param string $checksum checksum to store |
| 1084 | 1089 | * @param int $keyIndex account that we expect to use |
| 1085 | 1090 | * @param bool $segwit opt in to segwit |
@@ -1109,9 +1114,9 @@ discard block |
||
| 1109 | 1114 | * |
| 1110 | 1115 | * @param string $identifier the wallet identifier to create |
| 1111 | 1116 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
| 1112 | - * @param array $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1113 | - * @param $encryptedPrimarySeed |
|
| 1114 | - * @param $encryptedSecret |
|
| 1117 | + * @param string[] $backupPublicKey BIP32 extended public key - [backup key, path "M"] |
|
| 1118 | + * @param string|false $encryptedPrimarySeed |
|
| 1119 | + * @param string|false $encryptedSecret |
|
| 1115 | 1120 | * @param $recoverySecret |
| 1116 | 1121 | * @param string $checksum checksum to store |
| 1117 | 1122 | * @param int $keyIndex account that we expect to use |
@@ -1843,7 +1848,7 @@ discard block |
||
| 1843 | 1848 | * convert a Satoshi value to a BTC value |
| 1844 | 1849 | * |
| 1845 | 1850 | * @param int $satoshi |
| 1846 | - * @return float |
|
| 1851 | + * @return string |
|
| 1847 | 1852 | */ |
| 1848 | 1853 | public static function toBTC($satoshi) { |
| 1849 | 1854 | return bcdiv((int)(string)$satoshi, 100000000, 8); |
@@ -1873,7 +1878,7 @@ discard block |
||
| 1873 | 1878 | * convert a BTC value to a Satoshi value |
| 1874 | 1879 | * |
| 1875 | 1880 | * @param float $btc |
| 1876 | - * @return string |
|
| 1881 | + * @return integer |
|
| 1877 | 1882 | */ |
| 1878 | 1883 | public static function toSatoshi($btc) { |
| 1879 | 1884 | return (int)self::toSatoshiString($btc); |
@@ -1934,6 +1939,9 @@ discard block |
||
| 1934 | 1939 | } |
| 1935 | 1940 | } |
| 1936 | 1941 | |
| 1942 | + /** |
|
| 1943 | + * @param BIP32Key[] $keys |
|
| 1944 | + */ |
|
| 1937 | 1945 | public static function normalizeBIP32KeyArray($keys) { |
| 1938 | 1946 | return Util::arrayMapWithIndex(function ($idx, $key) { |
| 1939 | 1947 | return [$idx, self::normalizeBIP32Key($key)]; |
@@ -23,7 +23,6 @@ |
||
| 23 | 23 | use Blocktrail\SDK\Address\BitcoinAddressReader; |
| 24 | 24 | use Blocktrail\SDK\Address\BitcoinCashAddressReader; |
| 25 | 25 | use Blocktrail\SDK\Address\CashAddress; |
| 26 | -use Blocktrail\SDK\Backend\BlocktrailConverter; |
|
| 27 | 26 | use Blocktrail\SDK\Backend\BtccomConverter; |
| 28 | 27 | use Blocktrail\SDK\Backend\ConverterInterface; |
| 29 | 28 | use Blocktrail\SDK\Bitcoin\BIP32Key; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $this->blocktrailClient = new RestClient($apiEndpoint, $apiVersion, $apiKey, $apiSecret); |
| 104 | 104 | $this->dataClient = new RestClient($btccomEndpoint, $apiVersion, $apiKey, $apiSecret); |
| 105 | - $this->btccomRawTxClient = new RestClient(($this->testnet ? "t" : "") . "chain.btc.com", $apiVersion, $apiKey, $apiSecret); |
|
| 105 | + $this->btccomRawTxClient = new RestClient(($this->testnet ? "t" : "")."chain.btc.com", $apiVersion, $apiKey, $apiSecret); |
|
| 106 | 106 | |
| 107 | 107 | $this->converter = new BtccomConverter(); |
| 108 | 108 | } |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | } else { |
| 643 | 643 | // create new primary seed |
| 644 | 644 | /** @var HierarchicalKey $primaryPrivateKey */ |
| 645 | - list($primaryMnemonic, , $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']); |
|
| 645 | + list($primaryMnemonic,, $primaryPrivateKey) = $this->newPrimarySeed($options['passphrase']); |
|
| 646 | 646 | if ($storePrimaryMnemonic !== false) { |
| 647 | 647 | $storePrimaryMnemonic = true; |
| 648 | 648 | } |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | $backupPublicKey = null; |
| 682 | 682 | if (!isset($options['backup_mnemonic']) && !isset($options['backup_public_key'])) { |
| 683 | 683 | /** @var HierarchicalKey $backupPrivateKey */ |
| 684 | - list($backupMnemonic, , ) = $this->newBackupSeed(); |
|
| 684 | + list($backupMnemonic,,) = $this->newBackupSeed(); |
|
| 685 | 685 | } else if (isset($options['backup_mnemonic'])) { |
| 686 | 686 | $backupMnemonic = $options['backup_mnemonic']; |
| 687 | 687 | } elseif (isset($options['backup_public_key'])) { |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | ); |
| 715 | 715 | |
| 716 | 716 | // received the blocktrail public keys |
| 717 | - $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) { |
|
| 717 | + $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) { |
|
| 718 | 718 | return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])]; |
| 719 | 719 | }, $data['blocktrail_public_keys']); |
| 720 | 720 | |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | ); |
| 837 | 837 | |
| 838 | 838 | // received the blocktrail public keys |
| 839 | - $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) { |
|
| 839 | + $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) { |
|
| 840 | 840 | return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])]; |
| 841 | 841 | }, $data['blocktrail_public_keys']); |
| 842 | 842 | |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | 'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer($backupSeed)) : null, |
| 872 | 872 | 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($recoveryEncryptedSecret))) : null, |
| 873 | 873 | 'encrypted_secret' => $encryptedSecret ? MnemonicFactory::bip39()->entropyToMnemonic(new Buffer(base64_decode($encryptedSecret))) : null, |
| 874 | - 'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) { |
|
| 874 | + 'blocktrail_public_keys' => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) { |
|
| 875 | 875 | return [$keyIndex, $pubKey->tuple()]; |
| 876 | 876 | }, $blocktrailPublicKeys), |
| 877 | 877 | ], |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | ); |
| 979 | 979 | |
| 980 | 980 | // received the blocktrail public keys |
| 981 | - $blocktrailPublicKeys = Util::arrayMapWithIndex(function ($keyIndex, $pubKeyTuple) { |
|
| 981 | + $blocktrailPublicKeys = Util::arrayMapWithIndex(function($keyIndex, $pubKeyTuple) { |
|
| 982 | 982 | return [$keyIndex, BIP32Key::create(HierarchicalKeyFactory::fromExtended($pubKeyTuple[0]), $pubKeyTuple[1])]; |
| 983 | 983 | }, $data['blocktrail_public_keys']); |
| 984 | 984 | |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | 'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic($backupSeed) : null, |
| 1014 | 1014 | 'recovery_encrypted_secret' => $recoveryEncryptedSecret ? EncryptionMnemonic::encode($recoveryEncryptedSecret) : null, |
| 1015 | 1015 | 'encrypted_secret' => $encryptedSecret ? EncryptionMnemonic::encode($encryptedSecret) : null, |
| 1016 | - 'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) { |
|
| 1016 | + 'blocktrail_public_keys' => Util::arrayMapWithIndex(function($keyIndex, BIP32Key $pubKey) { |
|
| 1017 | 1017 | return [$keyIndex, $pubKey->tuple()]; |
| 1018 | 1018 | }, $blocktrailPublicKeys), |
| 1019 | 1019 | ] |
@@ -1207,10 +1207,7 @@ discard block |
||
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | $identifier = $options['identifier']; |
| 1210 | - $readonly = isset($options['readonly']) ? $options['readonly'] : |
|
| 1211 | - (isset($options['readOnly']) ? $options['readOnly'] : |
|
| 1212 | - (isset($options['read-only']) ? $options['read-only'] : |
|
| 1213 | - false)); |
|
| 1210 | + $readonly = isset($options['readonly']) ? $options['readonly'] : (isset($options['readOnly']) ? $options['readOnly'] : (isset($options['read-only']) ? $options['read-only'] : false)); |
|
| 1214 | 1211 | |
| 1215 | 1212 | // get the wallet data from the server |
| 1216 | 1213 | $data = $this->getWallet($identifier); |
@@ -1909,7 +1906,7 @@ discard block |
||
| 1909 | 1906 | */ |
| 1910 | 1907 | public static function sortMultisigKeys(array $pubKeys) { |
| 1911 | 1908 | $result = array_values($pubKeys); |
| 1912 | - usort($result, function (PublicKeyInterface $a, PublicKeyInterface $b) { |
|
| 1909 | + usort($result, function(PublicKeyInterface $a, PublicKeyInterface $b) { |
|
| 1913 | 1910 | $av = $a->getHex(); |
| 1914 | 1911 | $bv = $b->getHex(); |
| 1915 | 1912 | return $av == $bv ? 0 : $av > $bv ? 1 : -1; |
@@ -1935,7 +1932,7 @@ discard block |
||
| 1935 | 1932 | } |
| 1936 | 1933 | |
| 1937 | 1934 | public static function normalizeBIP32KeyArray($keys) { |
| 1938 | - return Util::arrayMapWithIndex(function ($idx, $key) { |
|
| 1935 | + return Util::arrayMapWithIndex(function($idx, $key) { |
|
| 1939 | 1936 | return [$idx, self::normalizeBIP32Key($key)]; |
| 1940 | 1937 | }, $keys); |
| 1941 | 1938 | } |
@@ -29,9 +29,9 @@ |
||
| 29 | 29 | /** |
| 30 | 30 | * GuzzleRestClient constructor. |
| 31 | 31 | * @param $apiEndpoint |
| 32 | - * @param $apiVersion |
|
| 33 | - * @param $apiKey |
|
| 34 | - * @param $apiSecret |
|
| 32 | + * @param string $apiVersion |
|
| 33 | + * @param string $apiKey |
|
| 34 | + * @param string $apiSecret |
|
| 35 | 35 | */ |
| 36 | 36 | public function __construct($apiEndpoint, $apiVersion, $apiKey, $apiSecret) { |
| 37 | 37 | parent::__construct($apiEndpoint, $apiVersion, $apiKey, $apiSecret); |
@@ -61,7 +61,7 @@ discard block |
||
| 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, |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | throw new ObjectNotFound($this->verboseErrors ? $body : Blocktrail::EXCEPTION_OBJECT_NOT_FOUND, $httpResponseCode); |
| 171 | 171 | } |
| 172 | 172 | } elseif ($httpResponseCode == 500) { |
| 173 | - throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR . "\nServer Response: " . $body, $httpResponseCode); |
|
| 173 | + throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR."\nServer Response: ".$body, $httpResponseCode); |
|
| 174 | 174 | } else { |
| 175 | - throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR . "\nServer Response: " . $body, $httpResponseCode); |
|
| 175 | + throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR."\nServer Response: ".$body, $httpResponseCode); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function getUrlForTransactions($txIds) { |
| 35 | - return "tx/" . implode(",", $txIds) . "?verbose=3"; |
|
| 35 | + return "tx/".implode(",", $txIds)."?verbose=3"; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function getUrlForBlockTransaction($blockHash) { |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | $data['total_input_value'] = $totalInputValue; |
| 230 | - $data['total_output_value'] = array_reduce($tx['outputs'], function ($total, $output) { |
|
| 230 | + $data['total_output_value'] = array_reduce($tx['outputs'], function($total, $output) { |
|
| 231 | 231 | return $total + $output['value']; |
| 232 | 232 | }, 0); |
| 233 | 233 | $data['total_fee'] = $tx['fee']; |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function getUrlForTransactions($txIds) { |
| 21 | - return "transactions/" . implode(",", $txIds); |
|
| 21 | + return "transactions/".implode(",", $txIds); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function getUrlForBlockTransaction($blockHash) { |