Completed
Push — master ( 10976f...429c59 )
by thomas
33:17 queued 09:17
created

TransactionInput   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 89.29%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 9
c 5
b 0
f 1
lcom 2
cbo 8
dl 0
loc 100
ccs 25
cts 28
cp 0.8929
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A __clone() 0 4 1
A getOutPoint() 0 4 1
A getScript() 0 4 1
A getSequence() 0 4 1
A isCoinbase() 0 7 2
A isFinal() 0 5 1
A getBuffer() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Serializer\Transaction\OutPointSerializer;
7
use BitWasp\Bitcoin\Script\Script;
8
use BitWasp\Bitcoin\Script\ScriptInterface;
9
use BitWasp\Bitcoin\Serializable;
10
use BitWasp\Bitcoin\Serializer\Transaction\TransactionInputSerializer;
11
use BitWasp\Buffertools\BufferInterface;
12
use BitWasp\CommonTrait\FunctionAliasArrayAccess;
13
14
class TransactionInput extends Serializable implements TransactionInputInterface
15
{
16
    use FunctionAliasArrayAccess;
17
18
    /**
19
     * @var OutPointInterface
20
     */
21
    private $outPoint;
22
23
    /**
24
     * @var ScriptInterface
25
     */
26
    private $script;
27
28
    /**
29
     * @var string|int
30
     */
31
    private $sequence;
32
33
    /**
34
     * @param OutPointInterface $outPoint
35
     * @param ScriptInterface $script
36
     * @param int $sequence
37
     */
38 1179
    public function __construct(OutPointInterface $outPoint, ScriptInterface $script, $sequence = self::SEQUENCE_FINAL)
39
    {
40
41 1179
        $this->outPoint = $outPoint;
42 1179
        $this->script = $script;
43 1179
        $this->sequence = $sequence;
44
45 1179
        $this
46 1179
            ->initFunctionAlias('outpoint', 'getOutPoint')
47 1179
            ->initFunctionAlias('script', 'getScript')
48 1179
            ->initFunctionAlias('sequence', 'getSequence');
49
50 1179
    }
51
52
    /**
53
     * @return TransactionInput
54
     */
55
    public function __clone()
56
    {
57
        $this->script = clone $this->script;
58
    }
59
60
    /**
61
     * @return OutPointInterface
62
     */
63 399
    public function getOutPoint()
64
    {
65 399
        return $this->outPoint;
66
    }
67
68
    /**
69
     * @return Script
70
     */
71 1047
    public function getScript()
72
    {
73 1047
        return $this->script;
74
    }
75
76
    /**
77
     * @return int
78
     */
79 387
    public function getSequence()
80
    {
81 387
        return $this->sequence;
82
    }
83
84
    /**
85
     * Check whether this transaction is a Coinbase transaction
86
     *
87
     * @return boolean
88
     */
89 12
    public function isCoinbase()
90
    {
91 12
        $math = Bitcoin::getMath();
92 12
        $outpoint = $this->outPoint;
93 12
        return $outpoint->getTxId()->getBinary() === str_pad('', 32, "\x00")
94 12
            && $math->cmp($outpoint->getVout(), $math->hexDec('ffffffff')) === 0;
95
    }
96
97
    /**
98
     * @return bool
99
     */
100 6
    public function isFinal()
101
    {
102 6
        $math = Bitcoin::getMath();
103 6
        return $math->cmp($this->getSequence(), self::SEQUENCE_FINAL) === 0;
104
    }
105
106
    /**
107
     * @return BufferInterface
108
     */
109 345
    public function getBuffer()
110
    {
111 345
        return (new TransactionInputSerializer(new OutPointSerializer()))->serialize($this);
112
    }
113
}
114