1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Collection\StaticCollection; |
6
|
|
|
use BitWasp\Buffertools\BufferInterface; |
7
|
|
|
|
8
|
|
|
class ScriptWitness extends StaticCollection |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* ScriptWitness constructor. |
12
|
|
|
* @param BufferInterface[] $sigValues |
13
|
|
|
*/ |
14
|
|
|
public function __construct(array $sigValues) |
15
|
|
|
{ |
16
|
|
|
$this->set = new \SplFixedArray(count($sigValues)); |
17
|
|
|
foreach ($sigValues as $idx => $push) { |
18
|
|
|
if (!$push instanceof BufferInterface) { |
19
|
|
|
throw new \InvalidArgumentException('Must provide BufferInterface[] to ScriptWitness'); |
20
|
|
|
} |
21
|
|
|
$this->set->offsetSet($idx, $push); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function __clone() |
26
|
|
|
{ |
27
|
|
|
$outputs = $this->set; |
28
|
|
|
$this->set = new \SplFixedArray(count($outputs)); |
29
|
|
|
|
30
|
|
|
foreach ($outputs as $idx => $output) { |
31
|
|
|
$this->set->offsetSet($idx, $output); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return BufferInterface |
37
|
|
|
*/ |
38
|
|
|
public function current() |
39
|
|
|
{ |
40
|
|
|
return $this->set->current(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param int $offset |
45
|
|
|
* @return BufferInterface |
46
|
|
|
*/ |
47
|
|
|
public function offsetGet($offset) |
48
|
|
|
{ |
49
|
|
|
if (!$this->set->offsetExists($offset)) { |
50
|
|
|
throw new \OutOfRangeException('No offset found'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->set->offsetGet($offset); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $start |
58
|
|
|
* @param int $length |
59
|
|
|
* @return ScriptWitness |
60
|
|
|
*/ |
61
|
|
|
public function slice($start, $length) |
62
|
|
|
{ |
63
|
|
|
$end = $this->set->getSize(); |
64
|
|
|
if ($start > $end || $length > $end) { |
65
|
|
|
throw new \RuntimeException('Invalid start or length'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$sliced = array_slice($this->set->toArray(), $start, $length); |
69
|
|
|
return new self($sliced); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|