Completed
Push — 0.0.35 ( b2fc74...d8d049 )
by thomas
28:12 queued 09:10
created

Checker::checkLockTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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