Completed
Pull Request — master (#446)
by thomas
103:28 queued 33:23
created

OutPointSerializer::getTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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
    private $txid;
15
    private $vout;
16
17 2692
    public function __construct()
18
    {
19 2692
        $this->txid = Types::bytestringle(32);
20 2692
        $this->vout = Types::uint32le();
21
    }
22
23
    /**
24
     * @param OutPointInterface $outpoint
25 2692
     * @return BufferInterface
26
     */
27 2692
    public function serialize(OutPointInterface $outpoint)
28 2692
    {
29 2692
        return new Buffer(
30 2692
            $this->txid->write($outpoint->getTxId()) .
31
            $this->vout->write($outpoint->getVout())
32
        );
33
    }
34
35
    /**
36
     * @param Parser $parser
37 2602
     * @return OutPointInterface
38
     */
39 2602
    public function fromParser(Parser $parser)
40 2602
    {
41 2602
        return new OutPoint($this->txid->read($parser), $this->vout->read($parser));
42 1301
    }
43
44
    /**
45
     * @param string|\BitWasp\Buffertools\BufferInterface $data
46
     * @return OutPointInterface
47
     */
48
    public function parse($data)
49 198
    {
50
        return $this->fromParser(new Parser($data));
51 198
    }
52
}
53