Completed
Pull Request — master (#403)
by thomas
73:13 queued 70:38
created

SignData::hasSignaturePolicy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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