forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionOutput.php
80 lines (68 loc) · 1.75 KB
/
TransactionOutput.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace BitWasp\Bitcoin\Transaction;
use BitWasp\Bitcoin\Script\ScriptInterface;
use BitWasp\Bitcoin\Serializable;
use BitWasp\Bitcoin\Serializer\Transaction\TransactionOutputSerializer;
use BitWasp\Buffertools\BufferInterface;
class TransactionOutput extends Serializable implements TransactionOutputInterface
{
/**
* @var int
*/
private $value;
/**
* @var ScriptInterface
*/
private $script;
/**
* Initialize class
*
* @param int $value
* @param ScriptInterface $script
*/
public function __construct(int $value, ScriptInterface $script)
{
if ($value < 0) {
throw new \RuntimeException('Transaction output value cannot be negative');
}
$this->value = $value;
$this->script = $script;
}
/**
* {@inheritdoc}
* @see TransactionOutputInterface::getValue()
*/
public function getValue(): int
{
return $this->value;
}
/**
* {@inheritdoc}
* @see TransactionOutputInterface::getScript()
*/
public function getScript(): ScriptInterface
{
return $this->script;
}
/**
* {@inheritdoc}
* @see TransactionOutputInterface::equals()
*/
public function equals(TransactionOutputInterface $output): bool
{
$script = $this->script->equals($output->getScript());
if (!$script) {
return false;
}
return gmp_cmp($this->value, $output->getValue()) === 0;
}
/**
* {@inheritdoc}
* @see \BitWasp\Bitcoin\SerializableInterface::getBuffer()
*/
public function getBuffer(): BufferInterface
{
return (new TransactionOutputSerializer())->serialize($this);
}
}