Completed
Pull Request — master (#591)
by thomas
22:54 queued 09:12
created

BitcoinConsensus   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A verify() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Script\Consensus;
6
7
use BitWasp\Bitcoin\Script\Consensus\Exception\BitcoinConsensusException;
8
use BitWasp\Bitcoin\Script\Interpreter\InterpreterInterface;
9
use BitWasp\Bitcoin\Script\ScriptInterface;
10
use BitWasp\Bitcoin\Transaction\TransactionInterface;
11
12
class BitcoinConsensus implements ConsensusInterface
13
{
14
    /**
15
     * @param TransactionInterface $tx
16
     * @param ScriptInterface $scriptPubKey
17
     * @param int $flags
18
     * @param int $nInputToSign
19
     * @param int $amount
20
     * @return bool
21
     * @throws BitcoinConsensusException
22
     */
23 500
    public function verify(TransactionInterface $tx, ScriptInterface $scriptPubKey, int $flags, int $nInputToSign, int $amount): bool
24
    {
25 500
        if ($flags !== ($flags & BITCOINCONSENSUS_VERIFY_ALL)) {
26 1
            throw new BitcoinConsensusException("Invalid flags for bitcoinconsensus");
27
        }
28
29 499
        $error = 0;
30 499
        if ($flags & InterpreterInterface::VERIFY_WITNESS) {
31 163
            $verify = (bool) bitcoinconsensus_verify_script_with_amount($scriptPubKey->getBinary(), $amount, $tx->getBinary(), $nInputToSign, $flags, $error);
32
        } else {
33 336
            $verify = (bool) bitcoinconsensus_verify_script($scriptPubKey->getBinary(), $tx->getBaseSerialization()->getBinary(), $nInputToSign, $flags, $error);
34
        }
35
36 499
        return $verify;
37
    }
38
}
39