Completed
Pull Request — 0.0.35 (#659)
by thomas
25:58
created

NestedP2shP2wshScriptDecorator   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
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\Script\WitnessScript;
10
use BitWasp\Bitcoin\Transaction\Factory\SignData;
11
12
class NestedP2shP2wshScriptDecorator extends ScriptHashDecorator
13
{
14
    /**
15
     * @var string[]
16
     */
17
    protected $allowedScriptTypes = [
18
        ScriptType::P2PKH,
19
        ScriptType::P2PK,
20
    ];
21
22
    /**
23
     * @var string
24
     */
25
    protected $decorateType = "scripthash|witness_v0_scripthash";
26
27
    /**
28
     * @param KeyInterface $key
29
     * @return ScriptAndSignData
30
     * @throws \BitWasp\Bitcoin\Exceptions\P2shScriptException
31
     * @throws \BitWasp\Bitcoin\Exceptions\WitnessScriptException
32
     */
33 2
    public function convertKey(KeyInterface $key)
34
    {
35 2
        $witnessScript = new WitnessScript($this->scriptDataFactory->convertKey($key)->getScriptPubKey());
36 2
        $redeemScript = new P2shScript($witnessScript);
37 2
        return new ScriptAndSignData(
38 2
            $redeemScript->getOutputScript(),
39 2
            (new SignData())
40 2
                ->p2sh($redeemScript)
41 2
                ->p2wsh($witnessScript)
42
        );
43
    }
44
}
45