Completed
Push — master ( 883b2a...6b2c83 )
by thomas
44:21 queued 41:03
created

OutPoint   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 3
Metric Value
wmc 7
c 6
b 0
f 3
lcom 1
cbo 5
dl 0
loc 71
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getTxId() 0 4 1
A getVout() 0 4 1
A equals() 0 9 2
A getBuffer() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Serializable;
6
use BitWasp\Bitcoin\Serializer\Transaction\OutPointSerializer;
7
use BitWasp\Buffertools\BufferInterface;
8
use BitWasp\CommonTrait\FunctionAliasArrayAccess;
9
10
class OutPoint extends Serializable implements OutPointInterface
11
{
12
    use FunctionAliasArrayAccess;
13
14
    /**
15
     * @var BufferInterface
16
     */
17
    private $hashPrevOutput;
18
19
    /**
20
     * @var int
21
     */
22
    private $nPrevOutput;
23
24
    /**
25
     * OutPoint constructor.
26
     * @param BufferInterface $hashPrevOutput
27
     * @param int $nPrevOutput
28
     */
29 1158
    public function __construct(BufferInterface $hashPrevOutput, $nPrevOutput)
30
    {
31 1158
        if ($hashPrevOutput->getSize() !== 32) {
32 6
            throw new \InvalidArgumentException('OutPoint: hashPrevOut must be a 32-byte Buffer');
33
        }
34
        
35 1152
        $this->hashPrevOutput = $hashPrevOutput;
36 1152
        $this->nPrevOutput = $nPrevOutput;
37
38 1152
        $this
39 1152
            ->initFunctionAlias('txid', 'getTxId')
40 1152
            ->initFunctionAlias('vout', 'getVout');
41 1152
    }
42
43
    /**
44
     * @return BufferInterface
45
     */
46 360
    public function getTxId()
47
    {
48 360
        return $this->hashPrevOutput;
49
    }
50
51
    /**
52
     * @return int
53
     */
54 366
    public function getVout()
55
    {
56 366
        return $this->nPrevOutput;
57
    }
58
59
    /**
60
     * @param OutPointInterface $outPoint
61
     * @return int
62
     */
63 18
    public function equals(OutPointInterface $outPoint)
64
    {
65 18
        $txid = strcmp($this->getTxId()->getBinary(), $outPoint->getTxId()->getBinary());
66 18
        if ($txid !== 0) {
67 12
            return false;
68
        }
69
70 18
        return gmp_cmp($this->getVout(), $outPoint->getVout()) === 0;
71
    }
72
73
    /**
74
     * @return BufferInterface
75
     */
76 72
    public function getBuffer()
77
    {
78 72
        return (new OutPointSerializer())->serialize($this);
79
    }
80
}
81