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

NativeConsensus   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A verify() 0 12 1
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