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 | 29 | 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 | 29 | 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 | 29 | 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 | 2 | 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) { |
|
| 664 | |||
| 665 | 5 | public static function randomBits($bits) { |
|
| 668 | |||
| 669 | 5 | public static function randomBytes($bytes) { |
|
| 672 | |||
| 673 | 2 | protected function createNewWalletV2($options) { |
|
| 792 | |||
| 793 | 4 | protected function createNewWalletV3($options) { |
|
| 930 | |||
| 931 | /** |
||
| 932 | * @param array $bip32Key |
||
| 933 | * @throws BlocktrailSDKException |
||
| 934 | */ |
||
| 935 | 10 | private function verifyPublicBIP32Key(array $bip32Key) { |
|
| 945 | |||
| 946 | /** |
||
| 947 | * @param array $walletData |
||
| 948 | * @throws BlocktrailSDKException |
||
| 949 | */ |
||
| 950 | 10 | private function verifyPublicOnly(array $walletData) { |
|
| 954 | |||
| 955 | /** |
||
| 956 | * create wallet using the API |
||
| 957 | * |
||
| 958 | * @param string $identifier the wallet identifier to create |
||
| 959 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 960 | * @param string $backupPublicKey plain public key |
||
| 961 | * @param string $primaryMnemonic mnemonic to store |
||
| 962 | * @param string $checksum checksum to store |
||
| 963 | * @param int $keyIndex account that we expect to use |
||
| 964 | * @return mixed |
||
| 965 | */ |
||
| 966 | 1 | public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, $keyIndex) { |
|
| 979 | |||
| 980 | /** |
||
| 981 | * create wallet using the API |
||
| 982 | * |
||
| 983 | * @param string $identifier the wallet identifier to create |
||
| 984 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 985 | * @param string $backupPublicKey plain public key |
||
| 986 | * @param $encryptedPrimarySeed |
||
| 987 | * @param $encryptedSecret |
||
| 988 | * @param $recoverySecret |
||
| 989 | * @param string $checksum checksum to store |
||
| 990 | * @param int $keyIndex account that we expect to use |
||
| 991 | * @return mixed |
||
| 992 | * @throws \Exception |
||
| 993 | */ |
||
| 994 | 5 | public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1010 | |||
| 1011 | /** |
||
| 1012 | * create wallet using the API |
||
| 1013 | * |
||
| 1014 | * @param string $identifier the wallet identifier to create |
||
| 1015 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1016 | * @param string $backupPublicKey plain public key |
||
| 1017 | * @param $encryptedPrimarySeed |
||
| 1018 | * @param $encryptedSecret |
||
| 1019 | * @param $recoverySecret |
||
| 1020 | * @param string $checksum checksum to store |
||
| 1021 | * @param int $keyIndex account that we expect to use |
||
| 1022 | * @return mixed |
||
| 1023 | * @throws \Exception |
||
| 1024 | */ |
||
| 1025 | 4 | public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1043 | |||
| 1044 | /** |
||
| 1045 | * upgrade wallet to use a new account number |
||
| 1046 | * the account number specifies which blocktrail cosigning key is used |
||
| 1047 | * |
||
| 1048 | * @param string $identifier the wallet identifier to be upgraded |
||
| 1049 | * @param int $keyIndex the new account to use |
||
| 1050 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1051 | * @return mixed |
||
| 1052 | */ |
||
| 1053 | 5 | public function upgradeKeyIndex($identifier, $keyIndex, $primaryPublicKey) { |
|
| 1062 | |||
| 1063 | /** |
||
| 1064 | * initialize a previously created wallet |
||
| 1065 | * |
||
| 1066 | * Either takes one argument: |
||
| 1067 | * @param array $options |
||
| 1068 | * |
||
| 1069 | * Or takes two arguments (old, deprecated syntax): |
||
| 1070 | * (@nonPHP-doc) @param string $identifier the wallet identifier to be initialized |
||
| 1071 | * (@nonPHP-doc) @param string $password the password to decrypt the mnemonic with |
||
| 1072 | * |
||
| 1073 | * @return WalletInterface |
||
| 1074 | * @throws \Exception |
||
| 1075 | */ |
||
| 1076 | 11 | public function initWallet($options) { |
|
| 1172 | |||
| 1173 | /** |
||
| 1174 | * get the wallet data from the server |
||
| 1175 | * |
||
| 1176 | * @param string $identifier the identifier of the wallet |
||
| 1177 | * @return mixed |
||
| 1178 | */ |
||
| 1179 | 11 | public function getWallet($identifier) { |
|
| 1183 | |||
| 1184 | /** |
||
| 1185 | * update the wallet data on the server |
||
| 1186 | * |
||
| 1187 | * @param string $identifier |
||
| 1188 | * @param $data |
||
| 1189 | * @return mixed |
||
| 1190 | */ |
||
| 1191 | 3 | public function updateWallet($identifier, $data) { |
|
| 1195 | |||
| 1196 | /** |
||
| 1197 | * delete a wallet from the server |
||
| 1198 | * the checksum address and a signature to verify you ownership of the key of that checksum address |
||
| 1199 | * is required to be able to delete a wallet |
||
| 1200 | * |
||
| 1201 | * @param string $identifier the identifier of the wallet |
||
| 1202 | * @param string $checksumAddress the address for your master private key (and the checksum used when creating the wallet) |
||
| 1203 | * @param string $signature a signature of the checksum address as message signed by the private key matching that address |
||
| 1204 | * @param bool $force ignore warnings (such as a non-zero balance) |
||
| 1205 | * @return mixed |
||
| 1206 | */ |
||
| 1207 | 10 | public function deleteWallet($identifier, $checksumAddress, $signature, $force = false) { |
|
| 1214 | |||
| 1215 | /** |
||
| 1216 | * create new backup key; |
||
| 1217 | * 1) a BIP39 mnemonic |
||
| 1218 | * 2) a seed from that mnemonic with a blank password |
||
| 1219 | * 3) a private key from that seed |
||
| 1220 | * |
||
| 1221 | * @return array [mnemonic, seed, key] |
||
| 1222 | */ |
||
| 1223 | 1 | protected function newBackupSeed() { |
|
| 1228 | |||
| 1229 | /** |
||
| 1230 | * create new primary key; |
||
| 1231 | * 1) a BIP39 mnemonic |
||
| 1232 | * 2) a seed from that mnemonic with the password |
||
| 1233 | * 3) a private key from that seed |
||
| 1234 | * |
||
| 1235 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1236 | * @return array [mnemonic, seed, key] |
||
| 1237 | * @TODO: require a strong password? |
||
| 1238 | */ |
||
| 1239 | 1 | protected function newPrimarySeed($passphrase) { |
|
| 1244 | |||
| 1245 | /** |
||
| 1246 | * create a new key; |
||
| 1247 | * 1) a BIP39 mnemonic |
||
| 1248 | * 2) a seed from that mnemonic with the password |
||
| 1249 | * 3) a private key from that seed |
||
| 1250 | * |
||
| 1251 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1252 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1253 | * @return array |
||
| 1254 | */ |
||
| 1255 | 1 | protected function generateNewSeed($passphrase = "", $forceEntropy = null) { |
|
| 1272 | |||
| 1273 | /** |
||
| 1274 | * generate a new mnemonic from some random entropy (512 bit) |
||
| 1275 | * |
||
| 1276 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1277 | * @return string |
||
| 1278 | * @throws \Exception |
||
| 1279 | */ |
||
| 1280 | 1 | protected function generateNewMnemonic($forceEntropy = null) { |
|
| 1290 | |||
| 1291 | /** |
||
| 1292 | * get the balance for the wallet |
||
| 1293 | * |
||
| 1294 | * @param string $identifier the identifier of the wallet |
||
| 1295 | * @return array |
||
| 1296 | */ |
||
| 1297 | 9 | public function getWalletBalance($identifier) { |
|
| 1301 | |||
| 1302 | /** |
||
| 1303 | * do HD wallet discovery for the wallet |
||
| 1304 | * |
||
| 1305 | * this can be REALLY slow, so we've set the timeout to 120s ... |
||
| 1306 | * |
||
| 1307 | * @param string $identifier the identifier of the wallet |
||
| 1308 | * @param int $gap the gap setting to use for discovery |
||
| 1309 | * @return mixed |
||
| 1310 | */ |
||
| 1311 | 2 | public function doWalletDiscovery($identifier, $gap = 200) { |
|
| 1315 | |||
| 1316 | /** |
||
| 1317 | * get a new derivation number for specified parent path |
||
| 1318 | * 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 |
||
| 1319 | * |
||
| 1320 | * returns the path |
||
| 1321 | * |
||
| 1322 | * @param string $identifier the identifier of the wallet |
||
| 1323 | * @param string $path the parent path for which to get a new derivation |
||
| 1324 | * @return string |
||
| 1325 | */ |
||
| 1326 | 1 | public function getNewDerivation($identifier, $path) { |
|
| 1330 | |||
| 1331 | /** |
||
| 1332 | * get a new derivation number for specified parent path |
||
| 1333 | * 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 |
||
| 1334 | * |
||
| 1335 | * @param string $identifier the identifier of the wallet |
||
| 1336 | * @param string $path the parent path for which to get a new derivation |
||
| 1337 | * @return mixed |
||
| 1338 | */ |
||
| 1339 | 10 | public function _getNewDerivation($identifier, $path) { |
|
| 1343 | |||
| 1344 | /** |
||
| 1345 | * get the path (and redeemScript) to specified address |
||
| 1346 | * |
||
| 1347 | * @param string $identifier |
||
| 1348 | * @param string $address |
||
| 1349 | * @return array |
||
| 1350 | * @throws \Exception |
||
| 1351 | */ |
||
| 1352 | public function getPathForAddress($identifier, $address) { |
||
| 1356 | |||
| 1357 | /** |
||
| 1358 | * send the transaction using the API |
||
| 1359 | * |
||
| 1360 | * @param string $identifier the identifier of the wallet |
||
| 1361 | * @param string $rawTransaction raw hex of the transaction (should be partially signed) |
||
| 1362 | * @param array $paths list of the paths that were used for the UTXO |
||
| 1363 | * @param bool $checkFee let the server verify the fee after signing |
||
| 1364 | * @return string the complete raw transaction |
||
| 1365 | * @throws \Exception |
||
| 1366 | */ |
||
| 1367 | 2 | public function sendTransaction($identifier, $rawTransaction, $paths, $checkFee = false) { |
|
| 1386 | |||
| 1387 | /** |
||
| 1388 | * use the API to get the best inputs to use based on the outputs |
||
| 1389 | * |
||
| 1390 | * the return array has the following format: |
||
| 1391 | * [ |
||
| 1392 | * "utxos" => [ |
||
| 1393 | * [ |
||
| 1394 | * "hash" => "<txHash>", |
||
| 1395 | * "idx" => "<index of the output of that <txHash>", |
||
| 1396 | * "scriptpubkey_hex" => "<scriptPubKey-hex>", |
||
| 1397 | * "value" => 32746327, |
||
| 1398 | * "address" => "1address", |
||
| 1399 | * "path" => "m/44'/1'/0'/0/13", |
||
| 1400 | * "redeem_script" => "<redeemScript-hex>", |
||
| 1401 | * ], |
||
| 1402 | * ], |
||
| 1403 | * "fee" => 10000, |
||
| 1404 | * "change"=> 1010109201, |
||
| 1405 | * ] |
||
| 1406 | * |
||
| 1407 | * @param string $identifier the identifier of the wallet |
||
| 1408 | * @param array $outputs the outputs you want to create - array[address => satoshi-value] |
||
| 1409 | * @param bool $lockUTXO when TRUE the UTXOs selected will be locked for a few seconds |
||
| 1410 | * so you have some time to spend them without race-conditions |
||
| 1411 | * @param bool $allowZeroConf |
||
| 1412 | * @param string $feeStrategy |
||
| 1413 | * @param null|int $forceFee |
||
| 1414 | * @return array |
||
| 1415 | * @throws \Exception |
||
| 1416 | */ |
||
| 1417 | 8 | public function coinSelection($identifier, $outputs, $lockUTXO = false, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null) { |
|
| 1418 | $args = [ |
||
| 1419 | 8 | 'lock' => (int)!!$lockUTXO, |
|
| 1420 | 8 | 'zeroconf' => (int)!!$allowZeroConf, |
|
| 1421 | 8 | 'fee_strategy' => $feeStrategy, |
|
| 1422 | ]; |
||
| 1423 | |||
| 1424 | 8 | if ($forceFee !== null) { |
|
| 1425 | $args['forcefee'] = (int)$forceFee; |
||
| 1426 | } |
||
| 1427 | |||
| 1428 | 8 | $response = $this->client->post( |
|
| 1429 | 8 | "wallet/{$identifier}/coin-selection", |
|
| 1430 | 8 | $args, |
|
| 1431 | 8 | $outputs, |
|
| 1432 | 8 | RestClient::AUTH_HTTP_SIG |
|
| 1433 | ); |
||
| 1434 | |||
| 1435 | 2 | return self::jsonDecode($response->body(), true); |
|
| 1436 | } |
||
| 1437 | |||
| 1438 | /** |
||
| 1439 | * |
||
| 1440 | * @param string $identifier the identifier of the wallet |
||
| 1441 | * @param bool $allowZeroConf |
||
| 1442 | * @param string $feeStrategy |
||
| 1443 | * @param null|int $forceFee |
||
| 1444 | * @param int $outputCnt |
||
| 1445 | * @return array |
||
| 1446 | * @throws \Exception |
||
| 1447 | */ |
||
| 1448 | public function walletMaxSpendable($identifier, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null, $outputCnt = 1) { |
||
| 1467 | |||
| 1468 | /** |
||
| 1469 | * @return array ['optimal_fee' => 10000, 'low_priority_fee' => 5000] |
||
| 1470 | */ |
||
| 1471 | 1 | public function feePerKB() { |
|
| 1475 | |||
| 1476 | /** |
||
| 1477 | * get the current price index |
||
| 1478 | * |
||
| 1479 | * @return array eg; ['USD' => 287.30] |
||
| 1480 | */ |
||
| 1481 | 1 | public function price() { |
|
| 1485 | |||
| 1486 | /** |
||
| 1487 | * setup webhook for wallet |
||
| 1488 | * |
||
| 1489 | * @param string $identifier the wallet identifier for which to create the webhook |
||
| 1490 | * @param string $webhookIdentifier the webhook identifier to use |
||
| 1491 | * @param string $url the url to receive the webhook events |
||
| 1492 | * @return array |
||
| 1493 | */ |
||
| 1494 | 1 | public function setupWalletWebhook($identifier, $webhookIdentifier, $url) { |
|
| 1498 | |||
| 1499 | /** |
||
| 1500 | * delete webhook for wallet |
||
| 1501 | * |
||
| 1502 | * @param string $identifier the wallet identifier for which to delete the webhook |
||
| 1503 | * @param string $webhookIdentifier the webhook identifier to delete |
||
| 1504 | * @return array |
||
| 1505 | */ |
||
| 1506 | 1 | public function deleteWalletWebhook($identifier, $webhookIdentifier) { |
|
| 1510 | |||
| 1511 | /** |
||
| 1512 | * lock a specific unspent output |
||
| 1513 | * |
||
| 1514 | * @param $identifier |
||
| 1515 | * @param $txHash |
||
| 1516 | * @param $txIdx |
||
| 1517 | * @param int $ttl |
||
| 1518 | * @return bool |
||
| 1519 | */ |
||
| 1520 | public function lockWalletUTXO($identifier, $txHash, $txIdx, $ttl = 3) { |
||
| 1524 | |||
| 1525 | /** |
||
| 1526 | * unlock a specific unspent output |
||
| 1527 | * |
||
| 1528 | * @param $identifier |
||
| 1529 | * @param $txHash |
||
| 1530 | * @param $txIdx |
||
| 1531 | * @return bool |
||
| 1532 | */ |
||
| 1533 | public function unlockWalletUTXO($identifier, $txHash, $txIdx) { |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * get all transactions for wallet (paginated) |
||
| 1540 | * |
||
| 1541 | * @param string $identifier the wallet identifier for which to get transactions |
||
| 1542 | * @param integer $page pagination: page number |
||
| 1543 | * @param integer $limit pagination: records per page (max 500) |
||
| 1544 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1545 | * @return array associative array containing the response |
||
| 1546 | */ |
||
| 1547 | 1 | public function walletTransactions($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 1556 | |||
| 1557 | /** |
||
| 1558 | * get all addresses for wallet (paginated) |
||
| 1559 | * |
||
| 1560 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1561 | * @param integer $page pagination: page number |
||
| 1562 | * @param integer $limit pagination: records per page (max 500) |
||
| 1563 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1564 | * @return array associative array containing the response |
||
| 1565 | */ |
||
| 1566 | 1 | public function walletAddresses($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 1575 | |||
| 1576 | /** |
||
| 1577 | * get all UTXOs for wallet (paginated) |
||
| 1578 | * |
||
| 1579 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1580 | * @param integer $page pagination: page number |
||
| 1581 | * @param integer $limit pagination: records per page (max 500) |
||
| 1582 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1583 | * @param boolean $zeroconf include zero confirmation transactions |
||
| 1584 | * @return array associative array containing the response |
||
| 1585 | */ |
||
| 1586 | 1 | public function walletUTXOs($identifier, $page = 1, $limit = 20, $sortDir = 'asc', $zeroconf = true) { |
|
| 1596 | |||
| 1597 | /** |
||
| 1598 | * get a paginated list of all wallets associated with the api user |
||
| 1599 | * |
||
| 1600 | * @param integer $page pagination: page number |
||
| 1601 | * @param integer $limit pagination: records per page |
||
| 1602 | * @return array associative array containing the response |
||
| 1603 | */ |
||
| 1604 | 2 | public function allWallets($page = 1, $limit = 20) { |
|
| 1612 | |||
| 1613 | /** |
||
| 1614 | * send raw transaction |
||
| 1615 | * |
||
| 1616 | * @param $txHex |
||
| 1617 | * @return bool |
||
| 1618 | */ |
||
| 1619 | public function sendRawTransaction($txHex) { |
||
| 1623 | |||
| 1624 | /** |
||
| 1625 | * testnet only ;-) |
||
| 1626 | * |
||
| 1627 | * @param $address |
||
| 1628 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1629 | * @return mixed |
||
| 1630 | * @throws \Exception |
||
| 1631 | */ |
||
| 1632 | public function faucetWithdrawal($address, $amount = 10000) { |
||
| 1639 | |||
| 1640 | /** |
||
| 1641 | * Exists for BC. Remove at major bump. |
||
| 1642 | * |
||
| 1643 | * @see faucetWithdrawal |
||
| 1644 | * @deprecated |
||
| 1645 | * @param $address |
||
| 1646 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1647 | * @return mixed |
||
| 1648 | * @throws \Exception |
||
| 1649 | */ |
||
| 1650 | public function faucetWithdrawl($address, $amount = 10000) { |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * verify a message signed bitcoin-core style |
||
| 1656 | * |
||
| 1657 | * @param string $message |
||
| 1658 | * @param string $address |
||
| 1659 | * @param string $signature |
||
| 1660 | * @return boolean |
||
| 1661 | */ |
||
| 1662 | 1 | public function verifyMessage($message, $address, $signature) { |
|
| 1679 | |||
| 1680 | /** |
||
| 1681 | * convert a Satoshi value to a BTC value |
||
| 1682 | * |
||
| 1683 | * @param int $satoshi |
||
| 1684 | * @return float |
||
| 1685 | */ |
||
| 1686 | public static function toBTC($satoshi) { |
||
| 1689 | |||
| 1690 | /** |
||
| 1691 | * convert a Satoshi value to a BTC value and return it as a string |
||
| 1692 | |||
| 1693 | * @param int $satoshi |
||
| 1694 | * @return string |
||
| 1695 | */ |
||
| 1696 | public static function toBTCString($satoshi) { |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * convert a BTC value to a Satoshi value |
||
| 1702 | * |
||
| 1703 | * @param float $btc |
||
| 1704 | * @return string |
||
| 1705 | */ |
||
| 1706 | 9 | public static function toSatoshiString($btc) { |
|
| 1709 | |||
| 1710 | /** |
||
| 1711 | * convert a BTC value to a Satoshi value |
||
| 1712 | * |
||
| 1713 | * @param float $btc |
||
| 1714 | * @return string |
||
| 1715 | */ |
||
| 1716 | 9 | public static function toSatoshi($btc) { |
|
| 1719 | |||
| 1720 | /** |
||
| 1721 | * json_decode helper that throws exceptions when it fails to decode |
||
| 1722 | * |
||
| 1723 | * @param $json |
||
| 1724 | * @param bool $assoc |
||
| 1725 | * @return mixed |
||
| 1726 | * @throws \Exception |
||
| 1727 | */ |
||
| 1728 | 20 | protected static function jsonDecode($json, $assoc = false) { |
|
| 1741 | |||
| 1742 | /** |
||
| 1743 | * sort public keys for multisig script |
||
| 1744 | * |
||
| 1745 | * @param PublicKeyInterface[] $pubKeys |
||
| 1746 | * @return PublicKeyInterface[] |
||
| 1747 | */ |
||
| 1748 | 10 | public static function sortMultisigKeys(array $pubKeys) { |
|
| 1758 | |||
| 1759 | /** |
||
| 1760 | * read and decode the json payload from a webhook's POST request. |
||
| 1761 | * |
||
| 1762 | * @param bool $returnObject flag to indicate if an object or associative array should be returned |
||
| 1763 | * @return mixed|null |
||
| 1764 | * @throws \Exception |
||
| 1765 | */ |
||
| 1766 | public static function getWebhookPayload($returnObject = false) { |
||
| 1774 | |||
| 1775 | public static function normalizeBIP32KeyArray($keys) { |
||
| 1780 | |||
| 1781 | 14 | public static function normalizeBIP32Key($key) { |
|
| 1799 | } |
||
| 1800 |
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.