|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Serializer\Transaction; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Serializer\Types; |
|
6
|
|
|
use BitWasp\Buffertools\Buffer; |
|
7
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
8
|
|
|
use BitWasp\Buffertools\Parser; |
|
9
|
|
|
use BitWasp\Bitcoin\Script\Script; |
|
10
|
|
|
use BitWasp\Bitcoin\Transaction\TransactionInput; |
|
11
|
|
|
use BitWasp\Bitcoin\Transaction\TransactionInputInterface; |
|
12
|
|
|
|
|
13
|
|
|
class TransactionInputSerializer |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var OutPointSerializer |
|
17
|
|
|
*/ |
|
18
|
|
|
private $outpointSerializer; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* TransactionInputSerializer constructor. |
|
22
|
|
|
* @param OutPointSerializerInterface $outPointSerializer |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(OutPointSerializerInterface $outPointSerializer) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->outpointSerializer = $outPointSerializer; |
|
|
|
|
|
|
27
|
|
|
$this->varstring = Types::varstring(); |
|
|
|
|
|
|
28
|
|
|
$this->uint32le = Types::uint32le(); |
|
|
|
|
|
|
29
|
2692 |
|
} |
|
30
|
|
|
|
|
31
|
2692 |
|
/** |
|
32
|
2692 |
|
* @param TransactionInputInterface $input |
|
33
|
2692 |
|
* @return BufferInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
public function serialize(TransactionInputInterface $input) |
|
36
|
|
|
{ |
|
37
|
|
|
return new Buffer( |
|
38
|
2692 |
|
$this->outpointSerializer->serialize($input->getOutPoint())->getBinary() . |
|
39
|
|
|
$this->varstring->write($input->getScript()->getBuffer()) . |
|
40
|
2692 |
|
$this->uint32le->write($input->getSequence()) |
|
41
|
2692 |
|
); |
|
42
|
2692 |
|
} |
|
43
|
2692 |
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param Parser $parser |
|
46
|
|
|
* @return TransactionInput |
|
47
|
|
|
* @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange |
|
48
|
|
|
*/ |
|
49
|
|
|
public function fromParser(Parser $parser) |
|
50
|
2602 |
|
{ |
|
51
|
|
|
return new TransactionInput( |
|
52
|
2602 |
|
$this->outpointSerializer->fromParser($parser), |
|
53
|
2602 |
|
new Script($this->varstring->read($parser)), |
|
54
|
2602 |
|
$this->uint32le->read($parser) |
|
55
|
2602 |
|
); |
|
56
|
2602 |
|
} |
|
57
|
1301 |
|
|
|
58
|
1301 |
|
/** |
|
59
|
|
|
* @param BufferInterface|string $string |
|
60
|
|
|
* @return TransactionInput |
|
61
|
|
|
* @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange |
|
62
|
|
|
*/ |
|
63
|
|
|
public function parse($string) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->fromParser(new Parser($string)); |
|
66
|
198 |
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.