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