Completed
Push — master ( bb8b5d...7f2cd3 )
by thomas
23:00
created

OutPointSerializer::parse()   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 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace BitWasp\Bitcoin\Serializer\Transaction;
4
5
use BitWasp\Bitcoin\Serializer\Types;
6
use BitWasp\Bitcoin\Transaction\OutPoint;
7
use BitWasp\Bitcoin\Transaction\OutPointInterface;
8
use BitWasp\Buffertools\Buffer;
9
use BitWasp\Buffertools\BufferInterface;
10
use BitWasp\Buffertools\Parser;
11
12
class OutPointSerializer implements OutPointSerializerInterface
13
{
14
    /**
15
     * @var \BitWasp\Buffertools\Types\ByteString
16
     */
17
    private $txid;
18
19
    /**
20
     * @var \BitWasp\Buffertools\Types\Uint32
21
     */
22
    private $vout;
23
24 1338
    public function __construct()
25
    {
26 1338
        $this->txid = Types::bytestringle(32);
27 1338
        $this->vout = Types::uint32le();
28 1338
    }
29
30
    /**
31
     * @param OutPointInterface $outpoint
32
     * @return BufferInterface
33
     */
34 1308
    public function serialize(OutPointInterface $outpoint)
35
    {
36 1308
        return new Buffer(
37 1308
            $this->txid->write($outpoint->getTxId()) .
38 1308
            $this->vout->write($outpoint->getVout())
39
        );
40
    }
41
42
    /**
43
     * @param Parser $parser
44
     * @return OutPointInterface
45
     */
46 68
    public function fromParser(Parser $parser)
47
    {
48 68
        return new OutPoint($this->txid->read($parser), $this->vout->read($parser));
49
    }
50
51
    /**
52
     * @param string|\BitWasp\Buffertools\BufferInterface $data
53
     * @return OutPointInterface
54
     */
55 2
    public function parse($data)
56
    {
57 2
        return $this->fromParser(new Parser($data));
58
    }
59
}
60