1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Transaction\Mutator; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
6
|
|
|
use BitWasp\Bitcoin\Transaction\OutPoint; |
7
|
|
|
use BitWasp\Bitcoin\Transaction\OutPointInterface; |
8
|
|
|
use BitWasp\Bitcoin\Transaction\TransactionInput; |
9
|
|
|
use BitWasp\Bitcoin\Transaction\TransactionInputInterface; |
10
|
|
|
use BitWasp\Buffertools\Buffer; |
11
|
|
|
|
12
|
|
|
class InputMutator |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var TransactionInputInterface |
16
|
|
|
*/ |
17
|
|
|
private $input; |
18
|
|
|
|
19
|
118 |
|
/** |
20
|
|
|
* @param TransactionInputInterface $input |
21
|
118 |
|
*/ |
22
|
118 |
|
public function __construct(TransactionInputInterface $input) |
23
|
|
|
{ |
24
|
|
|
$this->input = $input; |
25
|
|
|
} |
26
|
|
|
|
27
|
106 |
|
/** |
28
|
|
|
* @return TransactionInputInterface |
29
|
106 |
|
*/ |
30
|
|
|
public function done() |
31
|
|
|
{ |
32
|
|
|
return $this->input; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
112 |
|
* @param array $array |
37
|
|
|
* @return $this |
38
|
112 |
|
*/ |
39
|
112 |
|
private function replace(array $array = []) |
40
|
112 |
|
{ |
41
|
112 |
|
$this->input = new TransactionInput( |
42
|
112 |
|
array_key_exists('outpoint', $array) ? $array['outpoint'] : $this->input->getOutPoint(), |
43
|
112 |
|
array_key_exists('script', $array) ? $array['script'] : $this->input->getScript(), |
44
|
|
|
array_key_exists('nSequence', $array) ? $array['nSequence'] : $this->input->getSequence() |
45
|
112 |
|
); |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
6 |
|
* @param OutPointInterface $outPoint |
52
|
|
|
* @return InputMutator |
53
|
6 |
|
*/ |
54
|
|
|
public function outpoint(OutPointInterface $outPoint) |
55
|
|
|
{ |
56
|
|
|
return $this->replace(array('outpoint' => $outPoint)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
6 |
|
/** |
61
|
|
|
* @return $this |
62
|
6 |
|
*/ |
63
|
|
|
public function null() |
64
|
|
|
{ |
65
|
|
|
return $this->replace(array('outpoint' => new OutPoint(new Buffer(str_pad('', 32, "\x00"), 32), 0xffffffff))); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
12 |
|
* @param Buffer $txid |
70
|
|
|
* @return $this |
71
|
12 |
|
*/ |
72
|
|
|
public function txid(Buffer $txid) |
73
|
|
|
{ |
74
|
|
|
return $this->replace(array('txid' => $txid)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
106 |
|
* @param int $vout |
79
|
|
|
* @return InputMutator |
80
|
106 |
|
*/ |
81
|
|
|
public function vout($vout) |
82
|
|
|
{ |
83
|
|
|
return $this->replace(array('vout' => $vout)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
12 |
|
* @param ScriptInterface $script |
88
|
|
|
* @return $this |
89
|
12 |
|
*/ |
90
|
|
|
public function script(ScriptInterface $script) |
91
|
|
|
{ |
92
|
|
|
return $this->replace(array('script' => $script)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param int $nSequence |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function sequence($nSequence) |
100
|
|
|
{ |
101
|
|
|
return $this->replace(array('nSequence' => $nSequence)); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|