Completed
Push — master ( cc9f4e...3a552b )
by thomas
38:55 queued 36:36
created

Checker::checkSequence()   C

Complexity

Conditions 8
Paths 5

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8.0189

Importance

Changes 0
Metric Value
cc 8
eloc 15
nc 5
nop 1
dl 0
loc 27
ccs 14
cts 15
cp 0.9333
crap 8.0189
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Script\Interpreter;
6
7
use BitWasp\Bitcoin\Script\ScriptInterface;
8
use BitWasp\Bitcoin\Transaction\SignatureHash\Hasher;
9
use BitWasp\Bitcoin\Transaction\SignatureHash\SigHash;
10
use BitWasp\Bitcoin\Transaction\SignatureHash\V1Hasher;
11
use BitWasp\Buffertools\Buffer;
12
use BitWasp\Buffertools\BufferInterface;
13
14
class Checker extends CheckerBase
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $sigHashCache = [];
20
21
    /**
22
     * @param ScriptInterface $script
23
     * @param int $sigHashType
24
     * @param int $sigVersion
25
     * @return BufferInterface
26
     */
27 330
    public function getSigHash(ScriptInterface $script, int $sigHashType, int $sigVersion): BufferInterface
28
    {
29 330
        $cacheCheck = $sigVersion . $sigHashType . $script->getBuffer()->getBinary();
30 330
        if (!isset($this->sigHashCache[$cacheCheck])) {
31 330
            if (SigHash::V1 === $sigVersion) {
32 82
                $hasher = new V1Hasher($this->transaction, $this->amount);
33
            } else {
34 250
                $hasher = new Hasher($this->transaction);
35
            }
36
37 330
            $hash = $hasher->calculate($script, $this->nInput, $sigHashType);
38 330
            $this->sigHashCache[$cacheCheck] = $hash->getBinary();
39
        } else {
40 46
            $hash = new Buffer($this->sigHashCache[$cacheCheck], 32);
41
        }
42
43 330
        return $hash;
44
    }
45
}
46