Completed
Pull Request — master (#446)
by thomas
228:15 queued 224:06
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
    /**
15
     * @var \BitWasp\Buffertools\Types\ByteString
16
     */
17 2692
    private $txid;
18
19 2692
    /**
20 2692
     * @var \BitWasp\Buffertools\Types\Uint32
21
     */
22
    private $vout;
23
24
    public function __construct()
25 2692
    {
26
        $this->txid = Types::bytestringle(32);
27 2692
        $this->vout = Types::uint32le();
28 2692
    }
29 2692
30 2692
    /**
31
     * @param OutPointInterface $outpoint
32
     * @return BufferInterface
33
     */
34
    public function serialize(OutPointInterface $outpoint)
35
    {
36
        return new Buffer(
37 2602
            $this->txid->write($outpoint->getTxId()) .
38
            $this->vout->write($outpoint->getVout())
39 2602
        );
40 2602
    }
41 2602
42 1301
    /**
43
     * @param Parser $parser
44
     * @return OutPointInterface
45
     */
46
    public function fromParser(Parser $parser)
47
    {
48
        return new OutPoint($this->txid->read($parser), $this->vout->read($parser));
49 198
    }
50
51 198
    /**
52
     * @param string|\BitWasp\Buffertools\BufferInterface $data
53 198
     * @return OutPointInterface
54
     */
55
    public function parse($data)
56
    {
57
        return $this->fromParser(new Parser($data));
58
    }
59
}
60