Completed
Pull Request — 0.0.35 (#659)
by thomas
30:11 queued 21:19
created

P2shScriptDecorator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A convertKey() 0 9 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Key\KeyToScript\Decorator;
4
5
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\KeyInterface;
6
use BitWasp\Bitcoin\Key\KeyToScript\ScriptAndSignData;
7
use BitWasp\Bitcoin\Script\P2shScript;
8
use BitWasp\Bitcoin\Script\ScriptType;
9
use BitWasp\Bitcoin\Transaction\Factory\SignData;
10
11
class P2shScriptDecorator extends ScriptHashDecorator
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $allowedScriptTypes = [
17
        ScriptType::P2PKH,
18
        ScriptType::P2PK,
19
        ScriptType::P2WKH,
20
    ];
21
22
    /**
23
     * @var string
24
     */
25
    protected $decorateType = ScriptType::P2SH;
26
27
    /**
28
     * @param KeyInterface $key
29
     * @return ScriptAndSignData
30
     * @throws \BitWasp\Bitcoin\Exceptions\P2shScriptException
31
     */
32 4
    public function convertKey(KeyInterface $key)
33
    {
34 4
        $redeemScript = new P2shScript($this->scriptDataFactory->convertKey($key)->getScriptPubKey());
35 4
        return new ScriptAndSignData(
36 4
            $redeemScript->getOutputScript(),
37 4
            (new SignData())
38 4
                ->p2sh($redeemScript)
39
        );
40
    }
41
}
42