1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Collection\Transaction; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Collection\StaticCollection; |
6
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
7
|
|
|
use BitWasp\Bitcoin\Script\ScriptWitnessInterface; |
8
|
|
|
|
9
|
|
|
class TransactionWitnessCollection extends StaticCollection |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Initialize a new collection with a list of Inputs. |
13
|
|
|
* |
14
|
|
|
* @param ScriptWitnessInterface[] $vScriptWitness |
15
|
|
|
*/ |
16
|
1278 |
|
public function __construct(array $vScriptWitness = []) |
17
|
|
|
{ |
18
|
1278 |
|
$this->set = new \SplFixedArray(count($vScriptWitness)); |
19
|
|
|
|
20
|
1278 |
|
foreach ($vScriptWitness as $idx => $input) { |
21
|
84 |
|
if (!$input instanceof ScriptWitnessInterface) { |
22
|
|
|
throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection'); |
23
|
|
|
} |
24
|
|
|
|
25
|
84 |
|
$this->set->offsetSet($idx, $input); |
26
|
1278 |
|
} |
27
|
1278 |
|
} |
28
|
|
|
|
29
|
|
|
public function __clone() |
30
|
|
|
{ |
31
|
|
|
$inputs = $this->set; |
32
|
|
|
$this->set = new \SplFixedArray(count($inputs)); |
33
|
|
|
|
34
|
|
|
foreach ($inputs as $idx => $input) { |
35
|
|
|
$this->set->offsetSet($idx, $input); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return ScriptWitnessInterface[] |
41
|
|
|
*/ |
42
|
|
|
public function all() |
43
|
|
|
{ |
44
|
|
|
return $this->set->toArray(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return ScriptWitnessInterface |
49
|
|
|
*/ |
50
|
54 |
|
public function current() |
51
|
|
|
{ |
52
|
54 |
|
return $this->set->current(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param int $offset |
57
|
|
|
* @return ScriptWitnessInterface |
58
|
|
|
*/ |
59
|
54 |
|
public function offsetGet($offset) |
60
|
|
|
{ |
61
|
54 |
|
if (!$this->set->offsetExists($offset)) { |
62
|
|
|
throw new \OutOfRangeException('No offset found'); |
63
|
|
|
} |
64
|
|
|
|
65
|
54 |
|
return $this->set->offsetGet($offset); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|