|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Collection\StaticCollection; |
|
6
|
|
|
use BitWasp\Bitcoin\Serializer\Script\ScriptWitnessSerializer; |
|
7
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
8
|
|
|
|
|
9
|
|
|
class ScriptWitness extends StaticCollection implements ScriptWitnessInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* ScriptWitness constructor. |
|
13
|
|
|
* @param BufferInterface[] $sigValues |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct(array $sigValues) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->set = new \SplFixedArray(count($sigValues)); |
|
18
|
|
|
foreach ($sigValues as $idx => $push) { |
|
19
|
|
|
if (!$push instanceof BufferInterface) { |
|
20
|
|
|
throw new \InvalidArgumentException('Must provide BufferInterface[] to ScriptWitness'); |
|
21
|
|
|
} |
|
22
|
|
|
$this->set->offsetSet($idx, $push); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function __clone() |
|
27
|
|
|
{ |
|
28
|
|
|
$outputs = $this->set; |
|
29
|
|
|
$this->set = new \SplFixedArray(count($outputs)); |
|
30
|
|
|
|
|
31
|
|
|
foreach ($outputs as $idx => $output) { |
|
32
|
|
|
$this->set->offsetSet($idx, $output); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return BufferInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
public function bottom() |
|
40
|
|
|
{ |
|
41
|
|
|
return parent::offsetGet(count($this) - 1); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return BufferInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
public function current() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->set->current(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param int $offset |
|
54
|
|
|
* @return BufferInterface |
|
55
|
|
|
*/ |
|
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
|
|
|
/** |
|
66
|
|
|
* @param int $start |
|
67
|
|
|
* @param int $length |
|
68
|
|
|
* @return ScriptWitness |
|
69
|
|
|
*/ |
|
70
|
|
|
public function slice($start, $length) |
|
71
|
|
|
{ |
|
72
|
|
|
$end = $this->set->getSize(); |
|
73
|
|
|
if ($start > $end || $length > $end) { |
|
74
|
|
|
throw new \RuntimeException('Invalid start or length'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$sliced = array_slice($this->set->toArray(), $start, $length); |
|
78
|
|
|
return new self($sliced); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return \BitWasp\Buffertools\BufferInterface |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getBuffer() |
|
85
|
|
|
{ |
|
86
|
|
|
return (new ScriptWitnessSerializer())->serialize($this); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.