Completed
Pull Request — master (#518)
by thomas
58:22 queued 55:50
created

PayToPubkey::getKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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