Completed
Pull Request — master (#446)
by thomas
105:00 queued 101:56
created

TransactionOutput::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
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 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 1336
    public function __construct($value, ScriptInterface $script)
29
    {
30 1336
        if ($value < 0) {
31
            throw new \RuntimeException('Transaction output value cannot be negative');
32
        }
33 1336
        $this->value = $value;
34 1336
        $this->script = $script;
35 1336
    }
36
37
    /**
38
     * {@inheritdoc}
39
     * @see TransactionOutputInterface::getValue()
40
     */
41 1392
    public function getValue()
42
    {
43 1392
        return $this->value;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     * @see TransactionOutputInterface::getScript()
49
     */
50 1388
    public function getScript()
51
    {
52 1388
        return $this->script;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     * @see TransactionOutputInterface::equals()
58
     */
59 16
    public function equals(TransactionOutputInterface $output)
60
    {
61 16
        $script = $this->script->equals($output->getScript());
62 16
        if (!$script) {
63 4
            return false;
64
        }
65
66 16
        return gmp_cmp($this->value, $output->getValue()) === 0;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     * @see \BitWasp\Bitcoin\SerializableInterface::getBuffer()
72
     */
73 2
    public function getBuffer()
74
    {
75 2
        return (new TransactionOutputSerializer())->serialize($this);
76
    }
77
}
78