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 |
||
| 34 | class BlocktrailSDK implements BlocktrailSDKInterface { |
||
| 35 | /** |
||
| 36 | * @var Connection\RestClient |
||
| 37 | */ |
||
| 38 | protected $client; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string currently only supporting; bitcoin |
||
| 42 | */ |
||
| 43 | protected $network; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var bool |
||
| 47 | */ |
||
| 48 | protected $testnet; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var NetworkInterface |
||
| 52 | */ |
||
| 53 | protected $networkParams; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $apiKey the API_KEY to use for authentication |
||
| 57 | * @param string $apiSecret the API_SECRET to use for authentication |
||
| 58 | * @param string $network the cryptocurrency 'network' to consume, eg BTC, LTC, etc |
||
| 59 | * @param bool $testnet testnet yes/no |
||
| 60 | * @param string $apiVersion the version of the API to consume |
||
| 61 | * @param null $apiEndpoint overwrite the endpoint used |
||
| 62 | * this will cause the $network, $testnet and $apiVersion to be ignored! |
||
| 63 | */ |
||
| 64 | 81 | public function __construct($apiKey, $apiSecret, $network = 'BTC', $testnet = false, $apiVersion = 'v1', $apiEndpoint = null) { |
|
| 79 | |||
| 80 | /** |
||
| 81 | * normalize network string |
||
| 82 | * |
||
| 83 | * @param string $network |
||
| 84 | * @param bool $testnet |
||
| 85 | * @return array |
||
| 86 | * @throws \Exception |
||
| 87 | */ |
||
| 88 | 81 | protected function normalizeNetwork($network, $testnet) { |
|
| 91 | |||
| 92 | /** |
||
| 93 | * set BitcoinLib to the correct magic-byte defaults for the selected network |
||
| 94 | * |
||
| 95 | * @param $network |
||
| 96 | * @param $testnet |
||
| 97 | */ |
||
| 98 | 81 | protected function setBitcoinLibMagicBytes($network, $testnet) { |
|
| 102 | |||
| 103 | /** |
||
| 104 | * enable CURL debugging output |
||
| 105 | * |
||
| 106 | * @param bool $debug |
||
| 107 | * |
||
| 108 | * @codeCoverageIgnore |
||
| 109 | */ |
||
| 110 | public function setCurlDebugging($debug = true) { |
||
| 113 | |||
| 114 | /** |
||
| 115 | * enable verbose errors |
||
| 116 | * |
||
| 117 | * @param bool $verboseErrors |
||
| 118 | * |
||
| 119 | * @codeCoverageIgnore |
||
| 120 | */ |
||
| 121 | public function setVerboseErrors($verboseErrors = true) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * set cURL default option on Guzzle client |
||
| 127 | * @param string $key |
||
| 128 | * @param bool $value |
||
| 129 | * |
||
| 130 | * @codeCoverageIgnore |
||
| 131 | */ |
||
| 132 | public function setCurlDefaultOption($key, $value) { |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return RestClient |
||
| 138 | */ |
||
| 139 | 2 | public function getRestClient() { |
|
| 142 | |||
| 143 | /** |
||
| 144 | * get a single address |
||
| 145 | * @param string $address address hash |
||
| 146 | * @return array associative array containing the response |
||
| 147 | */ |
||
| 148 | 1 | public function address($address) { |
|
| 152 | |||
| 153 | /** |
||
| 154 | * get all transactions for an address (paginated) |
||
| 155 | * @param string $address address hash |
||
| 156 | * @param integer $page pagination: page number |
||
| 157 | * @param integer $limit pagination: records per page (max 500) |
||
| 158 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 159 | * @return array associative array containing the response |
||
| 160 | */ |
||
| 161 | 1 | public function addressTransactions($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 170 | |||
| 171 | /** |
||
| 172 | * get all unconfirmed transactions for an address (paginated) |
||
| 173 | * @param string $address address hash |
||
| 174 | * @param integer $page pagination: page number |
||
| 175 | * @param integer $limit pagination: records per page (max 500) |
||
| 176 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 177 | * @return array associative array containing the response |
||
| 178 | */ |
||
| 179 | 1 | public function addressUnconfirmedTransactions($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 188 | |||
| 189 | /** |
||
| 190 | * get all unspent outputs for an address (paginated) |
||
| 191 | * @param string $address address hash |
||
| 192 | * @param integer $page pagination: page number |
||
| 193 | * @param integer $limit pagination: records per page (max 500) |
||
| 194 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 195 | * @return array associative array containing the response |
||
| 196 | */ |
||
| 197 | 1 | public function addressUnspentOutputs($address, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 206 | |||
| 207 | /** |
||
| 208 | * get all unspent outputs for a batch of addresses (paginated) |
||
| 209 | * |
||
| 210 | * @param string[] $addresses |
||
| 211 | * @param integer $page pagination: page number |
||
| 212 | * @param integer $limit pagination: records per page (max 500) |
||
| 213 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 214 | * @return array associative array containing the response |
||
| 215 | * @throws \Exception |
||
| 216 | */ |
||
| 217 | public function batchAddressUnspentOutputs($addresses, $page = 1, $limit = 20, $sortDir = 'asc') { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * verify ownership of an address |
||
| 229 | * @param string $address address hash |
||
| 230 | * @param string $signature a signed message (the address hash) using the private key of the address |
||
| 231 | * @return array associative array containing the response |
||
| 232 | */ |
||
| 233 | 2 | public function verifyAddress($address, $signature) { |
|
| 240 | |||
| 241 | /** |
||
| 242 | * get all blocks (paginated) |
||
| 243 | * @param integer $page pagination: page number |
||
| 244 | * @param integer $limit pagination: records per page |
||
| 245 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 246 | * @return array associative array containing the response |
||
| 247 | */ |
||
| 248 | 1 | public function allBlocks($page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 257 | |||
| 258 | /** |
||
| 259 | * get the latest block |
||
| 260 | * @return array associative array containing the response |
||
| 261 | */ |
||
| 262 | 1 | public function blockLatest() { |
|
| 266 | |||
| 267 | /** |
||
| 268 | * get an individual block |
||
| 269 | * @param string|integer $block a block hash or a block height |
||
| 270 | * @return array associative array containing the response |
||
| 271 | */ |
||
| 272 | 1 | public function block($block) { |
|
| 276 | |||
| 277 | /** |
||
| 278 | * get all transaction in a block (paginated) |
||
| 279 | * @param string|integer $block a block hash or a block height |
||
| 280 | * @param integer $page pagination: page number |
||
| 281 | * @param integer $limit pagination: records per page |
||
| 282 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 283 | * @return array associative array containing the response |
||
| 284 | */ |
||
| 285 | 1 | public function blockTransactions($block, $page = 1, $limit = 20, $sortDir = 'asc') { |
|
| 294 | |||
| 295 | /** |
||
| 296 | * get a single transaction |
||
| 297 | * @param string $txhash transaction hash |
||
| 298 | * @return array associative array containing the response |
||
| 299 | */ |
||
| 300 | 1 | public function transaction($txhash) { |
|
| 304 | |||
| 305 | /** |
||
| 306 | * get a single transaction |
||
| 307 | * @param string[] $txhashes list of transaction hashes (up to 20) |
||
| 308 | * @return array[] array containing the response |
||
| 309 | */ |
||
| 310 | public function transactions($txhashes) { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * get a paginated list of all webhooks associated with the api user |
||
| 317 | * @param integer $page pagination: page number |
||
| 318 | * @param integer $limit pagination: records per page |
||
| 319 | * @return array associative array containing the response |
||
| 320 | */ |
||
| 321 | 1 | public function allWebhooks($page = 1, $limit = 20) { |
|
| 329 | |||
| 330 | /** |
||
| 331 | * get an existing webhook by it's identifier |
||
| 332 | * @param string $identifier a unique identifier associated with the webhook |
||
| 333 | * @return array associative array containing the response |
||
| 334 | */ |
||
| 335 | 1 | public function getWebhook($identifier) { |
|
| 339 | |||
| 340 | /** |
||
| 341 | * create a new webhook |
||
| 342 | * @param string $url the url to receive the webhook events |
||
| 343 | * @param string $identifier a unique identifier to associate with this webhook |
||
| 344 | * @return array associative array containing the response |
||
| 345 | */ |
||
| 346 | 1 | public function setupWebhook($url, $identifier = null) { |
|
| 354 | |||
| 355 | /** |
||
| 356 | * update an existing webhook |
||
| 357 | * @param string $identifier the unique identifier of the webhook to update |
||
| 358 | * @param string $newUrl the new url to receive the webhook events |
||
| 359 | * @param string $newIdentifier a new unique identifier to associate with this webhook |
||
| 360 | * @return array associative array containing the response |
||
| 361 | */ |
||
| 362 | 1 | public function updateWebhook($identifier, $newUrl = null, $newIdentifier = null) { |
|
| 370 | |||
| 371 | /** |
||
| 372 | * deletes an existing webhook and any event subscriptions associated with it |
||
| 373 | * @param string $identifier the unique identifier of the webhook to delete |
||
| 374 | * @return boolean true on success |
||
| 375 | */ |
||
| 376 | 1 | public function deleteWebhook($identifier) { |
|
| 380 | |||
| 381 | /** |
||
| 382 | * get a paginated list of all the events a webhook is subscribed to |
||
| 383 | * @param string $identifier the unique identifier of the webhook |
||
| 384 | * @param integer $page pagination: page number |
||
| 385 | * @param integer $limit pagination: records per page |
||
| 386 | * @return array associative array containing the response |
||
| 387 | */ |
||
| 388 | 1 | public function getWebhookEvents($identifier, $page = 1, $limit = 20) { |
|
| 396 | |||
| 397 | /** |
||
| 398 | * subscribes a webhook to transaction events of one particular transaction |
||
| 399 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 400 | * @param string $transaction the transaction hash |
||
| 401 | * @param integer $confirmations the amount of confirmations to send. |
||
| 402 | * @return array associative array containing the response |
||
| 403 | */ |
||
| 404 | 1 | public function subscribeTransaction($identifier, $transaction, $confirmations = 6) { |
|
| 413 | |||
| 414 | /** |
||
| 415 | * subscribes a webhook to transaction events on a particular address |
||
| 416 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 417 | * @param string $address the address hash |
||
| 418 | * @param integer $confirmations the amount of confirmations to send. |
||
| 419 | * @return array associative array containing the response |
||
| 420 | */ |
||
| 421 | 1 | public function subscribeAddressTransactions($identifier, $address, $confirmations = 6) { |
|
| 430 | |||
| 431 | /** |
||
| 432 | * batch subscribes a webhook to multiple transaction events |
||
| 433 | * |
||
| 434 | * @param string $identifier the unique identifier of the webhook |
||
| 435 | * @param array $batchData A 2D array of event data: |
||
| 436 | * [address => $address, confirmations => $confirmations] |
||
| 437 | * where $address is the address to subscibe to |
||
| 438 | * and optionally $confirmations is the amount of confirmations |
||
| 439 | * @return boolean true on success |
||
| 440 | */ |
||
| 441 | 1 | public function batchSubscribeAddressTransactions($identifier, $batchData) { |
|
| 453 | |||
| 454 | /** |
||
| 455 | * subscribes a webhook to a new block event |
||
| 456 | * @param string $identifier the unique identifier of the webhook to be triggered |
||
| 457 | * @return array associative array containing the response |
||
| 458 | */ |
||
| 459 | 1 | public function subscribeNewBlocks($identifier) { |
|
| 466 | |||
| 467 | /** |
||
| 468 | * removes an transaction event subscription from a webhook |
||
| 469 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 470 | * @param string $transaction the transaction hash of the event subscription |
||
| 471 | * @return boolean true on success |
||
| 472 | */ |
||
| 473 | 1 | public function unsubscribeTransaction($identifier, $transaction) { |
|
| 477 | |||
| 478 | /** |
||
| 479 | * removes an address transaction event subscription from a webhook |
||
| 480 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 481 | * @param string $address the address hash of the event subscription |
||
| 482 | * @return boolean true on success |
||
| 483 | */ |
||
| 484 | 1 | public function unsubscribeAddressTransactions($identifier, $address) { |
|
| 488 | |||
| 489 | /** |
||
| 490 | * removes a block event subscription from a webhook |
||
| 491 | * @param string $identifier the unique identifier of the webhook associated with the event subscription |
||
| 492 | * @return boolean true on success |
||
| 493 | */ |
||
| 494 | 1 | public function unsubscribeNewBlocks($identifier) { |
|
| 498 | |||
| 499 | /** |
||
| 500 | * create a new wallet |
||
| 501 | * - will generate a new primary seed (with password) and backup seed (without password) |
||
| 502 | * - send the primary seed (BIP39 'encrypted') and backup public key to the server |
||
| 503 | * - receive the blocktrail co-signing public key from the server |
||
| 504 | * |
||
| 505 | * Either takes one argument: |
||
| 506 | * @param array $options |
||
| 507 | * |
||
| 508 | * Or takes three arguments (old, deprecated syntax): |
||
| 509 | * (@nonPHP-doc) @param $identifier |
||
| 510 | * (@nonPHP-doc) @param $password |
||
| 511 | * (@nonPHP-doc) @param int $keyIndex override for the blocktrail cosigning key to use |
||
| 512 | * |
||
| 513 | * @return array[WalletInterface, array] list($wallet, $backupInfo) |
||
| 514 | * @throws \Exception |
||
| 515 | */ |
||
| 516 | 7 | public function createNewWallet($options) { |
|
| 560 | |||
| 561 | 1 | protected function createNewWalletV1($options) { |
|
| 671 | |||
| 672 | 5 | public static function randomBits($bits) { |
|
| 675 | |||
| 676 | 5 | public static function randomBytes($bytes) { |
|
| 679 | |||
| 680 | 2 | protected function createNewWalletV2($options) { |
|
| 800 | |||
| 801 | 4 | protected function createNewWalletV3($options) { |
|
| 939 | |||
| 940 | /** |
||
| 941 | * @param array $bip32Key |
||
| 942 | * @throws BlocktrailSDKException |
||
| 943 | */ |
||
| 944 | 10 | private function verifyPublicBIP32Key(array $bip32Key) { |
|
| 954 | |||
| 955 | /** |
||
| 956 | * @param array $walletData |
||
| 957 | * @throws BlocktrailSDKException |
||
| 958 | */ |
||
| 959 | 10 | private function verifyPublicOnly(array $walletData) { |
|
| 963 | |||
| 964 | /** |
||
| 965 | * create wallet using the API |
||
| 966 | * |
||
| 967 | * @param string $identifier the wallet identifier to create |
||
| 968 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 969 | * @param string $backupPublicKey plain public key |
||
| 970 | * @param string $primaryMnemonic mnemonic to store |
||
| 971 | * @param string $checksum checksum to store |
||
| 972 | * @param int $keyIndex account that we expect to use |
||
| 973 | * @return mixed |
||
| 974 | */ |
||
| 975 | 1 | public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, $keyIndex) { |
|
| 988 | |||
| 989 | /** |
||
| 990 | * create wallet using the API |
||
| 991 | * |
||
| 992 | * @param string $identifier the wallet identifier to create |
||
| 993 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 994 | * @param string $backupPublicKey plain public key |
||
| 995 | * @param $encryptedPrimarySeed |
||
| 996 | * @param $encryptedSecret |
||
| 997 | * @param $recoverySecret |
||
| 998 | * @param string $checksum checksum to store |
||
| 999 | * @param int $keyIndex account that we expect to use |
||
| 1000 | * @return mixed |
||
| 1001 | * @throws \Exception |
||
| 1002 | */ |
||
| 1003 | 5 | public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1019 | |||
| 1020 | /** |
||
| 1021 | * create wallet using the API |
||
| 1022 | * |
||
| 1023 | * @param string $identifier the wallet identifier to create |
||
| 1024 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1025 | * @param string $backupPublicKey plain public key |
||
| 1026 | * @param $encryptedPrimarySeed |
||
| 1027 | * @param $encryptedSecret |
||
| 1028 | * @param $recoverySecret |
||
| 1029 | * @param string $checksum checksum to store |
||
| 1030 | * @param int $keyIndex account that we expect to use |
||
| 1031 | * @return mixed |
||
| 1032 | * @throws \Exception |
||
| 1033 | */ |
||
| 1034 | 4 | public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex) { |
|
| 1052 | |||
| 1053 | /** |
||
| 1054 | * upgrade wallet to use a new account number |
||
| 1055 | * the account number specifies which blocktrail cosigning key is used |
||
| 1056 | * |
||
| 1057 | * @param string $identifier the wallet identifier to be upgraded |
||
| 1058 | * @param int $keyIndex the new account to use |
||
| 1059 | * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
||
| 1060 | * @return mixed |
||
| 1061 | */ |
||
| 1062 | public function upgradeKeyIndex($identifier, $keyIndex, $primaryPublicKey) { |
||
| 1071 | |||
| 1072 | /** |
||
| 1073 | * initialize a previously created wallet |
||
| 1074 | * |
||
| 1075 | * Takes an options object, or accepts identifier/password for backwards compatiblity. |
||
| 1076 | * |
||
| 1077 | * Some of the options: |
||
| 1078 | * - "readonly/readOnly/read-only" can be to a boolean value, |
||
| 1079 | * so the wallet is loaded in read-only mode (no private key) |
||
| 1080 | * - "check_backup_key" can be set to your own backup key: |
||
| 1081 | * Format: ["M', "xpub..."] |
||
| 1082 | * Setting this will allow the SDK to check the server hasn't |
||
| 1083 | * a different key (one it happens to control) |
||
| 1084 | |||
| 1085 | * Either takes one argument: |
||
| 1086 | * @param array $options |
||
| 1087 | * |
||
| 1088 | * Or takes two arguments (old, deprecated syntax): |
||
| 1089 | * (@nonPHP-doc) @param string $identifier the wallet identifier to be initialized |
||
| 1090 | * (@nonPHP-doc) @param string $password the password to decrypt the mnemonic with |
||
| 1091 | * |
||
| 1092 | * @return WalletInterface |
||
| 1093 | * @throws \Exception |
||
| 1094 | */ |
||
| 1095 | 16 | public function initWallet($options) { |
|
| 1202 | |||
| 1203 | /** |
||
| 1204 | * get the wallet data from the server |
||
| 1205 | * |
||
| 1206 | * @param string $identifier the identifier of the wallet |
||
| 1207 | * @return mixed |
||
| 1208 | */ |
||
| 1209 | 16 | public function getWallet($identifier) { |
|
| 1213 | |||
| 1214 | /** |
||
| 1215 | * update the wallet data on the server |
||
| 1216 | * |
||
| 1217 | * @param string $identifier |
||
| 1218 | * @param $data |
||
| 1219 | * @return mixed |
||
| 1220 | */ |
||
| 1221 | public function updateWallet($identifier, $data) { |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * delete a wallet from the server |
||
| 1228 | * the checksum address and a signature to verify you ownership of the key of that checksum address |
||
| 1229 | * is required to be able to delete a wallet |
||
| 1230 | * |
||
| 1231 | * @param string $identifier the identifier of the wallet |
||
| 1232 | * @param string $checksumAddress the address for your master private key (and the checksum used when creating the wallet) |
||
| 1233 | * @param string $signature a signature of the checksum address as message signed by the private key matching that address |
||
| 1234 | * @param bool $force ignore warnings (such as a non-zero balance) |
||
| 1235 | * @return mixed |
||
| 1236 | */ |
||
| 1237 | public function deleteWallet($identifier, $checksumAddress, $signature, $force = false) { |
||
| 1244 | |||
| 1245 | /** |
||
| 1246 | * create new backup key; |
||
| 1247 | * 1) a BIP39 mnemonic |
||
| 1248 | * 2) a seed from that mnemonic with a blank password |
||
| 1249 | * 3) a private key from that seed |
||
| 1250 | * |
||
| 1251 | * @return array [mnemonic, seed, key] |
||
| 1252 | */ |
||
| 1253 | 1 | protected function newBackupSeed() { |
|
| 1258 | |||
| 1259 | /** |
||
| 1260 | * create new primary key; |
||
| 1261 | * 1) a BIP39 mnemonic |
||
| 1262 | * 2) a seed from that mnemonic with the password |
||
| 1263 | * 3) a private key from that seed |
||
| 1264 | * |
||
| 1265 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1266 | * @return array [mnemonic, seed, key] |
||
| 1267 | * @TODO: require a strong password? |
||
| 1268 | */ |
||
| 1269 | 1 | protected function newPrimarySeed($passphrase) { |
|
| 1274 | |||
| 1275 | /** |
||
| 1276 | * create a new key; |
||
| 1277 | * 1) a BIP39 mnemonic |
||
| 1278 | * 2) a seed from that mnemonic with the password |
||
| 1279 | * 3) a private key from that seed |
||
| 1280 | * |
||
| 1281 | * @param string $passphrase the password to use in the BIP39 creation of the seed |
||
| 1282 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1283 | * @return array |
||
| 1284 | */ |
||
| 1285 | 1 | protected function generateNewSeed($passphrase = "", $forceEntropy = null) { |
|
| 1302 | |||
| 1303 | /** |
||
| 1304 | * generate a new mnemonic from some random entropy (512 bit) |
||
| 1305 | * |
||
| 1306 | * @param string $forceEntropy forced entropy instead of random entropy for testing purposes |
||
| 1307 | * @return string |
||
| 1308 | * @throws \Exception |
||
| 1309 | */ |
||
| 1310 | 1 | protected function generateNewMnemonic($forceEntropy = null) { |
|
| 1320 | |||
| 1321 | /** |
||
| 1322 | * get the balance for the wallet |
||
| 1323 | * |
||
| 1324 | * @param string $identifier the identifier of the wallet |
||
| 1325 | * @return array |
||
| 1326 | */ |
||
| 1327 | public function getWalletBalance($identifier) { |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * do HD wallet discovery for the wallet |
||
| 1334 | * |
||
| 1335 | * this can be REALLY slow, so we've set the timeout to 120s ... |
||
| 1336 | * |
||
| 1337 | * @param string $identifier the identifier of the wallet |
||
| 1338 | * @param int $gap the gap setting to use for discovery |
||
| 1339 | * @return mixed |
||
| 1340 | */ |
||
| 1341 | public function doWalletDiscovery($identifier, $gap = 200) { |
||
| 1345 | |||
| 1346 | /** |
||
| 1347 | * get a new derivation number for specified parent path |
||
| 1348 | * 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 |
||
| 1349 | * |
||
| 1350 | * returns the path |
||
| 1351 | * |
||
| 1352 | * @param string $identifier the identifier of the wallet |
||
| 1353 | * @param string $path the parent path for which to get a new derivation |
||
| 1354 | * @return string |
||
| 1355 | */ |
||
| 1356 | public function getNewDerivation($identifier, $path) { |
||
| 1360 | |||
| 1361 | /** |
||
| 1362 | * get a new derivation number for specified parent path |
||
| 1363 | * 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 |
||
| 1364 | * |
||
| 1365 | * @param string $identifier the identifier of the wallet |
||
| 1366 | * @param string $path the parent path for which to get a new derivation |
||
| 1367 | * @return mixed |
||
| 1368 | */ |
||
| 1369 | public function _getNewDerivation($identifier, $path) { |
||
| 1373 | |||
| 1374 | /** |
||
| 1375 | * get the path (and redeemScript) to specified address |
||
| 1376 | * |
||
| 1377 | * @param string $identifier |
||
| 1378 | * @param string $address |
||
| 1379 | * @return array |
||
| 1380 | * @throws \Exception |
||
| 1381 | */ |
||
| 1382 | public function getPathForAddress($identifier, $address) { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * send the transaction using the API |
||
| 1389 | * |
||
| 1390 | * @param string $identifier the identifier of the wallet |
||
| 1391 | * @param string|array $rawTransaction raw hex of the transaction (should be partially signed) |
||
| 1392 | * @param array $paths list of the paths that were used for the UTXO |
||
| 1393 | * @param bool $checkFee let the server verify the fee after signing |
||
| 1394 | * @return string the complete raw transaction |
||
| 1395 | * @throws \Exception |
||
| 1396 | */ |
||
| 1397 | public function sendTransaction($identifier, $rawTransaction, $paths, $checkFee = false) { |
||
| 1427 | |||
| 1428 | /** |
||
| 1429 | * use the API to get the best inputs to use based on the outputs |
||
| 1430 | * |
||
| 1431 | * the return array has the following format: |
||
| 1432 | * [ |
||
| 1433 | * "utxos" => [ |
||
| 1434 | * [ |
||
| 1435 | * "hash" => "<txHash>", |
||
| 1436 | * "idx" => "<index of the output of that <txHash>", |
||
| 1437 | * "scriptpubkey_hex" => "<scriptPubKey-hex>", |
||
| 1438 | * "value" => 32746327, |
||
| 1439 | * "address" => "1address", |
||
| 1440 | * "path" => "m/44'/1'/0'/0/13", |
||
| 1441 | * "redeem_script" => "<redeemScript-hex>", |
||
| 1442 | * ], |
||
| 1443 | * ], |
||
| 1444 | * "fee" => 10000, |
||
| 1445 | * "change"=> 1010109201, |
||
| 1446 | * ] |
||
| 1447 | * |
||
| 1448 | * @param string $identifier the identifier of the wallet |
||
| 1449 | * @param array $outputs the outputs you want to create - array[address => satoshi-value] |
||
| 1450 | * @param bool $lockUTXO when TRUE the UTXOs selected will be locked for a few seconds |
||
| 1451 | * so you have some time to spend them without race-conditions |
||
| 1452 | * @param bool $allowZeroConf |
||
| 1453 | * @param string $feeStrategy |
||
| 1454 | * @param null|int $forceFee |
||
| 1455 | * @return array |
||
| 1456 | * @throws \Exception |
||
| 1457 | */ |
||
| 1458 | public function coinSelection($identifier, $outputs, $lockUTXO = false, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null) { |
||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * |
||
| 1481 | * @param string $identifier the identifier of the wallet |
||
| 1482 | * @param bool $allowZeroConf |
||
| 1483 | * @param string $feeStrategy |
||
| 1484 | * @param null|int $forceFee |
||
| 1485 | * @param int $outputCnt |
||
| 1486 | * @return array |
||
| 1487 | * @throws \Exception |
||
| 1488 | */ |
||
| 1489 | public function walletMaxSpendable($identifier, $allowZeroConf = false, $feeStrategy = Wallet::FEE_STRATEGY_OPTIMAL, $forceFee = null, $outputCnt = 1) { |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * @return array ['optimal_fee' => 10000, 'low_priority_fee' => 5000] |
||
| 1511 | */ |
||
| 1512 | public function feePerKB() { |
||
| 1516 | |||
| 1517 | /** |
||
| 1518 | * get the current price index |
||
| 1519 | * |
||
| 1520 | * @return array eg; ['USD' => 287.30] |
||
| 1521 | */ |
||
| 1522 | 1 | public function price() { |
|
| 1526 | |||
| 1527 | /** |
||
| 1528 | * setup webhook for wallet |
||
| 1529 | * |
||
| 1530 | * @param string $identifier the wallet identifier for which to create the webhook |
||
| 1531 | * @param string $webhookIdentifier the webhook identifier to use |
||
| 1532 | * @param string $url the url to receive the webhook events |
||
| 1533 | * @return array |
||
| 1534 | */ |
||
| 1535 | public function setupWalletWebhook($identifier, $webhookIdentifier, $url) { |
||
| 1539 | |||
| 1540 | /** |
||
| 1541 | * delete webhook for wallet |
||
| 1542 | * |
||
| 1543 | * @param string $identifier the wallet identifier for which to delete the webhook |
||
| 1544 | * @param string $webhookIdentifier the webhook identifier to delete |
||
| 1545 | * @return array |
||
| 1546 | */ |
||
| 1547 | public function deleteWalletWebhook($identifier, $webhookIdentifier) { |
||
| 1551 | |||
| 1552 | /** |
||
| 1553 | * lock a specific unspent output |
||
| 1554 | * |
||
| 1555 | * @param $identifier |
||
| 1556 | * @param $txHash |
||
| 1557 | * @param $txIdx |
||
| 1558 | * @param int $ttl |
||
| 1559 | * @return bool |
||
| 1560 | */ |
||
| 1561 | public function lockWalletUTXO($identifier, $txHash, $txIdx, $ttl = 3) { |
||
| 1565 | |||
| 1566 | /** |
||
| 1567 | * unlock a specific unspent output |
||
| 1568 | * |
||
| 1569 | * @param $identifier |
||
| 1570 | * @param $txHash |
||
| 1571 | * @param $txIdx |
||
| 1572 | * @return bool |
||
| 1573 | */ |
||
| 1574 | public function unlockWalletUTXO($identifier, $txHash, $txIdx) { |
||
| 1578 | |||
| 1579 | /** |
||
| 1580 | * get all transactions for wallet (paginated) |
||
| 1581 | * |
||
| 1582 | * @param string $identifier the wallet identifier for which to get transactions |
||
| 1583 | * @param integer $page pagination: page number |
||
| 1584 | * @param integer $limit pagination: records per page (max 500) |
||
| 1585 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1586 | * @return array associative array containing the response |
||
| 1587 | */ |
||
| 1588 | public function walletTransactions($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * get all addresses for wallet (paginated) |
||
| 1600 | * |
||
| 1601 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1602 | * @param integer $page pagination: page number |
||
| 1603 | * @param integer $limit pagination: records per page (max 500) |
||
| 1604 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1605 | * @return array associative array containing the response |
||
| 1606 | */ |
||
| 1607 | public function walletAddresses($identifier, $page = 1, $limit = 20, $sortDir = 'asc') { |
||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * get all UTXOs for wallet (paginated) |
||
| 1619 | * |
||
| 1620 | * @param string $identifier the wallet identifier for which to get addresses |
||
| 1621 | * @param integer $page pagination: page number |
||
| 1622 | * @param integer $limit pagination: records per page (max 500) |
||
| 1623 | * @param string $sortDir pagination: sort direction (asc|desc) |
||
| 1624 | * @param boolean $zeroconf include zero confirmation transactions |
||
| 1625 | * @return array associative array containing the response |
||
| 1626 | */ |
||
| 1627 | public function walletUTXOs($identifier, $page = 1, $limit = 20, $sortDir = 'asc', $zeroconf = true) { |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * get a paginated list of all wallets associated with the api user |
||
| 1640 | * |
||
| 1641 | * @param integer $page pagination: page number |
||
| 1642 | * @param integer $limit pagination: records per page |
||
| 1643 | * @return array associative array containing the response |
||
| 1644 | */ |
||
| 1645 | public function allWallets($page = 1, $limit = 20) { |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * send raw transaction |
||
| 1656 | * |
||
| 1657 | * @param $txHex |
||
| 1658 | * @return bool |
||
| 1659 | */ |
||
| 1660 | public function sendRawTransaction($txHex) { |
||
| 1664 | |||
| 1665 | /** |
||
| 1666 | * testnet only ;-) |
||
| 1667 | * |
||
| 1668 | * @param $address |
||
| 1669 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1670 | * @return mixed |
||
| 1671 | * @throws \Exception |
||
| 1672 | */ |
||
| 1673 | public function faucetWithdrawal($address, $amount = 10000) { |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Exists for BC. Remove at major bump. |
||
| 1683 | * |
||
| 1684 | * @see faucetWithdrawal |
||
| 1685 | * @deprecated |
||
| 1686 | * @param $address |
||
| 1687 | * @param int $amount defaults to 0.0001 BTC, max 0.001 BTC |
||
| 1688 | * @return mixed |
||
| 1689 | * @throws \Exception |
||
| 1690 | */ |
||
| 1691 | public function faucetWithdrawl($address, $amount = 10000) { |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * verify a message signed bitcoin-core style |
||
| 1697 | * |
||
| 1698 | * @param string $message |
||
| 1699 | * @param string $address |
||
| 1700 | * @param string $signature |
||
| 1701 | * @return boolean |
||
| 1702 | */ |
||
| 1703 | 1 | public function verifyMessage($message, $address, $signature) { |
|
| 1720 | |||
| 1721 | /** |
||
| 1722 | * convert a Satoshi value to a BTC value |
||
| 1723 | * |
||
| 1724 | * @param int $satoshi |
||
| 1725 | * @return float |
||
| 1726 | */ |
||
| 1727 | public static function toBTC($satoshi) { |
||
| 1730 | |||
| 1731 | /** |
||
| 1732 | * convert a Satoshi value to a BTC value and return it as a string |
||
| 1733 | |||
| 1734 | * @param int $satoshi |
||
| 1735 | * @return string |
||
| 1736 | */ |
||
| 1737 | public static function toBTCString($satoshi) { |
||
| 1740 | |||
| 1741 | /** |
||
| 1742 | * convert a BTC value to a Satoshi value |
||
| 1743 | * |
||
| 1744 | * @param float $btc |
||
| 1745 | * @return string |
||
| 1746 | */ |
||
| 1747 | public static function toSatoshiString($btc) { |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | * convert a BTC value to a Satoshi value |
||
| 1753 | * |
||
| 1754 | * @param float $btc |
||
| 1755 | * @return string |
||
| 1756 | */ |
||
| 1757 | public static function toSatoshi($btc) { |
||
| 1760 | |||
| 1761 | /** |
||
| 1762 | * json_decode helper that throws exceptions when it fails to decode |
||
| 1763 | * |
||
| 1764 | * @param $json |
||
| 1765 | * @param bool $assoc |
||
| 1766 | * @return mixed |
||
| 1767 | * @throws \Exception |
||
| 1768 | */ |
||
| 1769 | 25 | protected static function jsonDecode($json, $assoc = false) { |
|
| 1782 | |||
| 1783 | /** |
||
| 1784 | * sort public keys for multisig script |
||
| 1785 | * |
||
| 1786 | * @param PublicKeyInterface[] $pubKeys |
||
| 1787 | * @return PublicKeyInterface[] |
||
| 1788 | */ |
||
| 1789 | public static function sortMultisigKeys(array $pubKeys) { |
||
| 1799 | |||
| 1800 | /** |
||
| 1801 | * read and decode the json payload from a webhook's POST request. |
||
| 1802 | * |
||
| 1803 | * @param bool $returnObject flag to indicate if an object or associative array should be returned |
||
| 1804 | * @return mixed|null |
||
| 1805 | * @throws \Exception |
||
| 1806 | */ |
||
| 1807 | public static function getWebhookPayload($returnObject = false) { |
||
| 1815 | |||
| 1816 | public static function normalizeBIP32KeyArray($keys) { |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * @param array|BIP32Key $key |
||
| 1824 | * @return BIP32Key |
||
| 1825 | * @throws \Exception |
||
| 1826 | */ |
||
| 1827 | 13 | public static function normalizeBIP32Key($key) { |
|
| 1845 | } |
||
| 1846 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.