| Conditions | 14 |
| Paths | 396 |
| Total Lines | 70 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 131 | public function testCases($fixture) |
||
| 132 | { |
||
| 133 | $bitcoind = $this->rpcFactory->startBitcoind(); |
||
| 134 | $this->assertTrue($bitcoind->isRunning()); |
||
| 135 | |||
| 136 | $defaultPolicy = Interpreter::VERIFY_NONE | Interpreter::VERIFY_P2SH | Interpreter::VERIFY_WITNESS | Interpreter::VERIFY_CHECKLOCKTIMEVERIFY | Interpreter::VERIFY_CHECKSEQUENCEVERIFY;; |
||
| 137 | $txBuilder = new TxBuilder(); |
||
| 138 | if (array_key_exists('version', $fixture['raw'])) { |
||
| 139 | $txBuilder->version((int) $fixture['raw']['version']); |
||
| 140 | } |
||
| 141 | |||
| 142 | $totalOut = 12345; |
||
| 143 | foreach ($fixture['raw']['outs'] as $output) { |
||
| 144 | $txBuilder->output($output['value'], ScriptFactory::fromHex($output['script'])); |
||
| 145 | $totalOut += $output['value']; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var SignData[] $signDatas |
||
| 150 | * @var Utxo[] $utxos |
||
| 151 | */ |
||
| 152 | $signDatas = []; |
||
| 153 | $utxos = []; |
||
| 154 | foreach ($fixture['raw']['ins'] as $input) { |
||
| 155 | $scriptPubKey = ScriptFactory::fromHex($input['scriptPubKey']); |
||
| 156 | |||
| 157 | $value = array_key_exists('value', $input) ? (int) $input['value'] : $totalOut; |
||
| 158 | $utxo = $this->fundOutput($bitcoind, $scriptPubKey, $value); |
||
| 159 | |||
| 160 | $sequence = array_key_exists('sequence', $input) ? (int) $input['sequence'] : 0xffffffff; |
||
| 161 | $txBuilder->spendOutPoint($utxo->getOutPoint(), null, $sequence); |
||
| 162 | |||
| 163 | $signData = new SignData(); |
||
| 164 | if (array_key_exists('redeemScript', $input) && "" !== $input['redeemScript']) { |
||
| 165 | $signData->p2sh(ScriptFactory::fromHex($input['redeemScript'])); |
||
| 166 | } |
||
| 167 | if (array_key_exists('witnessScript', $input) && "" !== $input['witnessScript']) { |
||
| 168 | $signData->p2wsh(ScriptFactory::fromHex($input['witnessScript'])); |
||
| 169 | } |
||
| 170 | |||
| 171 | $policy = array_key_exists('signaturePolicy', $fixture) ? $this->getScriptFlagsFromString($fixture['signaturePolicy']) : $defaultPolicy; |
||
| 172 | $signData->signaturePolicy($policy); |
||
| 173 | $signDatas[] = $signData; |
||
| 174 | |||
| 175 | $utxos[] = $utxo; |
||
| 176 | } |
||
| 177 | |||
| 178 | $txBuilder->locktime(isset($fixture['raw']['locktime']) ? $fixture['raw']['locktime'] : 0); |
||
| 179 | |||
| 180 | $signer = new Signer($txBuilder->get()); |
||
| 181 | foreach ($fixture['raw']['ins'] as $i => $input) { |
||
| 182 | $iSigner = $signer->input($i, $utxos[$i]->getOutput(), $signDatas[$i]); |
||
| 183 | foreach ($input['keys'] as $key) { |
||
| 184 | $priv = PrivateKeyFactory::fromWif($key['key'], null, NetworkFactory::bitcoinTestnet()); |
||
| 185 | $sigHashType = $key['sigHashType']; |
||
| 186 | $iSigner->sign($priv, $sigHashType); |
||
| 187 | } |
||
| 188 | |||
| 189 | $this->assertTrue($iSigner->isFullySigned()); |
||
| 190 | } |
||
| 191 | |||
| 192 | $tx = $signer->get(); |
||
| 193 | $result = $bitcoind->makeRpcRequest('sendrawtransaction', [$tx->getHex(), true]); |
||
| 194 | $this->assertEquals(null, $result['error']); |
||
| 195 | |||
| 196 | $txid = $result['result']; |
||
| 197 | $this->assertEquals(64, strlen($txid)); |
||
| 198 | |||
| 199 | $bitcoind->destroy(); |
||
| 200 | } |
||
| 201 | } |
||
| 202 |