1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script\ScriptInfo; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Key\PublicKeyFactory; |
6
|
|
|
use BitWasp\Bitcoin\Script\Classifier\OutputClassifier; |
7
|
|
|
use BitWasp\Bitcoin\Script\Script; |
8
|
|
|
use BitWasp\Bitcoin\Script\ScriptFactory; |
9
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
10
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface; |
11
|
|
|
use BitWasp\Bitcoin\Signature\TransactionSignatureInterface; |
12
|
|
|
|
13
|
|
|
class PayToPubkey implements ScriptInfoInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var ScriptInterface |
17
|
|
|
*/ |
18
|
|
|
private $script; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var PublicKeyInterface |
22
|
|
|
*/ |
23
|
|
|
private $publicKey; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param ScriptInterface $script |
27
|
|
|
*/ |
28
|
24 |
|
public function __construct(ScriptInterface $script) |
29
|
|
|
{ |
30
|
24 |
|
$this->script = $script; |
31
|
24 |
|
$chunks = $script->getScriptParser()->decode(); |
32
|
24 |
|
if (count($chunks) < 1 || !$chunks[0]->isPush()) { |
33
|
|
|
throw new \InvalidArgumentException('Malformed pay-to-pubkey script'); |
34
|
|
|
} |
35
|
24 |
|
$this->publicKey = PublicKeyFactory::fromHex($chunks[0]->getData()); |
36
|
24 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
24 |
|
public function classification() |
42
|
|
|
{ |
43
|
24 |
|
return OutputClassifier::PAYTOPUBKEY; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return int |
48
|
|
|
*/ |
49
|
24 |
|
public function getRequiredSigCount() |
50
|
|
|
{ |
51
|
24 |
|
return 1; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return int |
56
|
|
|
*/ |
57
|
|
|
public function getKeyCount() |
58
|
|
|
{ |
59
|
|
|
return 1; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param PublicKeyInterface $publicKey |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function checkInvolvesKey(PublicKeyInterface $publicKey) |
67
|
|
|
{ |
68
|
|
|
return $publicKey->getBinary() === $this->publicKey->getBinary(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return PublicKeyInterface[] |
73
|
|
|
*/ |
74
|
24 |
|
public function getKeys() |
75
|
|
|
{ |
76
|
24 |
|
return [$this->publicKey]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param TransactionSignatureInterface[] $signatures |
81
|
|
|
* @param PublicKeyInterface[] $publicKeys |
82
|
|
|
* @return Script|ScriptInterface |
83
|
|
|
*/ |
84
|
12 |
|
public function makeScriptSig(array $signatures = [], array $publicKeys = []) |
85
|
|
|
{ |
86
|
12 |
|
$newScript = new Script(); |
87
|
12 |
|
if (count($signatures) === $this->getRequiredSigCount()) { |
88
|
12 |
|
$newScript = ScriptFactory::sequence([$signatures[0]->getBuffer()]); |
89
|
12 |
|
} |
90
|
|
|
|
91
|
12 |
|
return $newScript; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|