Completed
Push — master ( 55cd4a...70da09 )
by thomas
26:52
created

Validator::checkSignatures()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.2
cc 4
eloc 7
nc 4
nop 2
crap 20
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Script\Consensus\ConsensusInterface;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
8
class Validator implements ValidatorInterface
9
{
10
    /**
11
     * @var TransactionInterface
12
     */
13
    private $transaction;
14
15
    /**
16
     * Validator constructor.
17
     * @param TransactionInterface $transaction
18
     */
19
    public function __construct(TransactionInterface $transaction)
20
    {
21
        $this->transaction = $transaction;
22
    }
23
24
    /**
25
     * @param ConsensusInterface $consensus
26
     * @param int $nInput
27
     * @param ScriptInterface $scriptPubKey
28
     * @return bool
29
     */
30
    public function checkSignature(ConsensusInterface $consensus, $nInput, ScriptInterface $scriptPubKey)
31
    {
32
        return $consensus->verify($this->transaction, $scriptPubKey, $nInput);
33
    }
34
35
    /**
36
     * @param ConsensusInterface $consensus
37
     * @param array $scriptPubKeys
38
     * @return bool
39
     */
40
    public function checkSignatures(ConsensusInterface $consensus, array $scriptPubKeys)
41
    {
42
        if (count($this->transaction->getInputs()) !== count($scriptPubKeys)) {
43
            throw new \InvalidArgumentException('Incorrect scriptPubKey count');
44
        }
45
46
        $result = true;
47
        foreach ($scriptPubKeys as $i => $scriptPubKey) {
48
            $result = $result && $this->checkSignature($consensus, $i, $scriptPubKey);
49
        }
50
51
        return $result;
52
    }
53
}
54