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