1 | <?php |
||
17 | class TxSignerContext |
||
18 | { |
||
19 | /** |
||
20 | * @var \BitWasp\Bitcoin\Script\ScriptInfo\ScriptInfoInterface |
||
21 | */ |
||
22 | private $scriptInfo; |
||
23 | |||
24 | /** |
||
25 | * @var null|ScriptInterface |
||
26 | */ |
||
27 | private $redeemScript; |
||
28 | |||
29 | /** |
||
30 | * @var ScriptInterface |
||
31 | */ |
||
32 | private $prevOutScript; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $prevOutType; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $scriptType; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | private $signatures = []; |
||
48 | |||
49 | /** |
||
50 | * @var PublicKeyInterface[] |
||
51 | */ |
||
52 | private $publicKeys = []; |
||
53 | |||
54 | /** |
||
55 | * @var EcAdapterInterface |
||
56 | */ |
||
57 | private $ecAdapter; |
||
58 | |||
59 | /** |
||
60 | * @param EcAdapterInterface $ecAdapter |
||
61 | * @param ScriptInterface $outputScript |
||
62 | * @param ScriptInterface $redeemScript |
||
63 | */ |
||
64 | public function __construct( |
||
65 | 129 | EcAdapterInterface $ecAdapter, |
|
66 | ScriptInterface $outputScript, |
||
67 | ScriptInterface $redeemScript = null |
||
68 | ) { |
||
69 | $handler = ScriptFactory::info($outputScript, $redeemScript); |
||
70 | $this->scriptType = $this->prevOutType = $handler->classification(); |
||
71 | if ($handler instanceof ScriptHash) { |
||
72 | $this->scriptType = $handler->getInfo()->classification(); |
||
73 | } |
||
74 | |||
75 | // Gather public keys from redeemScript / outputScript |
||
76 | $this->ecAdapter = $ecAdapter; |
||
77 | $this->redeemScript = $redeemScript; |
||
78 | $this->prevOutScript = $outputScript; |
||
79 | $this->scriptInfo = $handler; |
||
80 | |||
81 | // According to scriptType, extract public keys |
||
82 | $this->publicKeys = $this->scriptInfo->getKeys(); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | 129 | * @return ScriptInterface |
|
87 | 117 | * @throws \RuntimeException |
|
88 | 117 | */ |
|
89 | 36 | public function getRedeemScript() |
|
90 | 36 | { |
|
91 | if (null === $this->redeemScript) { |
||
92 | throw new \RuntimeException('No redeem script was set'); |
||
93 | 117 | } |
|
94 | 117 | ||
95 | 117 | return $this->redeemScript; |
|
96 | 117 | } |
|
97 | |||
98 | /** |
||
99 | 117 | * |
|
100 | 117 | * @return string |
|
101 | */ |
||
102 | public function getPrevOutType() |
||
103 | { |
||
104 | return $this->prevOutType; |
||
105 | } |
||
106 | 36 | ||
107 | /** |
||
108 | 36 | * @return string |
|
109 | 6 | */ |
|
110 | public function getScriptType() |
||
111 | { |
||
112 | 30 | return $this->scriptType; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * @return array|\BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface[] |
||
117 | */ |
||
118 | public function getPublicKeys() |
||
122 | |||
123 | /** |
||
124 | * @return array |
||
125 | */ |
||
126 | public function getSignatures() |
||
130 | |||
131 | /** |
||
132 | * @param integer $idx |
||
133 | * @param TransactionSignatureInterface $signature |
||
134 | * @return $this |
||
135 | */ |
||
136 | 39 | public function setSignature($idx, TransactionSignatureInterface $signature = null) |
|
141 | |||
142 | /** |
||
143 | * @param PublicKeyInterface[] $publicKeys |
||
144 | * @return $this |
||
145 | */ |
||
146 | 87 | public function setPublicKeys(array $publicKeys) |
|
151 | |||
152 | /** |
||
153 | * @param TransactionInterface $tx |
||
154 | 69 | * @param int $inputToExtract |
|
155 | * @return $this |
||
156 | 69 | */ |
|
157 | public function extractSigs(TransactionInterface $tx, $inputToExtract) |
||
217 | 6 | ||
218 | /** |
||
219 | 6 | * @return \BitWasp\Bitcoin\Script\Script |
|
220 | 6 | */ |
|
221 | 6 | public function regenerateScript() |
|
226 | 6 | ||
227 | 6 | /** |
|
228 | * @return int |
||
229 | 6 | */ |
|
230 | public function getRequiredSigCount() |
||
234 | 6 | ||
235 | 6 | /** |
|
236 | 6 | * @return int |
|
237 | */ |
||
238 | public function getSigCount() |
||
242 | 6 | ||
243 | 6 | /** |
|
244 | 6 | * @return bool |
|
245 | 6 | */ |
|
246 | public function isFullySigned() |
||
251 | } |
||
252 |