|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Transaction; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Bitcoin; |
|
6
|
|
|
use BitWasp\Bitcoin\Serializer\Transaction\OutPointSerializer; |
|
7
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
|
8
|
|
|
use BitWasp\Bitcoin\Serializable; |
|
9
|
|
|
use BitWasp\Bitcoin\Serializer\Transaction\TransactionInputSerializer; |
|
10
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
11
|
|
|
|
|
12
|
|
|
class TransactionInput extends Serializable implements TransactionInputInterface |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var OutPointInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $outPoint; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ScriptInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $script; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string|int |
|
27
|
|
|
*/ |
|
28
|
|
|
private $sequence; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param OutPointInterface $outPoint |
|
32
|
|
|
* @param ScriptInterface $script |
|
33
|
|
|
* @param int $sequence |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(OutPointInterface $outPoint, ScriptInterface $script, $sequence = self::SEQUENCE_FINAL) |
|
36
|
2764 |
|
{ |
|
37
|
|
|
$this->outPoint = $outPoint; |
|
38
|
2764 |
|
$this->script = $script; |
|
39
|
2764 |
|
$this->sequence = $sequence; |
|
40
|
2764 |
|
} |
|
41
|
2764 |
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return OutPointInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getOutPoint() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->outPoint; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return ScriptInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getScript() |
|
54
|
2698 |
|
{ |
|
55
|
|
|
return $this->script; |
|
56
|
2698 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return int |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getSequence() |
|
62
|
2710 |
|
{ |
|
63
|
|
|
return $this->sequence; |
|
64
|
2710 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param TransactionInputInterface $input |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
2686 |
|
public function equals(TransactionInputInterface $input) |
|
71
|
|
|
{ |
|
72
|
2686 |
|
if (!$this->outPoint->equals($input->getOutPoint())) { |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (!$this->script->equals($input->getScript())) { |
|
77
|
|
|
return false; |
|
78
|
|
|
} |
|
79
|
48 |
|
|
|
80
|
|
|
return gmp_cmp(gmp_init($this->sequence), gmp_init($input->getSequence())) === 0; |
|
81
|
48 |
|
} |
|
82
|
12 |
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Check whether this transaction is a Coinbase transaction |
|
85
|
48 |
|
* |
|
86
|
6 |
|
* @return boolean |
|
87
|
|
|
*/ |
|
88
|
|
|
public function isCoinbase() |
|
89
|
48 |
|
{ |
|
90
|
|
|
$math = Bitcoin::getMath(); |
|
91
|
|
|
$outpoint = $this->outPoint; |
|
92
|
|
|
return $outpoint->getTxId()->getBinary() === str_pad('', 32, "\x00") |
|
93
|
|
|
&& $math->cmp(gmp_init($outpoint->getVout()), gmp_init(0xffffffff)) === 0; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
12 |
|
* @return bool |
|
98
|
|
|
*/ |
|
99
|
12 |
|
public function isFinal() |
|
100
|
12 |
|
{ |
|
101
|
12 |
|
$math = Bitcoin::getMath(); |
|
102
|
12 |
|
return $math->cmp(gmp_init($this->getSequence()), gmp_init(self::SEQUENCE_FINAL)) === 0; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return BufferInterface |
|
107
|
|
|
*/ |
|
108
|
6 |
|
public function getBuffer() |
|
109
|
|
|
{ |
|
110
|
6 |
|
return (new TransactionInputSerializer(new OutPointSerializer()))->serialize($this); |
|
111
|
6 |
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|