Complex classes like BlocktrailSDK often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BlocktrailSDK, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class BlocktrailSDK implements BlocktrailSDKInterface { |
||
| 34 | /** |
||
| 35 | * @var Connection\RestClient |
||
| 36 | */ |
||
| 37 | protected $client; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string currently only supporting; bitcoin |
||
| 41 | */ |
||
| 42 | protected $network; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var bool |
||
| 46 | */ |
||
| 47 | protected $testnet; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $apiKey the API_KEY to use for authentication |
||
| 51 | * @param string $apiSecret the API_SECRET to use for authentication |
||
| 52 | * @param string $network the cryptocurrency 'network' to consume, eg BTC, LTC, etc |
||
| 53 | * @param bool $testnet testnet yes/no |
||
| 54 | * @param string $apiVersion the version of the API to consume |
||
| 55 | * @param null $apiEndpoint overwrite the endpoint used |
||
| 56 | * this will cause the $network, $testnet and $apiVersion to be ignored! |
||
| 57 | */ |
||
| 58 | 80 | public function __construct($apiKey, $apiSecret, $network = 'BTC', $testnet = false, $apiVersion = 'v1', $apiEndpoint = null) { |
|
| 73 | |||
| 74 | /** |
||
| 75 | * normalize network string |
||
| 76 | * |
||
| 77 | * @param $network |
||
| 78 | * @param $testnet |
||
| 79 | * @return array |
||
| 80 | * @throws \Exception |
||
| 81 | */ |
||
| 82 | 80 | protected function normalizeNetwork($network, $testnet) { |
|
| 85 | |||
| 86 | /** |
||
| 87 | * set BitcoinLib to the correct magic-byte defaults for the selected network |
||
| 88 | * |
||
| 89 | * @param $network |
||
| 90 | * @param $testnet |
||
| 91 | */ |
||
| 92 | 80 | protected function setBitcoinLibMagicBytes($network, $testnet) { |
|
| 96 | |||
| 97 | /** |
||
| 98 | * enable CURL debugging output |
||
| 99 | * |
||
| 100 | * @param bool $debug |
||
| 101 | * |
||
| 102 | * @codeCoverageIgnore |
||
| 103 | */ |
||
| 104 | public function setCurlDebugging($debug = true) { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * enable verbose errors |
||
| 110 | * |
||
| 111 | * @param bool $verboseErrors |
||
| 112 | * |
||
| 113 | * @codeCoverageIgnore |
||
| 114 | */ |
||
| 115 | public function setVerboseErrors($verboseErrors = true) { |
||
| 118 | |||
| 119 | /** |
||
| 120 | * set cURL default option on Guzzle client |
||
| 121 | * @param string $key |
||
| 122 | * @param bool $value |
||
| 123 | * |
||
| 124 | * @codeCoverageIgnore |
||
| 125 | */ |
||
| 126 | public function setCurlDefaultOption($key, $value) { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return RestClient |
||
| 132 | */ |
||
| 133 | 2 | public function getRestClient() { |
|
| 136 | |||
| 137 | /** |
||
| 138 | * get a single address |
||
| 139 | * @param string $address address hash |
||
| 140 | * @return array associative array containing the response |
||
| 141 | */ |
||
| 142 | 1 | public function address($address) { |
|
| 146 | |||
| 147 | /** |
||
| 148 | * get all transactions for an address (paginated) |
||
| 149 | * @param string $address address hash |
||
| 150 | * @param integer $page pagination: page number |
||
| 151 | * @param integer $limit pagination: records per page (max 500) |
||
| 152 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 153 | * @return array associative array containing the response |
||
| 154 | */ |
||
| 155 | 1 | public function addressTransactions($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 164 | |||
| 165 | /** |
||
| 166 | * get all unconfirmed transactions for an address (paginated) |
||
| 167 | * @param string $address address hash |
||
| 168 | * @param integer $page pagination: page number |
||
| 169 | * @param integer $limit pagination: records per page (max 500) |
||
| 170 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 171 | * @return array associative array containing the response |
||
| 172 | */ |
||
| 173 | 1 | public function addressUnconfirmedTransactions($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 182 | |||
| 183 | /** |
||
| 184 | * get all unspent outputs for an address (paginated) |
||
| 185 | * @param string $address address hash |
||
| 186 | * @param integer $page pagination: page number |
||
| 187 | * @param integer $limit pagination: records per page (max 500) |
||
| 188 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 189 | * @return array associative array containing the response |
||
| 190 | */ |
||
| 191 | 1 | public function addressUnspentOutputs($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 200 | |||
| 201 | /** |
||
| 202 | * get all unspent outputs for a batch of addresses (paginated) |
||
| 203 | * |
||
| 204 | * @param string[] $addresses |
||
| 205 | * @param integer $page pagination: page number |
||
| 206 | * @param integer $limit pagination: records per page (max 500) |
||
| 207 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 208 | * @return array associative array containing the response |
||
| 209 | * @throws \Exception |
||
| 210 | */ |
||
| 211 | public function batchAddressUnspentOutputs($addresses, $page = 1, $limit = 20, $sortDir = 'asc') { |
||
| 220 | |||
| 221 | /** |
||
| 222 | * verify ownership of an address |
||
| 223 | * @param string $address address hash |
||
| 224 | * @param string $signature a signed message (the address hash) using the private key of the address |
||
| 225 | * @return array associative array containing the response |
||
| 226 | */ |
||
| 227 | 2 | public function verifyAddress($address, $signature) { |
|
| 234 | |||
| 235 | /** |
||
| 236 | * get all blocks (paginated) |
||
| 237 | * @param integer $page pagination: page number |
||
| 238 | * @param integer $limit pagination: records per page |
||
| 239 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 240 | * @return array associative array containing the response |
||
| 241 | */ |
||
| 242 | 1 | public function allBlocks($page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 251 | |||
| 252 | /** |
||
| 253 | * get the latest block |
||
| 254 | * @return array associative array containing the response |
||
| 255 | */ |
||
| 256 | 1 | public function blockLatest() { |
|
| 260 | |||
| 261 | /** |
||
| 262 | * get an individual block |
||
| 263 | * @param string|integer $block a block hash or a block height |
||
| 264 | * @return array associative array containing the response |
||
| 265 | */ |
||
| 266 | 1 | public function block($block) { |
|
| 270 | |||
| 271 | /** |
||
| 272 | * get all transaction in a block (paginated) |
||
| 273 | * @param string|integer $block a block hash or a block height |
||
| 274 | * @param integer $page pagination: page number |
||
| 275 | * @param integer $limit pagination: records per page |
||
| 276 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 277 | * @return array associative array containing the response |
||
| 278 | */ |
||
| 279 | 1 | public function blockTransactions($block, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 288 | |||
| 289 | /** |
||
| 290 | * get a single transaction |
||
| 291 | * @param string $txhash transaction hash |
||
| 292 | * @return array associative array containing the response |
||
| 293 | */ |
||
| 294 | 5 | public function transaction($txhash) { |
|
| 298 | |||
| 299 | /** |
||
| 300 | * get a single transaction |
||
| 301 | * @param string[] $txhashes list of transaction hashes (up to 20) |
||
| 302 | * @return array[] array containing the response |
||
| 303 | */ |
||
| 304 | public function transactions($txhashes) { |
||
| 308 | |||
| 309 | /** |
||
| 310 | * get a paginated list of all webhooks associated with the api user |
||
| 311 | * @param integer $page pagination: page number |
||
| 312 | * @param integer $limit pagination: records per page |
||
| 313 | * @return array associative array containing the response |
||
| 314 | */ |
||
| 315 | 1 | public function allWebhooks($page = 1, $limit = 20) { |
|
| 323 | |||
| 324 | /** |
||
| 325 | * get an existing webhook by it's identifier |
||
| 326 | * @param string $identifier a unique identifier associated with the webhook |
||
| 327 | * @return array associative array containing the response |
||
| 328 | */ |
||
| 329 | 1 | public function getWebhook($identifier) { |
|
| 333 | |||
| 334 | /** |
||
| 335 | * create a new webhook |
||
| 336 | * @param string $url the url to receive the webhook events |
||
| 337 | * @param string $identifier a unique identifier to associate with this webhook |
||
| 338 | * @return array associative array containing the response |
||
| 339 | */ |
||
| 340 | 1 | public function setupWebhook($url, $identifier = null) { |
|
| 348 | |||
| 349 | /** |
||
| 350 | * update an existing webhook |
||
| 351 | * @param string $identifier the unique identifier of the webhook to update |
||
| 352 | * @param string $newUrl the new url to receive the webhook events |
||
| 353 | * @param string $newIdentifier a new unique identifier to associate with this webhook |
||
| 354 | * @return array associative array containing the response |
||
| 355 | */ |
||
| 356 | 1 | public function updateWebhook($identifier, $newUrl = null, $newIdentifier = null) { |
|
| 364 | |||
| 365 | /** |
||
| 366 | * deletes an existing webhook and any event subscriptions associated with it |
||
| 367 | * @param string $identifier the unique identifier of the webhook to delete |
||
| 368 | * @return boolean true on success |
||
| 369 | */ |
||
| 370 | 1 | public function deleteWebhook($identifier) { |
|
| 374 | |||
| 375 | /** |
||
| 376 | * get a paginated list of all the events a webhook is subscribed to |
||
| 377 | * @param string $identifier the unique identifier of the webhook |
||
| 378 | * @param integer $page pagination: page number |
||
| 379 | * @param integer $limit pagination: records per page |
||
| 380 | * @return array associative array containing the response |
||
| 381 | */ |
||
| 382 | 2 | public function getWebhookEvents($identifier, $page = 1, $limit = 20) { |
|
| 390 | |||
| 391 | /** |
||
| 392 | * subscribes a webhook to transaction events of one particular transaction |
||
| 393 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 394 | * @param string $transaction the transaction hash |
||
| 395 | * @param integer $confirmations the amount of confirmations to send. |
||
| 396 | * @return array associative array containing the response |
||
| 397 | */ |
||
| 398 | 1 | public function subscribeTransaction($identifier, $transaction, $confirmations = 6) { |
|
| 407 | |||
| 408 | /** |
||
| 409 | * subscribes a webhook to transaction events on a particular address |
||
| 410 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 411 | * @param string $address the address hash |
||
| 412 | * @param integer $confirmations the amount of confirmations to send. |
||
| 413 | * @return array associative array containing the response |
||
| 414 | */ |
||
| 415 | 1 | public function subscribeAddressTransactions($identifier, $address, $confirmations = 6) { |
|
| 424 | |||
| 425 | /** |
||
| 426 | * batch subscribes a webhook to multiple transaction events |
||
| 427 | * |
||
| 428 | * @param string $identifier the unique identifier of the webhook |
||
| 429 | * @param array $batchData A 2D array of event data: |
||
| 430 | * [address => $address, confirmations => $confirmations] |
||
| 431 | * where $address is the address to subscibe to |
||
| 432 | * and optionally $confirmations is the amount of confirmations |
||
| 433 | * @return boolean true on success |
||
| 434 | */ |
||
| 435 | 1 | public function batchSubscribeAddressTransactions($identifier, $batchData) { |
|
| 447 | |||
| 448 | /** |
||
| 449 | * subscribes a webhook to a new block event |
||
| 450 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 451 | * @return array associative array containing the response |
||
| 452 | */ |
||
| 453 | 1 | public function subscribeNewBlocks($identifier) { |
|
| 460 | |||
| 461 | /** |
||
| 462 | * removes an transaction event subscription from a webhook |
||
| 463 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 464 | * @param string $transaction the transaction hash of the event subscription |
||
| 465 | * @return boolean true on success |
||
| 466 | */ |
||
| 467 | 1 | public function unsubscribeTransaction($identifier, $transaction) { |
|
| 471 | |||
| 472 | /** |
||
| 473 | * removes an address transaction event subscription from a webhook |
||
| 474 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 475 | * @param string $address the address hash of the event subscription |
||
| 476 | * @return boolean true on success |
||
| 477 | */ |
||
| 478 | 1 | public function unsubscribeAddressTransactions($identifier, $address) { |
|
| 482 | |||
| 483 | /** |
||
| 484 | * removes a block event subscription from a webhook |
||
| 485 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 486 | * @return boolean true on success |
||
| 487 | */ |
||
| 488 | 1 | public function unsubscribeNewBlocks($identifier) { |
|
| 492 | |||
| 493 | /** |
||
| 494 | * create a new wallet |
||
| 495 | * - will generate a new primary seed (with password) and backup seed (without password) |
||
| 496 | * - send the primary seed (BIP39 'encrypted') and backup public key to the server |
||
| 497 | * - receive the blocktrail co-signing public key from the server |
||
| 498 | * |
||
| 499 | * Either takes one argument: |
||
| 500 | * @param array $options |
||
| 501 | * |
||
| 502 | * Or takes three arguments (old, deprecated syntax): |
||
| 503 | * (@nonPHP-doc) @param $identifier |
||
| 504 | * (@nonPHP-doc) @param $password |
||
| 505 | * (@nonPHP-doc) @param int $keyIndex override for the blocktrail cosigning key to use |
||
|
|
|||
| 506 | * |
||
| 507 | * @return array[WalletInterface, array] list($wallet, $backupInfo) |
||
| 508 | * @throws \Exception |
||
| 509 | */ |
||
| 510 | 7 | public function createNewWallet($options) { |
|
| 554 | |||
| 555 | 1 | protected function createNewWalletV1($options) { |
|
| 665 | |||
| 666 | 5 | public static function randomBits($bits) { |
|
| 669 | |||
| 670 | 5 | public static function randomBytes($bytes) { |
|
| 673 | |||
| 674 | 2 | protected function createNewWalletV2($options) { |
|
| 794 | |||
| 795 | 4 | protected function createNewWalletV3($options) { |
|
| 933 | |||
| 934 | /** |
||
| 935 | * @param array $bip32Key |
||
| 936 | * @throws BlocktrailSDKException |
||
| 937 | */ |
||
| 938 | 10 | private function verifyPublicBIP32Key(array $bip32Key) { |
|
| 948 | |||
| 949 | /** |
||
| 950 | * @param array $walletData |
||
| 951 | * @throws BlocktrailSDKException |
||
| 952 | */ |
||
| 953 | 10 | private function verifyPublicOnly(array $walletData) { |
|
| 957 | |||
| 958 | /** |
||
| 959 | * create wallet using the API |
||
| 960 | * |
||
| 961 | * @param string $identifier the wallet identifier to create |
||
| 962 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 963 | * @param string $backupPublicKey plain public key |
||
| 964 | * @param string $primaryMnemonic mnemonic to store |
||
| 965 | * @param string $checksum checksum to store |
||
| 966 | * @param int $keyIndex account that we expect to use |
||
| 967 | * @return mixed |
||
| 968 | */ |
||
| 969 | 1 | public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, $keyIndex) { |
|
| 982 | |||
| 983 | /** |
||
| 984 | * create wallet using the API |
||
| 985 | * |
||
| 986 | * @param string $identifier the wallet identifier to create |
||
| 987 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 988 | * @param string $backupPublicKey plain public key |
||
| 989 | * @param $encryptedPrimarySeed |
||
| 990 | * @param $encryptedSecret |
||
| 991 | * @param $recoverySecret |
||
| 992 | * @param string $checksum checksum to store |
||
| 993 | * @param int $keyIndex account that we expect to use |
||
| 994 | * @return mixed |
||
| 995 | * @throws \Exception |
||
| 996 | */ |
||
| 997 | 5 | public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1013 | |||
| 1014 | /** |
||
| 1015 | * create wallet using the API |
||
| 1016 | * |
||
| 1017 | * @param string $identifier the wallet identifier to create |
||
| 1018 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1019 | * @param string $backupPublicKey plain public key |
||
| 1020 | * @param $encryptedPrimarySeed |
||
| 1021 | * @param $encryptedSecret |
||
| 1022 | * @param $recoverySecret |
||
| 1023 | * @param string $checksum checksum to store |
||
| 1024 | * @param int $keyIndex account that we expect to use |
||
| 1025 | * @return mixed |
||
| 1026 | * @throws \Exception |
||
| 1027 | */ |
||
| 1028 | 4 | public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1046 | |||
| 1047 | /** |
||
| 1048 | * upgrade wallet to use a new account number |
||
| 1049 | * the account number specifies which blocktrail cosigning key is used |
||
| 1050 | * |
||
| 1051 | * @param string $identifier the wallet identifier to be upgraded |
||
| 1052 | * @param int $keyIndex the new account to use |
||
| 1053 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1054 | * @return mixed |
||
| 1055 | */ |
||
| 1056 | 5 | public function upgradeKeyIndex($identifier, $keyIndex, $primaryPublicKey) { |
|
| 1065 | |||
| 1066 | /** |
||
| 1067 | * initialize a previously created wallet |
||
| 1068 | * |
||
| 1069 | * Either takes one argument: |
||
| 1070 | * @param array $options |
||
| 1071 | * |
||
| 1072 | * Or takes two arguments (old, deprecated syntax): |
||
| 1073 | * (@nonPHP-doc) @param string $identifier the wallet identifier to be initialized |
||
| 1074 | * (@nonPHP-doc) @param string $password the password to decrypt the mnemonic with |
||
| 1075 | * |
||
| 1076 | * @return WalletInterface |
||
| 1077 | * @throws \Exception |
||
| 1078 | */ |
||
| 1079 | 15 | public function initWallet($options) { |
|
| 1177 | |||
| 1178 | /** |
||
| 1179 | * get the wallet data from the server |
||
| 1180 | * |
||
| 1181 | * @param string $identifier the identifier of the wallet |
||
| 1182 | * @return mixed |
||
| 1183 | */ |
||
| 1184 | 15 | public function getWallet($identifier) { |
|
| 1188 | |||
| 1189 | /** |
||
| 1190 | * update the wallet data on the server |
||
| 1191 | * |
||
| 1192 | * @param string $identifier |
||
| 1193 | * @param $data |
||
| 1194 | * @return mixed |
||
| 1195 | */ |
||
| 1196 | 3 | public function updateWallet($identifier, $data) { |
|
| 1200 | |||
| 1201 | /** |
||
| 1202 | * delete a wallet from the server |
||
| 1203 | * the checksum address and a signature to verify you ownership of the key of that checksum address |
||
| 1204 | * is required to be able to delete a wallet |
||
| 1205 | * |
||
| 1206 | * @param string $identifier the identifier of the wallet |
||
| 1207 | * @param string $checksumAddress the address for your master private key (and the checksum used when creating the wallet) |
||
| 1208 | * @param string $signature a signature of the checksum address as message signed by the private key matching that address |
||
| 1209 | * @param bool $force ignore warnings (such as a non-zero balance) |
||
| 1210 | * @return mixed |
||
| 1211 | */ |
||
| 1212 | 10 | public function deleteWallet($identifier, $checksumAddress, $signature, $force = false) { |
|
| 1219 | |||
| 1220 | /** |
||
| 1221 | * create new backup key; |
||
| 1222 | * 1) a BIP39 mnemonic |
||
| 1223 | * 2) a seed from that mnemonic with a blank password |
||
| 1224 | * 3) a private key from that seed |
||
| 1225 | * |
||
| 1226 | * @return array [mnemonic, seed, key] |
||
| 1227 | */ |
||
| 1228 | 1 | protected function newBackupSeed() { |
|
| 1233 | |||
| 1234 | /** |
||
| 1235 | * create new primary key; |
||
| 1236 | * 1) a BIP39 mnemonic |
||
| 1237 | * 2) a seed from that mnemonic with the password |
||
| 1238 | * 3) a private key from that seed |
||
| 1239 | * |
||
| 1240 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1241 | * @return array [mnemonic, seed, key] |
||
| 1242 | * @TODO: require a strong password? |
||
| 1243 | */ |
||
| 1244 | 1 | protected function newPrimarySeed($passphrase) { |
|
| 1249 | |||
| 1250 | /** |
||
| 1251 | * create a new key; |
||
| 1252 | * 1) a BIP39 mnemonic |
||
| 1253 | * 2) a seed from that mnemonic with the password |
||
| 1254 | * 3) a private key from that seed |
||
| 1255 | * |
||
| 1256 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1257 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1258 | * @return array |
||
| 1259 | */ |
||
| 1260 | 1 | protected function generateNewSeed($passphrase = "", $forceEntropy = null) { |
|
| 1277 | |||
| 1278 | /** |
||
| 1279 | * generate a new mnemonic from some random entropy (512 bit) |
||
| 1280 | * |
||
| 1281 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1282 | * @return string |
||
| 1283 | * @throws \Exception |
||
| 1284 | */ |
||
| 1285 | 1 | protected function generateNewMnemonic($forceEntropy = null) { |
|
| 1295 | |||
| 1296 | /** |
||
| 1297 | * get the balance for the wallet |
||
| 1298 | * |
||
| 1299 | * @param string $identifier the identifier of the wallet |
||
| 1300 | * @return array |
||
| 1301 | */ |
||
| 1302 | 9 | public function getWalletBalance($identifier) { |
|
| 1306 | |||
| 1307 | /** |
||
| 1308 | * do HD wallet discovery for the wallet |
||
| 1309 | * |
||
| 1310 | * this can be REALLY slow, so we've set the timeout to 120s ... |
||
| 1311 | * |
||
| 1312 | * @param string $identifier the identifier of the wallet |
||
| 1313 | * @param int $gap the gap setting to use for discovery |
||
| 1314 | * @return mixed |
||
| 1315 | */ |
||
| 1316 | 2 | public function doWalletDiscovery($identifier, $gap = 200) { |
|
| 1320 | |||
| 1321 | /** |
||
| 1322 | * get a new derivation number for specified parent path |
||
| 1323 | * eg; m/44'/1'/0/0 results in m/44'/1'/0/0/0 and next time in m/44'/1'/0/0/1 and next time in m/44'/1'/0/0/2 |
||
| 1324 | * |
||
| 1325 | * returns the path |
||
| 1326 | * |
||
| 1327 | * @param string $identifier the identifier of the wallet |
||
| 1328 | * @param string $path the parent path for which to get a new derivation |
||
| 1329 | * @return string |
||
| 1330 | */ |
||
| 1331 | 1 | public function getNewDerivation($identifier, $path) { |
|
| 1335 | |||
| 1336 | /** |
||
| 1337 | * get a new derivation number for specified parent path |
||
| 1338 | * eg; m/44'/1'/0/0 results in m/44'/1'/0/0/0 and next time in m/44'/1'/0/0/1 and next time in m/44'/1'/0/0/2 |
||
| 1339 | * |
||
| 1340 | * @param string $identifier the identifier of the wallet |
||
| 1341 | * @param string $path the parent path for which to get a new derivation |
||
| 1342 | * @return mixed |
||
| 1343 | */ |
||
| 1344 | 13 | public function _getNewDerivation($identifier, $path) { |
|
| 1348 | |||
| 1349 | /** |
||
| 1350 | * get the path (and redeemScript) to specified address |
||
| 1351 | * |
||
| 1352 | * @param string $identifier |
||
| 1353 | * @param string $address |
||
| 1354 | * @return array |
||
| 1355 | * @throws \Exception |
||
| 1356 | */ |
||
| 1357 | public function getPathForAddress($identifier, $address) { |
||
| 1361 | |||
| 1362 | /** |
||
| 1363 | * send the transaction using the API |
||
| 1364 | * |
||
| 1365 | * @param string $identifier the identifier of the wallet |
||
| 1366 | * @param string|array $rawTransaction raw hex of the transaction (should be partially signed) |
||
| 1367 | * @param array $paths list of the paths that were used for the UTXO |
||
| 1368 | * @param bool $checkFee let the server verify the fee after signing |
||
| 1369 | * @return string the complete raw transaction |
||
| 1370 | * @throws \Exception |
||
| 1371 | */ |
||
| 1372 | 4 | public function sendTransaction($identifier, $rawTransaction, $paths, $checkFee = false) { |
|
| 1402 | |||
| 1403 | /** |
||
| 1404 | * use the API to get the best inputs to use based on the outputs |
||
| 1405 | * |
||
| 1406 | * the return array has the following format: |
||
| 1407 | * [ |
||
| 1408 | * "utxos" => [ |
||
| 1409 | * [ |
||
| 1410 | * "hash" => "<txHash>", |
||
| 1411 | * "idx" => "<index of the output of that <txHash>", |
||
| 1412 | * "scriptpubkey_hex" => "<scriptPubKey-hex>", |
||
| 1413 | * "value" => 32746327, |
||
| 1414 | * "address" => "1address", |
||
| 1415 | * "path" => "m/44'/1'/0'/0/13", |
||
| 1416 | * "redeem_script" => "<redeemScript-hex>", |
||
| 1417 | * ], |
||
| 1418 | * ], |
||
| 1419 | * "fee" => 10000, |
||
| 1420 | * "change"=> 1010109201, |
||
| 1421 | * ] |
||
| 1422 | * |
||
| 1423 | * @param string $identifier the identifier of the wallet |
||
| 1424 | * @param array $outputs the outputs you want to create - array[address => satoshi-value] |
||
| 1425 | * @param bool $lockUTXO when TRUE the UTXOs selected will be locked for a few seconds |
||
| 1426 | * so you have some time to spend them without race-conditions |
||
| 1427 | * @param bool $allowZeroConf |
||
| 1428 | * @param string $feeStrategy |
||
| 1429 | * @param null|int $forceFee |
||
| 1430 | * @return array |
||
| 1431 | * @throws \Exception |
||
| 1432 | */ |
||
| 1433 | 11 | public function coinSelection($identifier, $outputs, $lockUTXO = false, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null) { |
|
| 1453 | |||
| 1454 | /** |
||
| 1455 | * |
||
| 1456 | * @param string $identifier the identifier of the wallet |
||
| 1457 | * @param bool $allowZeroConf |
||
| 1458 | * @param string $feeStrategy |
||
| 1459 | * @param null|int $forceFee |
||
| 1460 | * @param int $outputCnt |
||
| 1461 | * @return array |
||
| 1462 | * @throws \Exception |
||
| 1463 | */ |
||
| 1464 | public function walletMaxSpendable($identifier, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null, $outputCnt = 1) { |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * @return array ['optimal_fee' => 10000, 'low_priority_fee' => 5000] |
||
| 1486 | */ |
||
| 1487 | 3 | public function feePerKB() { |
|
| 1491 | |||
| 1492 | /** |
||
| 1493 | * get the current price index |
||
| 1494 | * |
||
| 1495 | * @return array eg; ['USD' => 287.30] |
||
| 1496 | */ |
||
| 1497 | 1 | public function price() { |
|
| 1501 | |||
| 1502 | /** |
||
| 1503 | * setup webhook for wallet |
||
| 1504 | * |
||
| 1505 | * @param string $identifier the wallet identifier for which to create the webhook |
||
| 1506 | * @param string $webhookIdentifier the webhook identifier to use |
||
| 1507 | * @param string $url the url to receive the webhook events |
||
| 1508 | * @return array |
||
| 1509 | */ |
||
| 1510 | 1 | public function setupWalletWebhook($identifier, $webhookIdentifier, $url) { |
|
| 1514 | |||
| 1515 | /** |
||
| 1516 | * delete webhook for wallet |
||
| 1517 | * |
||
| 1518 | * @param string $identifier the wallet identifier for which to delete the webhook |
||
| 1519 | * @param string $webhookIdentifier the webhook identifier to delete |
||
| 1520 | * @return array |
||
| 1521 | */ |
||
| 1522 | 1 | public function deleteWalletWebhook($identifier, $webhookIdentifier) { |
|
| 1526 | |||
| 1527 | /** |
||
| 1528 | * lock a specific unspent output |
||
| 1529 | * |
||
| 1530 | * @param $identifier |
||
| 1531 | * @param $txHash |
||
| 1532 | * @param $txIdx |
||
| 1533 | * @param int $ttl |
||
| 1534 | * @return bool |
||
| 1535 | */ |
||
| 1536 | public function lockWalletUTXO($identifier, $txHash, $txIdx, $ttl = 3) { |
||
| 1540 | |||
| 1541 | /** |
||
| 1542 | * unlock a specific unspent output |
||
| 1543 | * |
||
| 1544 | * @param $identifier |
||
| 1545 | * @param $txHash |
||
| 1546 | * @param $txIdx |
||
| 1547 | * @return bool |
||
| 1548 | */ |
||
| 1549 | public function unlockWalletUTXO($identifier, $txHash, $txIdx) { |
||
| 1553 | |||
| 1554 | /** |
||
| 1555 | * get all transactions for wallet (paginated) |
||
| 1556 | * |
||
| 1557 | * @param string $identifier the wallet identifier for which to get transactions |
||
| 1558 | * @param integer $page pagination: page number |
||
| 1559 | * @param integer $limit pagination: records per page (max 500) |
||
| 1560 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1561 | * @return array associative array containing the response |
||
| 1562 | */ |
||
| 1563 | 1 | public function walletTransactions($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 1572 | |||
| 1573 | /** |
||
| 1574 | * get all addresses for wallet (paginated) |
||
| 1575 | * |
||
| 1576 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1577 | * @param integer $page pagination: page number |
||
| 1578 | * @param integer $limit pagination: records per page (max 500) |
||
| 1579 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1580 | * @return array associative array containing the response |
||
| 1581 | */ |
||
| 1582 | 1 | public function walletAddresses($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 1591 | |||
| 1592 | /** |
||
| 1593 | * get all UTXOs for wallet (paginated) |
||
| 1594 | * |
||
| 1595 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1596 | * @param integer $page pagination: page number |
||
| 1597 | * @param integer $limit pagination: records per page (max 500) |
||
| 1598 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1599 | * @param boolean $zeroconf include zero confirmation transactions |
||
| 1600 | * @return array associative array containing the response |
||
| 1601 | */ |
||
| 1602 | 1 | public function walletUTXOs($identifier, $page = 1, $limit = 20, $sortDir = 'asc', $zeroconf = true) { |
|
| 1612 | |||
| 1613 | /** |
||
| 1614 | * get a paginated list of all wallets associated with the api user |
||
| 1615 | * |
||
| 1616 | * @param integer $page pagination: page number |
||
| 1617 | * @param integer $limit pagination: records per page |
||
| 1618 | * @return array associative array containing the response |
||
| 1619 | */ |
||
| 1620 | 2 | public function allWallets($page = 1, $limit = 20) { |
|
| 1628 | |||
| 1629 | /** |
||
| 1630 | * send raw transaction |
||
| 1631 | * |
||
| 1632 | * @param $txHex |
||
| 1633 | * @return bool |
||
| 1634 | */ |
||
| 1635 | public function sendRawTransaction($txHex) { |
||
| 1639 | |||
| 1640 | /** |
||
| 1641 | * testnet only ;-) |
||
| 1642 | * |
||
| 1643 | * @param $address |
||
| 1644 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1645 | * @return mixed |
||
| 1646 | * @throws \Exception |
||
| 1647 | */ |
||
| 1648 | public function faucetWithdrawal($address, $amount = 10000) { |
||
| 1655 | |||
| 1656 | /** |
||
| 1657 | * Exists for BC. Remove at major bump. |
||
| 1658 | * |
||
| 1659 | * @see faucetWithdrawal |
||
| 1660 | * @deprecated |
||
| 1661 | * @param $address |
||
| 1662 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1663 | * @return mixed |
||
| 1664 | * @throws \Exception |
||
| 1665 | */ |
||
| 1666 | public function faucetWithdrawl($address, $amount = 10000) { |
||
| 1669 | |||
| 1670 | /** |
||
| 1671 | * verify a message signed bitcoin-core style |
||
| 1672 | * |
||
| 1673 | * @param string $message |
||
| 1674 | * @param string $address |
||
| 1675 | * @param string $signature |
||
| 1676 | * @return boolean |
||
| 1677 | */ |
||
| 1678 | 1 | public function verifyMessage($message, $address, $signature) { |
|
| 1695 | |||
| 1696 | /** |
||
| 1697 | * convert a Satoshi value to a BTC value |
||
| 1698 | * |
||
| 1699 | * @param int $satoshi |
||
| 1700 | * @return float |
||
| 1701 | */ |
||
| 1702 | public static function toBTC($satoshi) { |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * convert a Satoshi value to a BTC value and return it as a string |
||
| 1708 | |||
| 1709 | * @param int $satoshi |
||
| 1710 | * @return string |
||
| 1711 | */ |
||
| 1712 | public static function toBTCString($satoshi) { |
||
| 1715 | |||
| 1716 | /** |
||
| 1717 | * convert a BTC value to a Satoshi value |
||
| 1718 | * |
||
| 1719 | * @param float $btc |
||
| 1720 | * @return string |
||
| 1721 | */ |
||
| 1722 | 12 | public static function toSatoshiString($btc) { |
|
| 1725 | |||
| 1726 | /** |
||
| 1727 | * convert a BTC value to a Satoshi value |
||
| 1728 | * |
||
| 1729 | * @param float $btc |
||
| 1730 | * @return string |
||
| 1731 | */ |
||
| 1732 | 12 | public static function toSatoshi($btc) { |
|
| 1735 | |||
| 1736 | /** |
||
| 1737 | * json_decode helper that throws exceptions when it fails to decode |
||
| 1738 | * |
||
| 1739 | * @param $json |
||
| 1740 | * @param bool $assoc |
||
| 1741 | * @return mixed |
||
| 1742 | * @throws \Exception |
||
| 1743 | */ |
||
| 1744 | 24 | protected static function jsonDecode($json, $assoc = false) { |
|
| 1757 | |||
| 1758 | /** |
||
| 1759 | * sort public keys for multisig script |
||
| 1760 | * |
||
| 1761 | * @param PublicKeyInterface[] $pubKeys |
||
| 1762 | * @return PublicKeyInterface[] |
||
| 1763 | */ |
||
| 1764 | 14 | public static function sortMultisigKeys(array $pubKeys) { |
|
| 1774 | |||
| 1775 | /** |
||
| 1776 | * read and decode the json payload from a webhook's POST request. |
||
| 1777 | * |
||
| 1778 | * @param bool $returnObject flag to indicate if an object or associative array should be returned |
||
| 1779 | * @return mixed|null |
||
| 1780 | * @throws \Exception |
||
| 1781 | */ |
||
| 1782 | public static function getWebhookPayload($returnObject = false) { |
||
| 1790 | |||
| 1791 | public static function normalizeBIP32KeyArray($keys) { |
||
| 1796 | |||
| 1797 | 18 | public static function normalizeBIP32Key($key) { |
|
| 1815 | } |
||
| 1816 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.