Completed
Pull Request — master (#285)
by thomas
21:56
created

PayToPubkeyHash::checkInvolvesKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\ScriptInfo;
4
5
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface;
6
use BitWasp\Bitcoin\Script\Classifier\OutputClassifier;
7
use BitWasp\Bitcoin\Script\ScriptInterface;
8
use BitWasp\Buffertools\BufferInterface;
9
10
class PayToPubkeyHash implements ScriptInfoInterface
11
{
12
13
    /**
14
     * @var BufferInterface
15
     */
16
    private $hash;
17
18
    /**
19
     * @param ScriptInterface $script
20
     */
21
    public function __construct(ScriptInterface $script)
22
    {
23
        $chunks = $script->getScriptParser()->decode();
24
        if (count($chunks) < 5 || !$chunks[2]->isPush()) {
25
            throw new \RuntimeException('Malformed pay-to-pubkey-hash script');
26
        }
27
28
        /** @var BufferInterface $hash */
29
        $hash = $chunks[2]->getData();
30
        $this->hash = $hash;
31
    }
32
33
    /**
34
     * @return int
35
     */
36
    public function getRequiredSigCount()
37
    {
38
        return 1;
39
    }
40
41
    /**
42
     * @return int
43
     */
44
    public function getKeyCount()
45
    {
46
        return 1;
47
    }
48
49
    /**
50
     * @param PublicKeyInterface $publicKey
51
     * @return bool
52
     */
53
    public function checkInvolvesKey(PublicKeyInterface $publicKey)
54
    {
55
        return $publicKey->getPubKeyHash()->getBinary() === $this->hash->getBinary();
56
    }
57
58
    /**
59
     * @return PublicKeyInterface[]
60
     */
61
    public function getKeys()
62
    {
63
        return [];
64
    }
65
}
66