Completed
Push — master ( abcf31...a8a46d )
by thomas
28:08 queued 25:46
created

P2shP2wshScriptDecorator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

1 Method

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