1 | <?php |
||
11 | class TxMutator |
||
12 | { |
||
13 | /** |
||
14 | * @var TransactionInterface |
||
15 | */ |
||
16 | private $transaction; |
||
17 | |||
18 | /** |
||
19 | * @var InputCollectionMutator |
||
20 | */ |
||
21 | private $inputsMutator; |
||
22 | |||
23 | /** |
||
24 | * @var OutputCollectionMutator |
||
25 | */ |
||
26 | private $outputsMutator; |
||
27 | |||
28 | /** |
||
29 | * @param TransactionInterface $transaction |
||
30 | */ |
||
31 | 56 | public function __construct(TransactionInterface $transaction) |
|
35 | |||
36 | /** |
||
37 | * @return InputCollectionMutator |
||
38 | */ |
||
39 | 50 | public function inputsMutator() |
|
40 | { |
||
41 | 50 | if (null === $this->inputsMutator) { |
|
42 | 50 | $this->inputsMutator = new InputCollectionMutator($this->transaction->getInputs()); |
|
43 | } |
||
44 | |||
45 | 50 | return $this->inputsMutator; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return OutputCollectionMutator |
||
50 | */ |
||
51 | public function outputsMutator() |
||
52 | { |
||
53 | if (null === $this->outputsMutator) { |
||
54 | $this->outputsMutator = new OutputCollectionMutator($this->transaction->getOutputs()); |
||
55 | } |
||
56 | |||
57 | return $this->outputsMutator; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return TransactionInterface |
||
62 | */ |
||
63 | 54 | public function done() |
|
64 | { |
||
65 | 54 | if (null !== $this->inputsMutator) { |
|
66 | 50 | $this->inputs($this->inputsMutator->done()); |
|
67 | } |
||
68 | |||
69 | 54 | if (null !== $this->outputsMutator) { |
|
70 | $this->outputs($this->outputsMutator->done()); |
||
71 | } |
||
72 | |||
73 | 54 | return $this->transaction; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param array $array |
||
78 | * @return $this |
||
79 | */ |
||
80 | 54 | private function replace(array $array = []) |
|
81 | { |
||
82 | 54 | $this->transaction = new Transaction( |
|
83 | 54 | array_key_exists('version', $array) ? $array['version'] : $this->transaction->getVersion(), |
|
84 | 54 | array_key_exists('inputs', $array) ? $array['inputs'] : $this->transaction->getInputs(), |
|
85 | 54 | array_key_exists('outputs', $array) ? $array['outputs'] : $this->transaction->getOutputs(), |
|
86 | 54 | array_key_exists('witness', $array) ? $array['witness'] : $this->transaction->getWitnesses(), |
|
87 | 54 | array_key_exists('nLockTime', $array) ? $array['nLockTime'] : $this->transaction->getLockTime() |
|
88 | ); |
||
89 | |||
90 | 54 | return $this; |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param int $nVersion |
||
95 | * @return $this |
||
96 | */ |
||
97 | 2 | public function version($nVersion) |
|
101 | |||
102 | /** |
||
103 | * @param TransactionInputInterface[] $inputCollection |
||
104 | * @return $this |
||
105 | */ |
||
106 | 54 | public function inputs(array $inputCollection) |
|
110 | |||
111 | /** |
||
112 | * @param TransactionOutputInterface[] $outputCollection |
||
113 | * @return $this |
||
114 | */ |
||
115 | 4 | public function outputs(array $outputCollection) |
|
119 | |||
120 | /** |
||
121 | * @param ScriptWitnessInterface[] $witnessCollection |
||
122 | * @return $this |
||
123 | */ |
||
124 | 52 | public function witness(array $witnessCollection) |
|
128 | |||
129 | /** |
||
130 | * @param int $locktime |
||
131 | * @return $this |
||
132 | */ |
||
133 | 2 | public function locktime($locktime) |
|
137 | } |
||
138 |