Completed
Pull Request — master (#391)
by thomas
256:49 queued 254:17
created

SignData::hasRedeemScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction\Factory;
4
5
use BitWasp\Bitcoin\Script\ScriptInterface;
6
7
class SignData
8
{
9
    /**
10
     * @var ScriptInterface
11
     */
12
    protected $redeemScript = null;
13
14
    /**
15
     * @var ScriptInterface
16
     */
17
    protected $witnessScript = null;
18
19
    /**
20
     * @var int
21
     */
22
    protected $signaturePolicy = null;
23
24
    /**
25
     * @param ScriptInterface $redeemScript
26
     * @return $this
27
     */
28 24
    public function p2sh(ScriptInterface $redeemScript)
29
    {
30 24
        $this->redeemScript = $redeemScript;
31 24
        return $this;
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    public function hasRedeemScript()
38
    {
39
        return $this->redeemScript instanceof ScriptInterface;
40
    }
41
42
    /**
43
     * @return ScriptInterface
44
     */
45 24
    public function getRedeemScript()
46
    {
47 24
        if (null === $this->redeemScript) {
48
            throw new \RuntimeException('Redeem script requested but not set');
49
        }
50
51 24
        return $this->redeemScript;
52
    }
53
    /**
54
     * @param ScriptInterface $witnessScript
55
     * @return $this
56
     */
57 18
    public function p2wsh(ScriptInterface $witnessScript)
58
    {
59 18
        $this->witnessScript = $witnessScript;
60 18
        return $this;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function hasWitnessScript()
67
    {
68
        return $this->witnessScript instanceof ScriptInterface;
69
    }
70
71
    /**
72
     * @return ScriptInterface
73
     */
74 18
    public function getWitnessScript()
75
    {
76 18
        if (null === $this->witnessScript) {
77
            throw new \RuntimeException('Witness script requested but not set');
78
        }
79
80 18
        return $this->witnessScript;
81
    }
82
    
83
    /**
84
     * @param int $flags
85
     * @return $this
86
     */
87
    public function signaturePolicy($flags)
88
    {
89
        $this->signaturePolicy = $flags;
90
        return $this;
91
    }
92
93
    /**
94
     * @return bool
95
     */
96 84
    public function hasSignaturePolicy()
97
    {
98 84
        return $this->signaturePolicy !== null;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function getSignaturePolicy()
105
    {
106
        if (null === $this->signaturePolicy) {
107
            throw new \RuntimeException('Requested signature policy but not set');
108
        }
109
        return $this->signaturePolicy;
110
    }
111
}
112