1 | <?php |
||
13 | class TransactionInputSerializer |
||
14 | { |
||
15 | /** |
||
16 | * @var OutPointSerializer |
||
17 | */ |
||
18 | private $outpointSerializer; |
||
19 | |||
20 | /** |
||
21 | * TransactionInputSerializer constructor. |
||
22 | * @param OutPointSerializer $outPointSerializer |
||
23 | */ |
||
24 | 345 | public function __construct(OutPointSerializer $outPointSerializer) |
|
25 | { |
||
26 | 345 | $this->outpointSerializer = $outPointSerializer; |
|
27 | 345 | } |
|
28 | |||
29 | /** |
||
30 | * @return \BitWasp\Buffertools\Template |
||
31 | */ |
||
32 | 321 | private function getInputTemplate() |
|
33 | { |
||
34 | 321 | return (new TemplateFactory()) |
|
35 | 321 | ->varstring() |
|
36 | 321 | ->uint32le() |
|
37 | 321 | ->getTemplate(); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param TransactionInputInterface $input |
||
42 | * @return Buffer |
||
43 | */ |
||
44 | 291 | public function serialize(TransactionInputInterface $input) |
|
45 | { |
||
46 | 291 | return Buffertools::concat( |
|
47 | 291 | $this->outpointSerializer->serialize($input->getOutPoint()), |
|
48 | 291 | $this->getInputTemplate()->write([ |
|
49 | 291 | $input->getScript()->getBuffer(), |
|
50 | 291 | $input->getSequence() |
|
51 | 291 | ]) |
|
52 | 291 | ); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param Parser $parser |
||
57 | * @return TransactionInput |
||
58 | * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange |
||
59 | */ |
||
60 | 240 | public function fromParser(Parser $parser) |
|
76 | |||
77 | /** |
||
78 | * @param $string |
||
79 | * @return TransactionInput |
||
80 | * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange |
||
81 | */ |
||
82 | 12 | public function parse($string) |
|
87 | } |
||
88 |