|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Transaction; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
|
6
|
|
|
use BitWasp\Bitcoin\Serializable; |
|
7
|
|
|
use BitWasp\Bitcoin\Serializer\Transaction\TransactionOutputSerializer; |
|
8
|
|
|
use BitWasp\CommonTrait\FunctionAliasArrayAccess; |
|
9
|
|
|
|
|
10
|
|
|
class TransactionOutput extends Serializable implements TransactionOutputInterface |
|
11
|
|
|
{ |
|
12
|
|
|
use FunctionAliasArrayAccess; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string|int |
|
16
|
|
|
*/ |
|
17
|
|
|
private $value; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var ScriptInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $script; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Initialize class |
|
26
|
|
|
* |
|
27
|
|
|
* @param int $value |
|
28
|
|
|
* @param ScriptInterface $script |
|
29
|
|
|
*/ |
|
30
|
3534 |
|
public function __construct($value, ScriptInterface $script) |
|
31
|
|
|
{ |
|
32
|
3534 |
|
$this->value = $value; |
|
33
|
3534 |
|
$this->script = $script; |
|
34
|
2356 |
|
$this |
|
35
|
3534 |
|
->initFunctionAlias('value', 'getValue') |
|
36
|
3534 |
|
->initFunctionAlias('script', 'getScript'); |
|
37
|
3534 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __clone() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->script = clone $this->script; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __debugInfo() |
|
51
|
|
|
{ |
|
52
|
|
|
return [ |
|
53
|
|
|
'value' => $this->value, |
|
54
|
|
|
'script' => $this->script |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @see TransactionOutputInterface::getValue() |
|
60
|
|
|
*/ |
|
61
|
3483 |
|
public function getValue() |
|
62
|
|
|
{ |
|
63
|
3483 |
|
return $this->value; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @see TransactionOutputInterface::getScript() |
|
68
|
|
|
*/ |
|
69
|
3477 |
|
public function getScript() |
|
70
|
|
|
{ |
|
71
|
3477 |
|
return $this->script; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param TransactionOutputInterface $output |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
6 |
|
public function equals(TransactionOutputInterface $output) |
|
79
|
|
|
{ |
|
80
|
6 |
|
$script = $this->script->equals($output->getScript()); |
|
81
|
6 |
|
if (!$script) { |
|
82
|
6 |
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
6 |
|
return gmp_cmp($this->value, $output->getValue()) === 0; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @see \BitWasp\Bitcoin\SerializableInterface::getBuffer() |
|
90
|
|
|
*/ |
|
91
|
3423 |
|
public function getBuffer() |
|
92
|
|
|
{ |
|
93
|
3423 |
|
return (new TransactionOutputSerializer())->serialize($this); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|