Completed
Pull Request — master (#403)
by thomas
31:50
created

BitcoinConsensus   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A verify() 0 11 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Consensus;
4
5
use BitWasp\Bitcoin\Script\Interpreter\InterpreterInterface;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
use BitWasp\Bitcoin\Transaction\TransactionInterface;
8
9
class BitcoinConsensus implements ConsensusInterface
10
{
11
    /**
12
     * @param TransactionInterface $tx
13
     * @param ScriptInterface $scriptPubKey
14
     * @param int $nInputToSign
15
     * @param int $flags
16
     * @param int $amount
17
     * @return bool
18
     */
19 102
    public function verify(TransactionInterface $tx, ScriptInterface $scriptPubKey, $flags, $nInputToSign, $amount)
20
    {
21 102
        $error = 0;
22 102
        if ($flags & InterpreterInterface::VERIFY_WITNESS) {
23 48
            $verify = (bool) bitcoinconsensus_verify_script_with_amount($scriptPubKey->getBinary(), $amount, $tx->getWitnessBuffer()->getBinary(), $nInputToSign, $flags, $error);
24 16
        } else {
25 57
            $verify = (bool) bitcoinconsensus_verify_script($scriptPubKey->getBinary(), $tx->getBinary(), $nInputToSign, $flags, $error);
26
        }
27
28 102
        return $verify;
29
    }
30
}
31