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