Completed
Pull Request — master (#391)
by thomas
256:49 queued 254:17
created

NativeConsensus::verify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 6
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Consensus;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Crypto\EcAdapter\Adapter\EcAdapterInterface;
7
use BitWasp\Bitcoin\Script\Interpreter\Checker;
8
use BitWasp\Bitcoin\Script\Interpreter\Interpreter;
9
use BitWasp\Bitcoin\Script\ScriptInterface;
10
use BitWasp\Bitcoin\Script\ScriptWitnessInterface;
11
use BitWasp\Bitcoin\Transaction\TransactionInterface;
12
13
class NativeConsensus implements ConsensusInterface
14
{
15
    /**
16
     * @var EcAdapterInterface
17
     */
18
    private $adapter;
19
20
    /**
21
     * NativeConsensus constructor.
22
     * @param EcAdapterInterface $ecAdapter
23
     */
24 36
    public function __construct(EcAdapterInterface $ecAdapter = null)
25
    {
26 36
        $this->adapter = $ecAdapter ?: Bitcoin::getEcAdapter();
27 36
    }
28
29
    /**
30
     * @param TransactionInterface $tx
31
     * @param ScriptInterface $scriptPubKey
32
     * @param int $nInputToSign
33
     * @param int $flags
34
     * @param int $amount
35
     * @param ScriptWitnessInterface|null $witness
36
     * @return bool
37
     */
38 27
    public function verify(TransactionInterface $tx, ScriptInterface $scriptPubKey, $flags, $nInputToSign, $amount, ScriptWitnessInterface $witness = null)
39
    {
40 27
        $inputs = $tx->getInputs();
41 27
        $interpreter = new Interpreter($this->adapter);
42 27
        return $interpreter->verify(
43 27
            $inputs[$nInputToSign]->getScript(),
44 9
            $scriptPubKey,
45 9
            $flags,
46 27
            new Checker($this->adapter, $tx, $nInputToSign, $amount),
47
            $witness
48 9
        );
49
    }
50
}
51