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