Completed
Pull Request — master (#389)
by thomas
402:01 queued 399:14
created

NativeConsensus::verify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 6
dl 0
loc 12
ccs 6
cts 9
cp 0.6667
crap 1.037
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 26
    public function __construct(EcAdapterInterface $ecAdapter = null)
25
    {
26 26
        $this->adapter = $ecAdapter ?: Bitcoin::getEcAdapter();
27 26
    }
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 18
    public function verify(TransactionInterface $tx, ScriptInterface $scriptPubKey, $flags, $nInputToSign, $amount, ScriptWitnessInterface $witness = null)
39
    {
40 18
        $inputs = $tx->getInputs();
41 18
        $interpreter = new Interpreter($this->adapter);
42 18
        return $interpreter->verify(
43 18
            $inputs[$nInputToSign]->getScript(),
44
            $scriptPubKey,
45
            $flags,
46 18
            new Checker($this->adapter, $tx, $nInputToSign, $amount),
47
            $witness
48
        );
49
    }
50
}
51