|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Transaction; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Serializable; |
|
6
|
|
|
use BitWasp\Bitcoin\Serializer\Transaction\OutPointSerializer; |
|
7
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
8
|
|
|
use BitWasp\CommonTrait\FunctionAliasArrayAccess; |
|
9
|
|
|
|
|
10
|
|
|
class OutPoint extends Serializable implements OutPointInterface |
|
11
|
|
|
{ |
|
12
|
|
|
use FunctionAliasArrayAccess; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var BufferInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
private $hashPrevOutput; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var int |
|
21
|
|
|
*/ |
|
22
|
|
|
private $nPrevOutput; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* OutPoint constructor. |
|
26
|
|
|
* @param BufferInterface $hashPrevOutput |
|
27
|
|
|
* @param int $nPrevOutput |
|
28
|
|
|
*/ |
|
29
|
3864 |
|
public function __construct(BufferInterface $hashPrevOutput, $nPrevOutput) |
|
30
|
|
|
{ |
|
31
|
3864 |
|
if ($hashPrevOutput->getSize() !== 32) { |
|
32
|
3 |
|
throw new \InvalidArgumentException('OutPoint: hashPrevOut must be a 32-byte Buffer'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
3861 |
|
$this->hashPrevOutput = $hashPrevOutput; |
|
36
|
3861 |
|
$this->nPrevOutput = $nPrevOutput; |
|
37
|
|
|
|
|
38
|
2574 |
|
$this |
|
39
|
3861 |
|
->initFunctionAlias('txid', 'getTxId') |
|
40
|
3861 |
|
->initFunctionAlias('vout', 'getVout'); |
|
41
|
3861 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __debugInfo() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'txid' => $this->hashPrevOutput, |
|
50
|
|
|
'vout' => $this->nPrevOutput, |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return BufferInterface |
|
56
|
|
|
*/ |
|
57
|
3453 |
|
public function getTxId() |
|
58
|
|
|
{ |
|
59
|
3453 |
|
return $this->hashPrevOutput; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return int |
|
64
|
|
|
*/ |
|
65
|
3456 |
|
public function getVout() |
|
66
|
|
|
{ |
|
67
|
3456 |
|
return $this->nPrevOutput; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param OutPointInterface $outPoint |
|
72
|
|
|
* @return int |
|
73
|
|
|
*/ |
|
74
|
9 |
|
public function equals(OutPointInterface $outPoint) |
|
75
|
|
|
{ |
|
76
|
9 |
|
$txid = strcmp($this->getTxId()->getBinary(), $outPoint->getTxId()->getBinary()); |
|
77
|
9 |
|
if ($txid !== 0) { |
|
78
|
6 |
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
9 |
|
return gmp_cmp($this->getVout(), $outPoint->getVout()) === 0; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return BufferInterface |
|
86
|
|
|
*/ |
|
87
|
96 |
|
public function getBuffer() |
|
88
|
|
|
{ |
|
89
|
96 |
|
return (new OutPointSerializer())->serialize($this); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|