@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | 'handler' => $handler, |
| 102 | 102 | 'base_uri' => $this->apiEndpoint, |
| 103 | 103 | 'headers' => array( |
| 104 | - 'User-Agent' => Blocktrail::SDK_USER_AGENT . '/' . Blocktrail::SDK_VERSION, |
|
| 104 | + 'User-Agent' => Blocktrail::SDK_USER_AGENT.'/'.Blocktrail::SDK_VERSION, |
|
| 105 | 105 | ), |
| 106 | 106 | 'http_errors' => false, |
| 107 | 107 | 'connect_timeout' => 3, |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $contentMD5Mode = !is_null($body) ? 'body' : 'url'; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $request = new Request($method, $this->apiEndpoint . $endpointUrl); |
|
| 249 | + $request = new Request($method, $this->apiEndpoint.$endpointUrl); |
|
| 250 | 250 | $uri = $request->getUri(); |
| 251 | 251 | |
| 252 | 252 | if ($queryString) { |
@@ -341,9 +341,9 @@ discard block |
||
| 341 | 341 | throw new ObjectNotFound($this->verboseErrors ? $body : Blocktrail::EXCEPTION_OBJECT_NOT_FOUND, $httpResponseCode); |
| 342 | 342 | } |
| 343 | 343 | } elseif ($httpResponseCode == 500) { |
| 344 | - throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR . "\nServer Response: " . $body, $httpResponseCode); |
|
| 344 | + throw new GenericServerError(Blocktrail::EXCEPTION_GENERIC_SERVER_ERROR."\nServer Response: ".$body, $httpResponseCode); |
|
| 345 | 345 | } else { |
| 346 | - throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR . "\nServer Response: " . $body, $httpResponseCode); |
|
| 346 | + throw new GenericHTTPError(Blocktrail::EXCEPTION_GENERIC_HTTP_ERROR."\nServer Response: ".$body, $httpResponseCode); |
|
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | |
@@ -184,12 +184,12 @@ |
||
| 184 | 184 | assert($witnessScript === null || $isWitness); |
| 185 | 185 | $classifier = new OutputClassifier(); |
| 186 | 186 | if ($classifier->isMultisig($script)) { |
| 187 | - list ($stackSizes, ) = SizeEstimation::estimateMultisigStackSize(new Multisig($script)); |
|
| 187 | + list ($stackSizes,) = SizeEstimation::estimateMultisigStackSize(new Multisig($script)); |
|
| 188 | 188 | } else if ($classifier->isPayToPublicKey($script)) { |
| 189 | - list ($stackSizes, ) = SizeEstimation::estimateP2PKStackSize(new PayToPubKey($script)); |
|
| 189 | + list ($stackSizes,) = SizeEstimation::estimateP2PKStackSize(new PayToPubKey($script)); |
|
| 190 | 190 | } else if ($classifier->isPayToPublicKeyHash($script)) { |
| 191 | 191 | // defaults to compressed, tough luck |
| 192 | - list ($stackSizes, ) = SizeEstimation::estimateP2PKHStackSize(); |
|
| 192 | + list ($stackSizes,) = SizeEstimation::estimateP2PKHStackSize(); |
|
| 193 | 193 | } else { |
| 194 | 194 | throw new \InvalidArgumentException("Unsupported script type"); |
| 195 | 195 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @param bool $setting |
| 54 | 54 | */ |
| 55 | 55 | public static function enforceScriptChecks($setting) { |
| 56 | - static::$checkScripts = (bool) $setting; |
|
| 56 | + static::$checkScripts = (bool)$setting; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if ($value <= Blocktrail::DUST) { |
| 110 | - throw new \Exception("Values should be more than dust (" . Blocktrail::DUST . ")"); |
|
| 110 | + throw new \Exception("Values should be more than dust (".Blocktrail::DUST.")"); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | if ($object instanceof SegwitAddress) { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if ($value <= Blocktrail::DUST) { |
| 165 | - throw new \Exception("Values should be more than dust (" . Blocktrail::DUST . ")"); |
|
| 165 | + throw new \Exception("Values should be more than dust (".Blocktrail::DUST.")"); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | if (!isset($this->outputs[$idx])) { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @return array |
| 209 | 209 | */ |
| 210 | 210 | public function getOutputs($json = false) { |
| 211 | - return array_map(function ($output) use ($json) { |
|
| 211 | + return array_map(function($output) use ($json) { |
|
| 212 | 212 | $result = $output; |
| 213 | 213 | |
| 214 | 214 | if ($json) { |
@@ -5,7 +5,6 @@ |
||
| 5 | 5 | use BitWasp\Bitcoin\Address\AddressFactory; |
| 6 | 6 | use BitWasp\Bitcoin\Address\AddressInterface; |
| 7 | 7 | use BitWasp\Bitcoin\Address\SegwitAddress; |
| 8 | -use BitWasp\Bitcoin\Script\Script; |
|
| 9 | 8 | use BitWasp\Bitcoin\Script\ScriptFactory; |
| 10 | 9 | use BitWasp\Bitcoin\Script\ScriptInterface; |
| 11 | 10 | use BitWasp\Buffertools\Buffer; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $this->getBlocktrailPublicKey($path)->buildKey($path)->publicKey() |
| 164 | 164 | ]), false); |
| 165 | 165 | |
| 166 | - if ($this->network !== "bitcoincash" && (int) $path[2] === 2) { |
|
| 166 | + if ($this->network !== "bitcoincash" && (int)$path[2] === 2) { |
|
| 167 | 167 | $witnessScript = new WitnessScript($multisig); |
| 168 | 168 | $redeemScript = new P2shScript($witnessScript); |
| 169 | 169 | $address = $redeemScript->getAddress()->getAddress(); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | for ($i = 0; $i < $count; $i++) { |
| 191 | 191 | //create a path subsequent address |
| 192 | - $path = (string)WalletPath::create($keyIndex, $_chain = 0, $start+$i)->path()->publicPath(); |
|
| 192 | + $path = (string)WalletPath::create($keyIndex, $_chain = 0, $start + $i)->path()->publicPath(); |
|
| 193 | 193 | list($address, $redeem, $witness) = $this->createAddress($path); |
| 194 | 194 | $addresses[$address] = array( |
| 195 | 195 | //'address' => $address, |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $totalUTXOs = 0; |
| 239 | 239 | $totalAddressesGenerated = 0; |
| 240 | 240 | |
| 241 | - $addressUTXOs = array(); //addresses and their utxos, paths and redeem scripts |
|
| 241 | + $addressUTXOs = array(); //addresses and their utxos, paths and redeem scripts |
|
| 242 | 242 | |
| 243 | 243 | //for each blocktrail pub key, do fund discovery on batches of addresses |
| 244 | 244 | foreach ($this->blocktrailPublicKeys as $keyIndex => $blocktrailPubKey) { |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | $addressUTXOs[$address]['utxos'][] = $utxo; |
| 277 | - $totalUTXOs ++; |
|
| 277 | + $totalUTXOs++; |
|
| 278 | 278 | |
| 279 | 279 | //add up the total utxo value for all addresses |
| 280 | 280 | $totalBalance += $utxo['value']; |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | $signer->redeemBitcoinCash(true); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - assert(Util::all(function ($signInfo) { |
|
| 392 | + assert(Util::all(function($signInfo) { |
|
| 393 | 393 | return $signInfo instanceof SignInfo; |
| 394 | 394 | }, $signInfo), '$signInfo should be SignInfo[]'); |
| 395 | 395 | |
@@ -9,6 +9,11 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | interface BlocktrailSDKInterface { |
| 11 | 11 | |
| 12 | + /** |
|
| 13 | + * @param string $apiSecret |
|
| 14 | + * |
|
| 15 | + * @return void |
|
| 16 | + */ |
|
| 12 | 17 | public function __construct($apiKey, $apiSecret, $network = 'BTC', $testnet = false, $apiVersion = 'v1', $apiEndpoint = null); |
| 13 | 18 | |
| 14 | 19 | /** |
@@ -17,6 +22,7 @@ discard block |
||
| 17 | 22 | * @param bool $debug |
| 18 | 23 | * |
| 19 | 24 | * @codeCoverageIgnore |
| 25 | + * @return void |
|
| 20 | 26 | */ |
| 21 | 27 | public function setCurlDebugging($debug = true); |
| 22 | 28 | |
@@ -26,6 +32,7 @@ discard block |
||
| 26 | 32 | * @param bool $verboseErrors |
| 27 | 33 | * |
| 28 | 34 | * @codeCoverageIgnore |
| 35 | + * @return void |
|
| 29 | 36 | */ |
| 30 | 37 | public function setVerboseErrors($verboseErrors = true); |
| 31 | 38 | |
@@ -35,6 +42,7 @@ discard block |
||
| 35 | 42 | * @param bool $value |
| 36 | 43 | * |
| 37 | 44 | * @codeCoverageIgnore |
| 45 | + * @return void |
|
| 38 | 46 | */ |
| 39 | 47 | public function setCurlDefaultOption($key, $value); |
| 40 | 48 | |
@@ -311,7 +319,7 @@ discard block |
||
| 311 | 319 | * |
| 312 | 320 | * @param string $identifier the wallet identifier to be upgraded |
| 313 | 321 | * @param int $keyIndex the new account to use |
| 314 | - * @param array $primaryPublicKey BIP32 extended public key - [key, path] |
|
| 322 | + * @param string[] $primaryPublicKey BIP32 extended public key - [key, path] |
|
| 315 | 323 | * @return mixed |
| 316 | 324 | */ |
| 317 | 325 | public function upgradeKeyIndex($identifier, $keyIndex, $primaryPublicKey); |
@@ -415,7 +423,7 @@ discard block |
||
| 415 | 423 | * |
| 416 | 424 | * @param string $identifier the identifier of the wallet |
| 417 | 425 | * @param string|array $rawTransaction raw hex of the transaction (should be partially signed) |
| 418 | - * @param array $paths list of the paths that were used for the UTXO |
|
| 426 | + * @param string[] $paths list of the paths that were used for the UTXO |
|
| 419 | 427 | * @param bool $checkFee let the server verify the fee after signing |
| 420 | 428 | * @return string the complete raw transaction |
| 421 | 429 | * @throws \Exception |
@@ -443,7 +451,7 @@ discard block |
||
| 443 | 451 | * ] |
| 444 | 452 | * |
| 445 | 453 | * @param string $identifier the identifier of the wallet |
| 446 | - * @param array $outputs the outputs you want to create - array[address => satoshi-value] |
|
| 454 | + * @param \array[] $outputs the outputs you want to create - array[address => satoshi-value] |
|
| 447 | 455 | * @param bool $lockUTXO when TRUE the UTXOs selected will be locked for a few seconds |
| 448 | 456 | * so you have some time to spend them without race-conditions |
| 449 | 457 | * @param bool $allowZeroConf |
@@ -487,22 +495,22 @@ discard block |
||
| 487 | 495 | /** |
| 488 | 496 | * lock a specific unspent output |
| 489 | 497 | * |
| 490 | - * @param $identifier |
|
| 498 | + * @param string $identifier |
|
| 491 | 499 | * @param $txHash |
| 492 | 500 | * @param $txIdx |
| 493 | 501 | * @param int $ttl |
| 494 | 502 | * @return |
| 495 | - */ |
|
| 503 | + boolean |
|
| 496 | 504 | public function lockWalletUTXO($identifier, $txHash, $txIdx, $ttl = 3); |
| 497 | 505 | |
| 498 | 506 | /** |
| 499 | 507 | * unlock a specific unspent output |
| 500 | 508 | * |
| 501 | - * @param $identifier |
|
| 509 | + * @param string $identifier |
|
| 502 | 510 | * @param $txHash |
| 503 | 511 | * @param $txIdx |
| 504 | 512 | * @return |
| 505 | - */ |
|
| 513 | + boolean |
|
| 506 | 514 | public function unlockWalletUTXO($identifier, $txHash, $txIdx); |
| 507 | 515 | |
| 508 | 516 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | - * @param string|BIP32Path $path |
|
| 311 | + * @param BIP32Path $path |
|
| 312 | 312 | * @return BIP32Key|false |
| 313 | 313 | * @throws \Exception |
| 314 | 314 | * |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | /** |
| 336 | 336 | * get address for the specified path |
| 337 | 337 | * |
| 338 | - * @param string|BIP32Path $path |
|
| 338 | + * @param string $path |
|
| 339 | 339 | * @return string |
| 340 | 340 | */ |
| 341 | 341 | public function getAddressByPath($path) { |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
| 435 | - * @param string|BIP32Path $path |
|
| 435 | + * @param BIP32Path $path |
|
| 436 | 436 | * @return BIP32Key |
| 437 | 437 | * @throws \Exception |
| 438 | 438 | */ |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | * 'fund' the txBuilder with UTXOs (modified in place) |
| 582 | 582 | * |
| 583 | 583 | * @param TransactionBuilder $txBuilder |
| 584 | - * @param bool|true $lockUTXOs |
|
| 584 | + * @param boolean $lockUTXOs |
|
| 585 | 585 | * @param bool|false $allowZeroConf |
| 586 | 586 | * @param null|int $forceFee |
| 587 | 587 | * @return TransactionBuilder |
@@ -703,6 +703,10 @@ discard block |
||
| 703 | 703 | return [$txb->get(), $signInfo]; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | + /** |
|
| 707 | + * @param integer $optimalFeePerKB |
|
| 708 | + * @param integer $lowPriorityFeePerKB |
|
| 709 | + */ |
|
| 706 | 710 | public function determineFeeAndChange(TransactionBuilder $txBuilder, $optimalFeePerKB, $lowPriorityFeePerKB) { |
| 707 | 711 | $send = $txBuilder->getOutputs(); |
| 708 | 712 | $utxos = $txBuilder->getUtxos(); |
@@ -816,7 +820,7 @@ discard block |
||
| 816 | 820 | * @todo: mark this as deprecated, insist on the utxo's or qualified scripts. |
| 817 | 821 | * @param int $utxoCnt number of unspent inputs in transaction |
| 818 | 822 | * @param int $outputCnt number of outputs in transaction |
| 819 | - * @return float |
|
| 823 | + * @return integer |
|
| 820 | 824 | * @access public reminder that people might use this! |
| 821 | 825 | */ |
| 822 | 826 | public static function estimateFee($utxoCnt, $outputCnt) { |
@@ -839,7 +843,7 @@ discard block |
||
| 839 | 843 | * @todo: variable varint |
| 840 | 844 | * @param int $txinSize |
| 841 | 845 | * @param int $txoutSize |
| 842 | - * @return float |
|
| 846 | + * @return integer |
|
| 843 | 847 | */ |
| 844 | 848 | public static function estimateSize($txinSize, $txoutSize) { |
| 845 | 849 | return 4 + 4 + $txinSize + 4 + $txoutSize + 4; // version + txinVarInt + txin + txoutVarInt + txout + locktime |
@@ -849,7 +853,7 @@ discard block |
||
| 849 | 853 | * only supports estimating size for P2PKH/P2SH outputs |
| 850 | 854 | * |
| 851 | 855 | * @param int $outputCnt number of outputs in transaction |
| 852 | - * @return float |
|
| 856 | + * @return integer |
|
| 853 | 857 | */ |
| 854 | 858 | public static function estimateSizeOutputs($outputCnt) { |
| 855 | 859 | return ($outputCnt * 34); |
@@ -904,7 +908,7 @@ discard block |
||
| 904 | 908 | * |
| 905 | 909 | * @param UTXO[] $utxos |
| 906 | 910 | * @param array[] $outputs |
| 907 | - * @param $feeStrategy |
|
| 911 | + * @param string $feeStrategy |
|
| 908 | 912 | * @param $optimalFeePerKB |
| 909 | 913 | * @param $lowPriorityFeePerKB |
| 910 | 914 | * @return int |
@@ -1003,8 +1007,8 @@ discard block |
||
| 1003 | 1007 | * @param \array[] $outputs |
| 1004 | 1008 | * @param bool $lockUTXO |
| 1005 | 1009 | * @param bool $allowZeroConf |
| 1006 | - * @param int|null|string $feeStrategy |
|
| 1007 | - * @param null $forceFee |
|
| 1010 | + * @param string $feeStrategy |
|
| 1011 | + * @param null|integer $forceFee |
|
| 1008 | 1012 | * @return array |
| 1009 | 1013 | */ |
| 1010 | 1014 | public function coinSelection($outputs, $lockUTXO = true, $allowZeroConf = false, $feeStrategy = self::FEE_STRATEGY_OPTIMAL, $forceFee = null) { |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @return array[] [ [xpub, path] ] |
| 214 | 214 | */ |
| 215 | 215 | public function getBlocktrailPublicKeys() { |
| 216 | - return array_map(function (BIP32Key $key) { |
|
| 216 | + return array_map(function(BIP32Key $key) { |
|
| 217 | 217 | return $key->tuple(); |
| 218 | 218 | }, $this->blocktrailPublicKeys); |
| 219 | 219 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | public function getAddressByPath($path) { |
| 337 | 337 | $path = (string)BIP32Path::path($path)->privatePath(); |
| 338 | 338 | if (!isset($this->derivations[$path])) { |
| 339 | - list($address, ) = $this->getRedeemScriptByPath($path); |
|
| 339 | + list($address,) = $this->getRedeemScriptByPath($path); |
|
| 340 | 340 | |
| 341 | 341 | $this->derivations[$path] = $address; |
| 342 | 342 | $this->derivationsByAddress[$address] = $path; |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | $signInfo[] = $utxo->getSignInfo(); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - $utxoSum = array_sum(array_map(function (UTXO $utxo) { |
|
| 663 | + $utxoSum = array_sum(array_map(function(UTXO $utxo) { |
|
| 664 | 664 | return $utxo->value; |
| 665 | 665 | }, $utxos)); |
| 666 | 666 | if ($utxoSum < array_sum(array_column($send, 'value'))) { |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | throw new \Exception("Wallet needs to be unlocked to pay"); |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - assert(Util::all(function ($signInfo) { |
|
| 796 | + assert(Util::all(function($signInfo) { |
|
| 797 | 797 | return $signInfo instanceof SignInfo; |
| 798 | 798 | }, $signInfo), '$signInfo should be SignInfo[]'); |
| 799 | 799 | |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | ]; |
| 807 | 807 | |
| 808 | 808 | // send the transaction |
| 809 | - return $this->sendTransaction($txs, array_map(function (SignInfo $r) { |
|
| 809 | + return $this->sendTransaction($txs, array_map(function(SignInfo $r) { |
|
| 810 | 810 | return (string)$r->path; |
| 811 | 811 | }, $signInfo), $apiCheckFee); |
| 812 | 812 | } |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | public static function estimateSizeUTXOs($utxoCnt) { |
| 866 | 866 | $txinSize = 0; |
| 867 | 867 | |
| 868 | - for ($i=0; $i<$utxoCnt; $i++) { |
|
| 868 | + for ($i = 0; $i < $utxoCnt; $i++) { |
|
| 869 | 869 | // @TODO: proper size calculation, we only do multisig right now so it's hardcoded and then we guess the size ... |
| 870 | 870 | $multisig = "2of3"; |
| 871 | 871 | |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | * @return int |
| 940 | 940 | */ |
| 941 | 941 | protected function determineChange($utxos, $outputs, $fee) { |
| 942 | - $inputsTotal = array_sum(array_map(function (UTXO $utxo) { |
|
| 942 | + $inputsTotal = array_sum(array_map(function(UTXO $utxo) { |
|
| 943 | 943 | return $utxo->value; |
| 944 | 944 | }, $utxos)); |
| 945 | 945 | $outputsTotal = array_sum(array_column($outputs, 'value')); |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | protected function signTransaction(Transaction $tx, array $signInfo) { |
| 959 | 959 | $signer = new Signer($tx, Bitcoin::getEcAdapter()); |
| 960 | 960 | |
| 961 | - assert(Util::all(function ($signInfo) { |
|
| 961 | + assert(Util::all(function($signInfo) { |
|
| 962 | 962 | return $signInfo instanceof SignInfo; |
| 963 | 963 | }, $signInfo), '$signInfo should be SignInfo[]'); |
| 964 | 964 | |