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

BitcoinConsensus::verify()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 5
dl 0
loc 15
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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