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

PayToPubkeyHash   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 56
ccs 0
cts 25
cp 0
rs 10
c 5
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getRequiredSigCount() 0 4 1
A getKeyCount() 0 4 1
A checkInvolvesKey() 0 4 1
A getKeys() 0 4 1
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