Completed
Pull Request — master (#593)
by thomas
15:02
created

ScriptWitness::getBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Script;
6
7
use BitWasp\Bitcoin\Collection\StaticBufferCollection;
8
use BitWasp\Bitcoin\Serializer\Script\ScriptWitnessSerializer;
9
use BitWasp\Buffertools\BufferInterface;
10
11
class ScriptWitness extends StaticBufferCollection implements ScriptWitnessInterface
12
{
13
    /**
14
     * @param ScriptWitnessInterface $witness
15
     * @return bool
16
     */
17
    public function equals(ScriptWitnessInterface $witness): bool
18
    {
19
        $nStack = count($this);
20
        if ($nStack !== count($witness)) {
21
            return false;
22
        }
23
24
        for ($i = 0; $i < $nStack; $i++) {
25
            if (false === $this->offsetGet($i)->equals($witness->offsetGet($i))) {
26
                return false;
27
            }
28
        }
29
30
        return true;
31
    }
32
33
    /**
34
     * @return \BitWasp\Buffertools\BufferInterface
35
     */
36
    public function getBuffer(): BufferInterface
37
    {
38
        return (new ScriptWitnessSerializer())->serialize($this);
39
    }
40
}
41