1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Transaction\Mutator; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Collection\MutableCollection; |
6
|
|
|
use BitWasp\Bitcoin\Collection\Transaction\TransactionInputCollection; |
7
|
|
|
use BitWasp\Bitcoin\Collection\Transaction\TransactionWitnessCollection; |
8
|
|
|
use BitWasp\Bitcoin\Script\ScriptWitnessInterface; |
9
|
|
|
use BitWasp\Bitcoin\Transaction\TransactionInputInterface; |
10
|
|
|
|
11
|
|
|
class WitnessCollectionMutator extends MutableCollection |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param ScriptWitnessInterface[] $inputs |
16
|
|
|
*/ |
17
|
|
|
public function __construct(array $inputs) |
18
|
|
|
{ |
19
|
|
|
/** @var InputMutator[] $set */ |
20
|
|
|
$set = []; |
21
|
|
|
foreach ($inputs as $i => $input) { |
22
|
|
|
$set[$i] = new InputMutator($input); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$this->set = \SplFixedArray::fromArray($set); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return InputMutator |
30
|
|
|
*/ |
31
|
|
|
public function current() |
32
|
|
|
{ |
33
|
|
|
return $this->set->current(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param int $offset |
38
|
|
|
* @return InputMutator |
39
|
|
|
*/ |
40
|
|
|
public function offsetGet($offset) |
41
|
|
|
{ |
42
|
|
|
if (!$this->set->offsetExists($offset)) { |
43
|
|
|
throw new \OutOfRangeException('Input does not exist'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this->set->offsetGet($offset); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return TransactionWitnessCollection |
51
|
|
|
*/ |
52
|
|
|
public function done() |
53
|
|
|
{ |
54
|
|
|
$set = []; |
55
|
|
|
foreach ($this->set as $mutator) { |
56
|
|
|
$set[] = $mutator->done(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return new TransactionWitnessCollection($set); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int|string $start |
64
|
|
|
* @param int|string $length |
65
|
|
|
* @return $this |
66
|
|
|
*/ |
67
|
|
|
public function slice($start, $length) |
68
|
|
|
{ |
69
|
|
|
$end = $this->set->getSize(); |
70
|
|
|
if ($start > $end || $length > $end) { |
71
|
|
|
throw new \RuntimeException('Invalid start or length'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->set = \SplFixedArray::fromArray(array_slice($this->set->toArray(), $start, $length)); |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
|
|
public function null() |
82
|
|
|
{ |
83
|
|
|
$this->slice(0, 0); |
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param ScriptWitnessInterface $witness |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
|
|
public function add(ScriptWitnessInterface $witness) |
92
|
|
|
{ |
93
|
|
|
$size = $this->set->getSize(); |
94
|
|
|
$this->set->setSize($size + 1); |
95
|
|
|
|
96
|
|
|
$this->set[$size] = new InputMutator($witness); |
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param int $i |
102
|
|
|
* @param ScriptWitnessInterface $input |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function set($i, ScriptWitnessInterface $input) |
106
|
|
|
{ |
107
|
|
|
$this->set[$i] = new InputMutator($input); |
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: