|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Script\Opcodes; |
|
6
|
|
|
use BitWasp\Bitcoin\Script\P2shScript; |
|
7
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface; |
|
8
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
|
9
|
|
|
|
|
10
|
|
|
class P2shScriptFactory |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var OutputScriptFactory |
|
14
|
|
|
*/ |
|
15
|
|
|
private $scriptPubKey; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Opcodes |
|
19
|
|
|
*/ |
|
20
|
|
|
private $opcodes; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* P2shScriptFactory constructor. |
|
24
|
|
|
* @param OutputScriptFactory $scriptPubKey |
|
25
|
|
|
* @param Opcodes $opcodes |
|
26
|
|
|
*/ |
|
27
|
42 |
|
public function __construct(OutputScriptFactory $scriptPubKey, Opcodes $opcodes) |
|
28
|
|
|
{ |
|
29
|
42 |
|
$this->scriptPubKey = $scriptPubKey; |
|
30
|
42 |
|
$this->opcodes = $opcodes; |
|
31
|
42 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Parse a ScriptInterface into a RedeemScript |
|
35
|
|
|
* |
|
36
|
|
|
* @param ScriptInterface $script |
|
37
|
|
|
* @return P2shScript |
|
38
|
|
|
*/ |
|
39
|
|
|
public function parse(ScriptInterface $script) |
|
40
|
|
|
{ |
|
41
|
|
|
return new P2shScript($script, $this->opcodes); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Create a multisig P2SH Script |
|
46
|
|
|
* |
|
47
|
|
|
* @param int $m |
|
48
|
|
|
* @param array $keys |
|
49
|
|
|
* @param bool|true $sort |
|
50
|
|
|
* @return P2shScript |
|
51
|
|
|
*/ |
|
52
|
42 |
|
public function multisig($m, array $keys, $sort = true) |
|
53
|
|
|
{ |
|
54
|
42 |
|
return new P2shScript($this->scriptPubKey->multisig($m, $keys, $sort), $this->opcodes); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Create a pay-to-pubkey P2SH Script |
|
59
|
|
|
* |
|
60
|
|
|
* @param PublicKeyInterface $publicKey |
|
61
|
|
|
* @return P2shScript |
|
62
|
|
|
*/ |
|
63
|
|
|
public function payToPubKey(PublicKeyInterface $publicKey) |
|
64
|
|
|
{ |
|
65
|
|
|
return new P2shScript($this->scriptPubKey->payToPubKey($publicKey), $this->opcodes); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Create a pay-to-pubkey-hash P2SH Script |
|
70
|
|
|
* |
|
71
|
|
|
* @param PublicKeyInterface $publicKey |
|
72
|
|
|
* @return P2shScript |
|
73
|
|
|
*/ |
|
74
|
|
|
public function payToPubKeyHash(PublicKeyInterface $publicKey) |
|
75
|
|
|
{ |
|
76
|
|
|
return new P2shScript($this->scriptPubKey->payToPubKeyHash($publicKey), $this->opcodes); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|