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 | */ |
||
132 | public function testCases(array $fixture) |
||
133 | { |
||
134 | $bitcoind = $this->rpcFactory->startBitcoind(); |
||
135 | $this->assertTrue($bitcoind->isRunning()); |
||
136 | |||
137 | $defaultPolicy = Interpreter::VERIFY_NONE | Interpreter::VERIFY_P2SH | Interpreter::VERIFY_WITNESS | Interpreter::VERIFY_CHECKLOCKTIMEVERIFY | Interpreter::VERIFY_CHECKSEQUENCEVERIFY; |
||
138 | ; |
||
139 | $txBuilder = new TxBuilder(); |
||
140 | if (array_key_exists('version', $fixture['raw'])) { |
||
141 | $txBuilder->version((int) $fixture['raw']['version']); |
||
142 | } |
||
143 | |||
144 | $totalOut = 12345; |
||
145 | foreach ($fixture['raw']['outs'] as $output) { |
||
146 | $value = (int) $output['value']; |
||
147 | $txBuilder->output($value, ScriptFactory::fromHex($output['script'])); |
||
148 | $totalOut += $value; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @var SignData[] $signDatas |
||
153 | * @var Utxo[] $utxos |
||
154 | */ |
||
155 | $signDatas = []; |
||
156 | $utxos = []; |
||
157 | foreach ($fixture['raw']['ins'] as $input) { |
||
158 | $scriptPubKey = ScriptFactory::fromHex($input['scriptPubKey']); |
||
159 | |||
160 | $value = array_key_exists('value', $input) ? (int) $input['value'] : $totalOut; |
||
161 | $utxo = $this->fundOutput($bitcoind, $scriptPubKey, $value); |
||
162 | |||
163 | $sequence = array_key_exists('sequence', $input) ? (int) $input['sequence'] : 0xffffffff; |
||
164 | $txBuilder->spendOutPoint($utxo->getOutPoint(), null, $sequence); |
||
165 | |||
166 | $signData = new SignData(); |
||
167 | if (array_key_exists('redeemScript', $input) && "" !== $input['redeemScript']) { |
||
168 | $signData->p2sh(ScriptFactory::fromHex($input['redeemScript'])); |
||
169 | } |
||
170 | if (array_key_exists('witnessScript', $input) && "" !== $input['witnessScript']) { |
||
171 | $signData->p2wsh(ScriptFactory::fromHex($input['witnessScript'])); |
||
172 | } |
||
173 | |||
174 | $policy = array_key_exists('signaturePolicy', $fixture) ? $this->getScriptFlagsFromString($fixture['signaturePolicy']) : $defaultPolicy; |
||
175 | $signData->signaturePolicy($policy); |
||
176 | $signDatas[] = $signData; |
||
177 | |||
178 | $utxos[] = $utxo; |
||
179 | } |
||
180 | |||
181 | $txBuilder->locktime(isset($fixture['raw']['locktime']) ? $fixture['raw']['locktime'] : 0); |
||
182 | |||
183 | $signer = new Signer($txBuilder->get()); |
||
184 | foreach ($fixture['raw']['ins'] as $i => $input) { |
||
185 | $iSigner = $signer->input($i, $utxos[$i]->getOutput(), $signDatas[$i]); |
||
186 | foreach ($input['keys'] as $key) { |
||
187 | $priv = PrivateKeyFactory::fromWif($key['key'], null, NetworkFactory::bitcoinTestnet()); |
||
188 | $sigHashType = $key['sigHashType']; |
||
189 | $iSigner->sign($priv, $sigHashType); |
||
190 | } |
||
191 | |||
192 | $this->assertTrue($iSigner->isFullySigned()); |
||
193 | } |
||
194 | |||
195 | $tx = $signer->get(); |
||
196 | $result = $bitcoind->makeRpcRequest('sendrawtransaction', [$tx->getHex(), true]); |
||
197 | $this->assertEquals(null, $result['error']); |
||
198 | |||
199 | $txid = $result['result']; |
||
200 | $this->assertEquals(64, strlen($txid)); |
||
201 | |||
205 |