Completed
Push — 0.0.35 ( b2fc74...d8d049 )
by thomas
28:12 queued 09:10
created

BitcoinConsensus   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
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
namespace BitWasp\Bitcoin\Script\Consensus;
4
5
use BitWasp\Bitcoin\Script\Consensus\Exception\BitcoinConsensusException;
6
use BitWasp\Bitcoin\Script\Interpreter\InterpreterInterface;
7
use BitWasp\Bitcoin\Script\ScriptInterface;
8
use BitWasp\Bitcoin\Transaction\TransactionInterface;
9
10
class BitcoinConsensus implements ConsensusInterface
11
{
12
    /**
13
     * @param TransactionInterface $tx
14
     * @param ScriptInterface $scriptPubKey
15
     * @param int $nInputToSign
16
     * @param int $flags
17
     * @param int $amount
18
     * @return bool
19
     */
20 477
    public function verify(TransactionInterface $tx, ScriptInterface $scriptPubKey, $flags, $nInputToSign, $amount)
21
    {
22 477
        if ($flags !== ($flags & BITCOINCONSENSUS_VERIFY_ALL)) {
23 1
            throw new BitcoinConsensusException("Invalid flags for bitcoinconsensus");
24
        }
25
26 476
        $error = 0;
27 476
        if ($flags & InterpreterInterface::VERIFY_WITNESS) {
28 140
            $verify = (bool) bitcoinconsensus_verify_script_with_amount($scriptPubKey->getBinary(), $amount, $tx->getBinary(), $nInputToSign, $flags, $error);
29
        } else {
30 336
            $verify = (bool) bitcoinconsensus_verify_script($scriptPubKey->getBinary(), $tx->getBaseSerialization()->getBinary(), $nInputToSign, $flags, $error);
31
        }
32
33 476
        return $verify;
34
    }
35
}
36