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 | * @var NetworkParams |
||
| 51 | */ |
||
| 52 | protected $networkParams; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param string $apiKey the API_KEY to use for authentication |
||
| 56 | * @param string $apiSecret the API_SECRET to use for authentication |
||
| 57 | * @param string $network the cryptocurrency 'network' to consume, eg BTC, LTC, etc |
||
| 58 | * @param bool $testnet testnet yes/no |
||
| 59 | * @param string $apiVersion the version of the API to consume |
||
| 60 | * @param null $apiEndpoint overwrite the endpoint used |
||
| 61 | * this will cause the $network, $testnet and $apiVersion to be ignored! |
||
| 62 | */ |
||
| 63 | 84 | public function __construct($apiKey, $apiSecret, $network = 'BTC', $testnet = false, $apiVersion = 'v1', $apiEndpoint = null) { |
|
| 78 | |||
| 79 | /** |
||
| 80 | * enable CURL debugging output |
||
| 81 | * |
||
| 82 | * @param bool $debug |
||
| 83 | * |
||
| 84 | * @codeCoverageIgnore |
||
| 85 | */ |
||
| 86 | public function setCurlDebugging($debug = true) { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * enable verbose errors |
||
| 92 | * |
||
| 93 | * @param bool $verboseErrors |
||
| 94 | * |
||
| 95 | * @codeCoverageIgnore |
||
| 96 | */ |
||
| 97 | public function setVerboseErrors($verboseErrors = true) { |
||
| 100 | |||
| 101 | /** |
||
| 102 | * set cURL default option on Guzzle client |
||
| 103 | * @param string $key |
||
| 104 | * @param bool $value |
||
| 105 | * |
||
| 106 | * @codeCoverageIgnore |
||
| 107 | */ |
||
| 108 | public function setCurlDefaultOption($key, $value) { |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @return RestClient |
||
| 114 | */ |
||
| 115 | 2 | public function getRestClient() { |
|
| 118 | |||
| 119 | /** |
||
| 120 | * @return NetworkParams |
||
| 121 | */ |
||
| 122 | 21 | public function getNetworkParams() { |
|
| 125 | |||
| 126 | /** |
||
| 127 | * get a single address |
||
| 128 | * @param string $address address hash |
||
| 129 | * @return array associative array containing the response |
||
| 130 | */ |
||
| 131 | 1 | public function address($address) { |
|
| 135 | |||
| 136 | /** |
||
| 137 | * get all transactions for an address (paginated) |
||
| 138 | * @param string $address address hash |
||
| 139 | * @param integer $page pagination: page number |
||
| 140 | * @param integer $limit pagination: records per page (max 500) |
||
| 141 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 142 | * @return array associative array containing the response |
||
| 143 | */ |
||
| 144 | 1 | public function addressTransactions($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 153 | |||
| 154 | /** |
||
| 155 | * get all unconfirmed transactions for an address (paginated) |
||
| 156 | * @param string $address address hash |
||
| 157 | * @param integer $page pagination: page number |
||
| 158 | * @param integer $limit pagination: records per page (max 500) |
||
| 159 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 160 | * @return array associative array containing the response |
||
| 161 | */ |
||
| 162 | 1 | public function addressUnconfirmedTransactions($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 171 | |||
| 172 | /** |
||
| 173 | * get all unspent outputs for an address (paginated) |
||
| 174 | * @param string $address address hash |
||
| 175 | * @param integer $page pagination: page number |
||
| 176 | * @param integer $limit pagination: records per page (max 500) |
||
| 177 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 178 | * @return array associative array containing the response |
||
| 179 | */ |
||
| 180 | 1 | public function addressUnspentOutputs($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 189 | |||
| 190 | /** |
||
| 191 | * get all unspent outputs for a batch of addresses (paginated) |
||
| 192 | * |
||
| 193 | * @param string[] $addresses |
||
| 194 | * @param integer $page pagination: page number |
||
| 195 | * @param integer $limit pagination: records per page (max 500) |
||
| 196 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 197 | * @return array associative array containing the response |
||
| 198 | * @throws \Exception |
||
| 199 | */ |
||
| 200 | public function batchAddressUnspentOutputs($addresses, $page = 1, $limit = 20, $sortDir = 'asc') { |
||
| 209 | |||
| 210 | /** |
||
| 211 | * verify ownership of an address |
||
| 212 | * @param string $address address hash |
||
| 213 | * @param string $signature a signed message (the address hash) using the private key of the address |
||
| 214 | * @return array associative array containing the response |
||
| 215 | */ |
||
| 216 | 2 | public function verifyAddress($address, $signature) { |
|
| 223 | |||
| 224 | /** |
||
| 225 | * get all blocks (paginated) |
||
| 226 | * @param integer $page pagination: page number |
||
| 227 | * @param integer $limit pagination: records per page |
||
| 228 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 229 | * @return array associative array containing the response |
||
| 230 | */ |
||
| 231 | 1 | public function allBlocks($page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 240 | |||
| 241 | /** |
||
| 242 | * get the latest block |
||
| 243 | * @return array associative array containing the response |
||
| 244 | */ |
||
| 245 | 1 | public function blockLatest() { |
|
| 249 | |||
| 250 | /** |
||
| 251 | * get an individual block |
||
| 252 | * @param string|integer $block a block hash or a block height |
||
| 253 | * @return array associative array containing the response |
||
| 254 | */ |
||
| 255 | 1 | public function block($block) { |
|
| 259 | |||
| 260 | /** |
||
| 261 | * get all transaction in a block (paginated) |
||
| 262 | * @param string|integer $block a block hash or a block height |
||
| 263 | * @param integer $page pagination: page number |
||
| 264 | * @param integer $limit pagination: records per page |
||
| 265 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 266 | * @return array associative array containing the response |
||
| 267 | */ |
||
| 268 | 1 | public function blockTransactions($block, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 277 | |||
| 278 | /** |
||
| 279 | * get a single transaction |
||
| 280 | * @param string $txhash transaction hash |
||
| 281 | * @return array associative array containing the response |
||
| 282 | */ |
||
| 283 | 5 | public function transaction($txhash) { |
|
| 287 | |||
| 288 | /** |
||
| 289 | * get a single transaction |
||
| 290 | * @param string[] $txhashes list of transaction hashes (up to 20) |
||
| 291 | * @return array[] array containing the response |
||
| 292 | */ |
||
| 293 | public function transactions($txhashes) { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * get a paginated list of all webhooks associated with the api user |
||
| 300 | * @param integer $page pagination: page number |
||
| 301 | * @param integer $limit pagination: records per page |
||
| 302 | * @return array associative array containing the response |
||
| 303 | */ |
||
| 304 | 1 | public function allWebhooks($page = 1, $limit = 20) { |
|
| 312 | |||
| 313 | /** |
||
| 314 | * get an existing webhook by it's identifier |
||
| 315 | * @param string $identifier a unique identifier associated with the webhook |
||
| 316 | * @return array associative array containing the response |
||
| 317 | */ |
||
| 318 | 1 | public function getWebhook($identifier) { |
|
| 322 | |||
| 323 | /** |
||
| 324 | * create a new webhook |
||
| 325 | * @param string $url the url to receive the webhook events |
||
| 326 | * @param string $identifier a unique identifier to associate with this webhook |
||
| 327 | * @return array associative array containing the response |
||
| 328 | */ |
||
| 329 | 1 | public function setupWebhook($url, $identifier = null) { |
|
| 337 | |||
| 338 | /** |
||
| 339 | * update an existing webhook |
||
| 340 | * @param string $identifier the unique identifier of the webhook to update |
||
| 341 | * @param string $newUrl the new url to receive the webhook events |
||
| 342 | * @param string $newIdentifier a new unique identifier to associate with this webhook |
||
| 343 | * @return array associative array containing the response |
||
| 344 | */ |
||
| 345 | 1 | public function updateWebhook($identifier, $newUrl = null, $newIdentifier = null) { |
|
| 353 | |||
| 354 | /** |
||
| 355 | * deletes an existing webhook and any event subscriptions associated with it |
||
| 356 | * @param string $identifier the unique identifier of the webhook to delete |
||
| 357 | * @return boolean true on success |
||
| 358 | */ |
||
| 359 | 1 | public function deleteWebhook($identifier) { |
|
| 363 | |||
| 364 | /** |
||
| 365 | * get a paginated list of all the events a webhook is subscribed to |
||
| 366 | * @param string $identifier the unique identifier of the webhook |
||
| 367 | * @param integer $page pagination: page number |
||
| 368 | * @param integer $limit pagination: records per page |
||
| 369 | * @return array associative array containing the response |
||
| 370 | */ |
||
| 371 | 2 | public function getWebhookEvents($identifier, $page = 1, $limit = 20) { |
|
| 379 | |||
| 380 | /** |
||
| 381 | * subscribes a webhook to transaction events of one particular transaction |
||
| 382 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 383 | * @param string $transaction the transaction hash |
||
| 384 | * @param integer $confirmations the amount of confirmations to send. |
||
| 385 | * @return array associative array containing the response |
||
| 386 | */ |
||
| 387 | 1 | public function subscribeTransaction($identifier, $transaction, $confirmations = 6) { |
|
| 396 | |||
| 397 | /** |
||
| 398 | * subscribes a webhook to transaction events on a particular address |
||
| 399 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 400 | * @param string $address the address hash |
||
| 401 | * @param integer $confirmations the amount of confirmations to send. |
||
| 402 | * @return array associative array containing the response |
||
| 403 | */ |
||
| 404 | 1 | public function subscribeAddressTransactions($identifier, $address, $confirmations = 6) { |
|
| 413 | |||
| 414 | /** |
||
| 415 | * batch subscribes a webhook to multiple transaction events |
||
| 416 | * |
||
| 417 | * @param string $identifier the unique identifier of the webhook |
||
| 418 | * @param array $batchData A 2D array of event data: |
||
| 419 | * [address => $address, confirmations => $confirmations] |
||
| 420 | * where $address is the address to subscibe to |
||
| 421 | * and optionally $confirmations is the amount of confirmations |
||
| 422 | * @return boolean true on success |
||
| 423 | */ |
||
| 424 | 1 | public function batchSubscribeAddressTransactions($identifier, $batchData) { |
|
| 436 | |||
| 437 | /** |
||
| 438 | * subscribes a webhook to a new block event |
||
| 439 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 440 | * @return array associative array containing the response |
||
| 441 | */ |
||
| 442 | 1 | public function subscribeNewBlocks($identifier) { |
|
| 449 | |||
| 450 | /** |
||
| 451 | * removes an transaction event subscription from a webhook |
||
| 452 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 453 | * @param string $transaction the transaction hash of the event subscription |
||
| 454 | * @return boolean true on success |
||
| 455 | */ |
||
| 456 | 1 | public function unsubscribeTransaction($identifier, $transaction) { |
|
| 460 | |||
| 461 | /** |
||
| 462 | * removes an address transaction event subscription from a webhook |
||
| 463 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 464 | * @param string $address the address hash of the event subscription |
||
| 465 | * @return boolean true on success |
||
| 466 | */ |
||
| 467 | 1 | public function unsubscribeAddressTransactions($identifier, $address) { |
|
| 471 | |||
| 472 | /** |
||
| 473 | * removes a block event subscription from a webhook |
||
| 474 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 475 | * @return boolean true on success |
||
| 476 | */ |
||
| 477 | 1 | public function unsubscribeNewBlocks($identifier) { |
|
| 481 | |||
| 482 | /** |
||
| 483 | * create a new wallet |
||
| 484 | * - will generate a new primary seed (with password) and backup seed (without password) |
||
| 485 | * - send the primary seed (BIP39 'encrypted') and backup public key to the server |
||
| 486 | * - receive the blocktrail co-signing public key from the server |
||
| 487 | * |
||
| 488 | * Either takes one argument: |
||
| 489 | * @param array $options |
||
| 490 | * |
||
| 491 | * Or takes three arguments (old, deprecated syntax): |
||
| 492 | * (@nonPHP-doc) @param $identifier |
||
| 493 | * (@nonPHP-doc) @param $password |
||
| 494 | * (@nonPHP-doc) @param int $keyIndex override for the blocktrail cosigning key to use |
||
|
|
|||
| 495 | * |
||
| 496 | * @return array[WalletInterface, array] list($wallet, $backupInfo) |
||
| 497 | * @throws \Exception |
||
| 498 | */ |
||
| 499 | 7 | public function createNewWallet($options) { |
|
| 543 | |||
| 544 | 7 | private function formatBlocktrailKeys(NetworkInterface $network, array $blocktrailPublicKeys) { |
|
| 549 | |||
| 550 | 1 | protected function createNewWalletV1($options) { |
|
| 657 | |||
| 658 | 5 | public static function randomBits($bits) { |
|
| 661 | |||
| 662 | 5 | public static function randomBytes($bytes) { |
|
| 665 | |||
| 666 | 2 | protected function createNewWalletV2($options) { |
|
| 783 | |||
| 784 | 4 | protected function createNewWalletV3($options) { |
|
| 919 | |||
| 920 | /** |
||
| 921 | * @param array $bip32Key |
||
| 922 | * @throws BlocktrailSDKException |
||
| 923 | */ |
||
| 924 | 10 | private function verifyPublicBIP32Key(array $bip32Key) { |
|
| 934 | |||
| 935 | /** |
||
| 936 | * @param array $walletData |
||
| 937 | * @throws BlocktrailSDKException |
||
| 938 | */ |
||
| 939 | 10 | private function verifyPublicOnly(array $walletData) { |
|
| 943 | |||
| 944 | /** |
||
| 945 | * create wallet using the API |
||
| 946 | * |
||
| 947 | * @param string $identifier the wallet identifier to create |
||
| 948 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 949 | * @param string $backupPublicKey plain public key |
||
| 950 | * @param string $primaryMnemonic mnemonic to store |
||
| 951 | * @param string $checksum checksum to store |
||
| 952 | * @param int $keyIndex account that we expect to use |
||
| 953 | * @return mixed |
||
| 954 | */ |
||
| 955 | 1 | public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, $keyIndex) { |
|
| 968 | |||
| 969 | /** |
||
| 970 | * create wallet using the API |
||
| 971 | * |
||
| 972 | * @param string $identifier the wallet identifier to create |
||
| 973 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 974 | * @param string $backupPublicKey plain public key |
||
| 975 | * @param $encryptedPrimarySeed |
||
| 976 | * @param $encryptedSecret |
||
| 977 | * @param $recoverySecret |
||
| 978 | * @param string $checksum checksum to store |
||
| 979 | * @param int $keyIndex account that we expect to use |
||
| 980 | * @return mixed |
||
| 981 | * @throws \Exception |
||
| 982 | */ |
||
| 983 | 5 | public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 999 | |||
| 1000 | /** |
||
| 1001 | * create wallet using the API |
||
| 1002 | * |
||
| 1003 | * @param string $identifier the wallet identifier to create |
||
| 1004 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1005 | * @param string $backupPublicKey plain public key |
||
| 1006 | * @param $encryptedPrimarySeed |
||
| 1007 | * @param $encryptedSecret |
||
| 1008 | * @param $recoverySecret |
||
| 1009 | * @param string $checksum checksum to store |
||
| 1010 | * @param int $keyIndex account that we expect to use |
||
| 1011 | * @return mixed |
||
| 1012 | * @throws \Exception |
||
| 1013 | */ |
||
| 1014 | 4 | public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1032 | |||
| 1033 | /** |
||
| 1034 | * upgrade wallet to use a new account number |
||
| 1035 | * the account number specifies which blocktrail cosigning key is used |
||
| 1036 | * |
||
| 1037 | * @param string $identifier the wallet identifier to be upgraded |
||
| 1038 | * @param int $keyIndex the new account to use |
||
| 1039 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1040 | * @return mixed |
||
| 1041 | */ |
||
| 1042 | 5 | public function upgradeKeyIndex($identifier, $keyIndex, $primaryPublicKey) { |
|
| 1051 | |||
| 1052 | /** |
||
| 1053 | * initialize a previously created wallet |
||
| 1054 | * |
||
| 1055 | * Takes an options object, or accepts identifier/password for backwards compatiblity. |
||
| 1056 | * |
||
| 1057 | * Some of the options: |
||
| 1058 | * - "readonly/readOnly/read-only" can be to a boolean value, |
||
| 1059 | * so the wallet is loaded in read-only mode (no private key) |
||
| 1060 | * - "check_backup_key" can be set to your own backup key: |
||
| 1061 | * Format: ["M', "xpub..."] |
||
| 1062 | * Setting this will allow the SDK to check the server hasn't |
||
| 1063 | * a different key (one it happens to control) |
||
| 1064 | |||
| 1065 | * Either takes one argument: |
||
| 1066 | * @param array $options |
||
| 1067 | * |
||
| 1068 | * Or takes two arguments (old, deprecated syntax): |
||
| 1069 | * (@nonPHP-doc) @param string $identifier the wallet identifier to be initialized |
||
| 1070 | * (@nonPHP-doc) @param string $password the password to decrypt the mnemonic with |
||
| 1071 | * |
||
| 1072 | * @return WalletInterface |
||
| 1073 | * @throws \Exception |
||
| 1074 | */ |
||
| 1075 | 18 | public function initWallet($options) { |
|
| 1176 | |||
| 1177 | /** |
||
| 1178 | * get the wallet data from the server |
||
| 1179 | * |
||
| 1180 | * @param string $identifier the identifier of the wallet |
||
| 1181 | * @return mixed |
||
| 1182 | */ |
||
| 1183 | 18 | public function getWallet($identifier) { |
|
| 1187 | |||
| 1188 | /** |
||
| 1189 | * update the wallet data on the server |
||
| 1190 | * |
||
| 1191 | * @param string $identifier |
||
| 1192 | * @param $data |
||
| 1193 | * @return mixed |
||
| 1194 | */ |
||
| 1195 | 3 | public function updateWallet($identifier, $data) { |
|
| 1199 | |||
| 1200 | /** |
||
| 1201 | * delete a wallet from the server |
||
| 1202 | * the checksum address and a signature to verify you ownership of the key of that checksum address |
||
| 1203 | * is required to be able to delete a wallet |
||
| 1204 | * |
||
| 1205 | * @param string $identifier the identifier of the wallet |
||
| 1206 | * @param string $checksumAddress the address for your master private key (and the checksum used when creating the wallet) |
||
| 1207 | * @param string $signature a signature of the checksum address as message signed by the private key matching that address |
||
| 1208 | * @param bool $force ignore warnings (such as a non-zero balance) |
||
| 1209 | * @return mixed |
||
| 1210 | */ |
||
| 1211 | 10 | public function deleteWallet($identifier, $checksumAddress, $signature, $force = false) { |
|
| 1218 | |||
| 1219 | /** |
||
| 1220 | * create new backup key; |
||
| 1221 | * 1) a BIP39 mnemonic |
||
| 1222 | * 2) a seed from that mnemonic with a blank password |
||
| 1223 | * 3) a private key from that seed |
||
| 1224 | * |
||
| 1225 | * @return array [mnemonic, seed, key] |
||
| 1226 | */ |
||
| 1227 | 1 | protected function newBackupSeed() { |
|
| 1232 | |||
| 1233 | /** |
||
| 1234 | * create new primary key; |
||
| 1235 | * 1) a BIP39 mnemonic |
||
| 1236 | * 2) a seed from that mnemonic with the password |
||
| 1237 | * 3) a private key from that seed |
||
| 1238 | * |
||
| 1239 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1240 | * @return array [mnemonic, seed, key] |
||
| 1241 | * @TODO: require a strong password? |
||
| 1242 | */ |
||
| 1243 | 1 | protected function newPrimarySeed($passphrase) { |
|
| 1248 | |||
| 1249 | /** |
||
| 1250 | * create a new key; |
||
| 1251 | * 1) a BIP39 mnemonic |
||
| 1252 | * 2) a seed from that mnemonic with the password |
||
| 1253 | * 3) a private key from that seed |
||
| 1254 | * |
||
| 1255 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1256 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1257 | * @return array |
||
| 1258 | */ |
||
| 1259 | 1 | protected function generateNewSeed($passphrase = "", $forceEntropy = null) { |
|
| 1276 | |||
| 1277 | /** |
||
| 1278 | * generate a new mnemonic from some random entropy (512 bit) |
||
| 1279 | * |
||
| 1280 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1281 | * @return string |
||
| 1282 | * @throws \Exception |
||
| 1283 | */ |
||
| 1284 | 1 | protected function generateNewMnemonic($forceEntropy = null) { |
|
| 1294 | |||
| 1295 | /** |
||
| 1296 | * get the balance for the wallet |
||
| 1297 | * |
||
| 1298 | * @param string $identifier the identifier of the wallet |
||
| 1299 | * @return array |
||
| 1300 | */ |
||
| 1301 | 9 | public function getWalletBalance($identifier) { |
|
| 1305 | |||
| 1306 | /** |
||
| 1307 | * do HD wallet discovery for the wallet |
||
| 1308 | * |
||
| 1309 | * this can be REALLY slow, so we've set the timeout to 120s ... |
||
| 1310 | * |
||
| 1311 | * @param string $identifier the identifier of the wallet |
||
| 1312 | * @param int $gap the gap setting to use for discovery |
||
| 1313 | * @return mixed |
||
| 1314 | */ |
||
| 1315 | 2 | public function doWalletDiscovery($identifier, $gap = 200) { |
|
| 1319 | |||
| 1320 | /** |
||
| 1321 | * get a new derivation number for specified parent path |
||
| 1322 | * 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 |
||
| 1323 | * |
||
| 1324 | * returns the path |
||
| 1325 | * |
||
| 1326 | * @param string $identifier the identifier of the wallet |
||
| 1327 | * @param string $path the parent path for which to get a new derivation |
||
| 1328 | * @return string |
||
| 1329 | */ |
||
| 1330 | 1 | public function getNewDerivation($identifier, $path) { |
|
| 1334 | |||
| 1335 | /** |
||
| 1336 | * get a new derivation number for specified parent path |
||
| 1337 | * 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 |
||
| 1338 | * |
||
| 1339 | * @param string $identifier the identifier of the wallet |
||
| 1340 | * @param string $path the parent path for which to get a new derivation |
||
| 1341 | * @return mixed |
||
| 1342 | */ |
||
| 1343 | 14 | public function _getNewDerivation($identifier, $path) { |
|
| 1347 | |||
| 1348 | /** |
||
| 1349 | * get the path (and redeemScript) to specified address |
||
| 1350 | * |
||
| 1351 | * @param string $identifier |
||
| 1352 | * @param string $address |
||
| 1353 | * @return array |
||
| 1354 | * @throws \Exception |
||
| 1355 | */ |
||
| 1356 | 1 | public function getPathForAddress($identifier, $address) { |
|
| 1360 | |||
| 1361 | /** |
||
| 1362 | * send the transaction using the API |
||
| 1363 | * |
||
| 1364 | * @param string $identifier the identifier of the wallet |
||
| 1365 | * @param string|array $rawTransaction raw hex of the transaction (should be partially signed) |
||
| 1366 | * @param array $paths list of the paths that were used for the UTXO |
||
| 1367 | * @param bool $checkFee let the server verify the fee after signing |
||
| 1368 | * @return string the complete raw transaction |
||
| 1369 | * @throws \Exception |
||
| 1370 | */ |
||
| 1371 | 4 | public function sendTransaction($identifier, $rawTransaction, $paths, $checkFee = false) { |
|
| 1401 | |||
| 1402 | /** |
||
| 1403 | * use the API to get the best inputs to use based on the outputs |
||
| 1404 | * |
||
| 1405 | * the return array has the following format: |
||
| 1406 | * [ |
||
| 1407 | * "utxos" => [ |
||
| 1408 | * [ |
||
| 1409 | * "hash" => "<txHash>", |
||
| 1410 | * "idx" => "<index of the output of that <txHash>", |
||
| 1411 | * "scriptpubkey_hex" => "<scriptPubKey-hex>", |
||
| 1412 | * "value" => 32746327, |
||
| 1413 | * "address" => "1address", |
||
| 1414 | * "path" => "m/44'/1'/0'/0/13", |
||
| 1415 | * "redeem_script" => "<redeemScript-hex>", |
||
| 1416 | * ], |
||
| 1417 | * ], |
||
| 1418 | * "fee" => 10000, |
||
| 1419 | * "change"=> 1010109201, |
||
| 1420 | * ] |
||
| 1421 | * |
||
| 1422 | * @param string $identifier the identifier of the wallet |
||
| 1423 | * @param array $outputs the outputs you want to create - array[address => satoshi-value] |
||
| 1424 | * @param bool $lockUTXO when TRUE the UTXOs selected will be locked for a few seconds |
||
| 1425 | * so you have some time to spend them without race-conditions |
||
| 1426 | * @param bool $allowZeroConf |
||
| 1427 | * @param string $feeStrategy |
||
| 1428 | * @param null|int $forceFee |
||
| 1429 | * @return array |
||
| 1430 | * @throws \Exception |
||
| 1431 | */ |
||
| 1432 | 11 | public function coinSelection($identifier, $outputs, $lockUTXO = false, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null) { |
|
| 1452 | |||
| 1453 | /** |
||
| 1454 | * |
||
| 1455 | * @param string $identifier the identifier of the wallet |
||
| 1456 | * @param bool $allowZeroConf |
||
| 1457 | * @param string $feeStrategy |
||
| 1458 | * @param null|int $forceFee |
||
| 1459 | * @param int $outputCnt |
||
| 1460 | * @return array |
||
| 1461 | * @throws \Exception |
||
| 1462 | */ |
||
| 1463 | public function walletMaxSpendable($identifier, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null, $outputCnt = 1) { |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * @return array ['optimal_fee' => 10000, 'low_priority_fee' => 5000] |
||
| 1485 | */ |
||
| 1486 | 3 | public function feePerKB() { |
|
| 1490 | |||
| 1491 | /** |
||
| 1492 | * get the current price index |
||
| 1493 | * |
||
| 1494 | * @return array eg; ['USD' => 287.30] |
||
| 1495 | */ |
||
| 1496 | 1 | public function price() { |
|
| 1500 | |||
| 1501 | /** |
||
| 1502 | * setup webhook for wallet |
||
| 1503 | * |
||
| 1504 | * @param string $identifier the wallet identifier for which to create the webhook |
||
| 1505 | * @param string $webhookIdentifier the webhook identifier to use |
||
| 1506 | * @param string $url the url to receive the webhook events |
||
| 1507 | * @return array |
||
| 1508 | */ |
||
| 1509 | 1 | public function setupWalletWebhook($identifier, $webhookIdentifier, $url) { |
|
| 1513 | |||
| 1514 | /** |
||
| 1515 | * delete webhook for wallet |
||
| 1516 | * |
||
| 1517 | * @param string $identifier the wallet identifier for which to delete the webhook |
||
| 1518 | * @param string $webhookIdentifier the webhook identifier to delete |
||
| 1519 | * @return array |
||
| 1520 | */ |
||
| 1521 | 1 | public function deleteWalletWebhook($identifier, $webhookIdentifier) { |
|
| 1525 | |||
| 1526 | /** |
||
| 1527 | * lock a specific unspent output |
||
| 1528 | * |
||
| 1529 | * @param $identifier |
||
| 1530 | * @param $txHash |
||
| 1531 | * @param $txIdx |
||
| 1532 | * @param int $ttl |
||
| 1533 | * @return bool |
||
| 1534 | */ |
||
| 1535 | public function lockWalletUTXO($identifier, $txHash, $txIdx, $ttl = 3) { |
||
| 1539 | |||
| 1540 | /** |
||
| 1541 | * unlock a specific unspent output |
||
| 1542 | * |
||
| 1543 | * @param $identifier |
||
| 1544 | * @param $txHash |
||
| 1545 | * @param $txIdx |
||
| 1546 | * @return bool |
||
| 1547 | */ |
||
| 1548 | public function unlockWalletUTXO($identifier, $txHash, $txIdx) { |
||
| 1552 | |||
| 1553 | /** |
||
| 1554 | * get all transactions for wallet (paginated) |
||
| 1555 | * |
||
| 1556 | * @param string $identifier the wallet identifier for which to get transactions |
||
| 1557 | * @param integer $page pagination: page number |
||
| 1558 | * @param integer $limit pagination: records per page (max 500) |
||
| 1559 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1560 | * @return array associative array containing the response |
||
| 1561 | */ |
||
| 1562 | 1 | public function walletTransactions($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 1571 | |||
| 1572 | /** |
||
| 1573 | * get all addresses for wallet (paginated) |
||
| 1574 | * |
||
| 1575 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1576 | * @param integer $page pagination: page number |
||
| 1577 | * @param integer $limit pagination: records per page (max 500) |
||
| 1578 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1579 | * @return array associative array containing the response |
||
| 1580 | */ |
||
| 1581 | 1 | public function walletAddresses($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 1590 | |||
| 1591 | /** |
||
| 1592 | * get all UTXOs for wallet (paginated) |
||
| 1593 | * |
||
| 1594 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1595 | * @param integer $page pagination: page number |
||
| 1596 | * @param integer $limit pagination: records per page (max 500) |
||
| 1597 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1598 | * @param boolean $zeroconf include zero confirmation transactions |
||
| 1599 | * @return array associative array containing the response |
||
| 1600 | */ |
||
| 1601 | 1 | public function walletUTXOs($identifier, $page = 1, $limit = 20, $sortDir = 'asc', $zeroconf = true) { |
|
| 1611 | |||
| 1612 | /** |
||
| 1613 | * get a paginated list of all wallets associated with the api user |
||
| 1614 | * |
||
| 1615 | * @param integer $page pagination: page number |
||
| 1616 | * @param integer $limit pagination: records per page |
||
| 1617 | * @return array associative array containing the response |
||
| 1618 | */ |
||
| 1619 | 2 | public function allWallets($page = 1, $limit = 20) { |
|
| 1627 | |||
| 1628 | /** |
||
| 1629 | * send raw transaction |
||
| 1630 | * |
||
| 1631 | * @param $txHex |
||
| 1632 | * @return bool |
||
| 1633 | */ |
||
| 1634 | public function sendRawTransaction($txHex) { |
||
| 1638 | |||
| 1639 | /** |
||
| 1640 | * testnet only ;-) |
||
| 1641 | * |
||
| 1642 | * @param $address |
||
| 1643 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1644 | * @return mixed |
||
| 1645 | * @throws \Exception |
||
| 1646 | */ |
||
| 1647 | public function faucetWithdrawal($address, $amount = 10000) { |
||
| 1654 | |||
| 1655 | /** |
||
| 1656 | * Exists for BC. Remove at major bump. |
||
| 1657 | * |
||
| 1658 | * @see faucetWithdrawal |
||
| 1659 | * @deprecated |
||
| 1660 | * @param $address |
||
| 1661 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1662 | * @return mixed |
||
| 1663 | * @throws \Exception |
||
| 1664 | */ |
||
| 1665 | public function faucetWithdrawl($address, $amount = 10000) { |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | * verify a message signed bitcoin-core style |
||
| 1671 | * |
||
| 1672 | * @param string $message |
||
| 1673 | * @param string $address |
||
| 1674 | * @param string $signature |
||
| 1675 | * @return boolean |
||
| 1676 | */ |
||
| 1677 | 1 | public function verifyMessage($message, $address, $signature) { |
|
| 1694 | |||
| 1695 | /** |
||
| 1696 | * convert a Satoshi value to a BTC value |
||
| 1697 | * |
||
| 1698 | * @param int $satoshi |
||
| 1699 | * @return float |
||
| 1700 | */ |
||
| 1701 | public static function toBTC($satoshi) { |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * convert a Satoshi value to a BTC value and return it as a string |
||
| 1707 | |||
| 1708 | * @param int $satoshi |
||
| 1709 | * @return string |
||
| 1710 | */ |
||
| 1711 | public static function toBTCString($satoshi) { |
||
| 1714 | |||
| 1715 | /** |
||
| 1716 | * convert a BTC value to a Satoshi value |
||
| 1717 | * |
||
| 1718 | * @param float $btc |
||
| 1719 | * @return string |
||
| 1720 | */ |
||
| 1721 | 12 | public static function toSatoshiString($btc) { |
|
| 1724 | |||
| 1725 | /** |
||
| 1726 | * convert a BTC value to a Satoshi value |
||
| 1727 | * |
||
| 1728 | * @param float $btc |
||
| 1729 | * @return string |
||
| 1730 | */ |
||
| 1731 | 12 | public static function toSatoshi($btc) { |
|
| 1734 | |||
| 1735 | /** |
||
| 1736 | * json_decode helper that throws exceptions when it fails to decode |
||
| 1737 | * |
||
| 1738 | * @param $json |
||
| 1739 | * @param bool $assoc |
||
| 1740 | * @return mixed |
||
| 1741 | * @throws \Exception |
||
| 1742 | */ |
||
| 1743 | 27 | protected static function jsonDecode($json, $assoc = false) { |
|
| 1756 | |||
| 1757 | /** |
||
| 1758 | * sort public keys for multisig script |
||
| 1759 | * |
||
| 1760 | * @param PublicKeyInterface[] $pubKeys |
||
| 1761 | * @return PublicKeyInterface[] |
||
| 1762 | */ |
||
| 1763 | 16 | public static function sortMultisigKeys(array $pubKeys) { |
|
| 1773 | |||
| 1774 | /** |
||
| 1775 | * read and decode the json payload from a webhook's POST request. |
||
| 1776 | * |
||
| 1777 | * @param bool $returnObject flag to indicate if an object or associative array should be returned |
||
| 1778 | * @return mixed|null |
||
| 1779 | * @throws \Exception |
||
| 1780 | */ |
||
| 1781 | public static function getWebhookPayload($returnObject = false) { |
||
| 1789 | |||
| 1790 | public static function normalizeBIP32KeyArray($keys, NetworkInterface $network) { |
||
| 1795 | |||
| 1796 | /** |
||
| 1797 | * @param BIP32Key|array $key |
||
| 1798 | * @param NetworkInterface $network |
||
| 1799 | * @return BIP32Key |
||
| 1800 | * @throws \Exception |
||
| 1801 | */ |
||
| 1802 | 21 | public static function normalizeBIP32Key($key, NetworkInterface $network) { |
|
| 1820 | } |
||
| 1821 |
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.