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

NestedP2shP2wshScriptDecorator::convertKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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