Completed
Push — master ( 4ca74a...73e746 )
by thomas
14s
created

TransactionOutput::getBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Script\ScriptInterface;
6
use BitWasp\Bitcoin\Serializable;
7
use BitWasp\Bitcoin\Serializer\Transaction\TransactionOutputSerializer;
8
9
class TransactionOutput extends Serializable implements TransactionOutputInterface
10
{
11
12
    /**
13
     * @var string|int
14
     */
15
    private $value;
16
17
    /**
18
     * @var ScriptInterface
19
     */
20
    private $script;
21
22
    /**
23
     * Initialize class
24
     *
25
     * @param int $value
26
     * @param ScriptInterface $script
27
     */
28 2668
    public function __construct($value, ScriptInterface $script)
29
    {
30 2668
        $this->value = $value;
31 2668
        $this->script = $script;
32 2668
    }
33
34
    /**
35
     * @see TransactionOutputInterface::getValue()
36
     */
37
    public function getValue()
38
    {
39
        return $this->value;
40
    }
41
42
    /**
43
     * @see TransactionOutputInterface::getScript()
44
     */
45 2818
    public function getScript()
46
    {
47 2818
        return $this->script;
48
    }
49
50
    /**
51
     * @param TransactionOutputInterface $output
52
     * @return bool
53 2806
     */
54
    public function equals(TransactionOutputInterface $output)
55 2806
    {
56
        $script = $this->script->equals($output->getScript());
57
        if (!$script) {
58
            return false;
59
        }
60
61
        return gmp_cmp($this->value, $output->getValue()) === 0;
62 48
    }
63
64 48
    /**
65 48
     * @see \BitWasp\Bitcoin\SerializableInterface::getBuffer()
66 12
     */
67
    public function getBuffer()
68
    {
69 48
        return (new TransactionOutputSerializer())->serialize($this);
70
    }
71
}
72