|
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
|
1350 |
|
public function __construct(array $inputs = []) |
|
16
|
|
|
{ |
|
17
|
1350 |
|
$this->set = new \SplFixedArray(count($inputs)); |
|
18
|
1350 |
|
foreach ($inputs as $idx => $input) { |
|
19
|
1116 |
|
if (!$input instanceof TransactionInputInterface) { |
|
20
|
6 |
|
throw new \InvalidArgumentException('Must provide TransactionInputInterface[] to TransactionInputCollection'); |
|
21
|
|
|
} |
|
22
|
1110 |
|
$this->set->offsetSet($idx, $input); |
|
23
|
1344 |
|
} |
|
24
|
1344 |
|
} |
|
25
|
|
|
|
|
26
|
126 |
|
public function __clone() |
|
27
|
|
|
{ |
|
28
|
126 |
|
$inputs = $this->set; |
|
29
|
126 |
|
$this->set = new \SplFixedArray(count($inputs)); |
|
30
|
|
|
|
|
31
|
126 |
|
foreach ($inputs as $idx => $input) { |
|
32
|
108 |
|
$this->set->offsetSet($idx, $input); |
|
33
|
126 |
|
} |
|
34
|
126 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return TransactionInputInterface[] |
|
38
|
|
|
*/ |
|
39
|
330 |
|
public function all() |
|
40
|
|
|
{ |
|
41
|
330 |
|
return $this->set->toArray(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return TransactionInputInterface |
|
46
|
|
|
*/ |
|
47
|
72 |
|
public function current() |
|
48
|
|
|
{ |
|
49
|
72 |
|
return $this->set->current(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param int $offset |
|
54
|
|
|
* @return TransactionInputInterface |
|
55
|
|
|
*/ |
|
56
|
822 |
|
public function offsetGet($offset) |
|
57
|
|
|
{ |
|
58
|
822 |
|
if (!$this->set->offsetExists($offset)) { |
|
59
|
12 |
|
throw new \OutOfRangeException('No offset found'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
810 |
|
return $this->set->offsetGet($offset); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|