1 | <?php |
||
17 | class V1Hasher extends SigHash |
||
18 | { |
||
19 | /** |
||
20 | * @var TransactionInterface |
||
21 | */ |
||
22 | protected $transaction; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | protected $amount; |
||
28 | |||
29 | /** |
||
30 | * @var TransactionOutputSerializer |
||
31 | */ |
||
32 | protected $outputSerializer; |
||
33 | |||
34 | /** |
||
35 | * @var TransactionOutputSerializer |
||
36 | */ |
||
37 | protected $outpointSerializer; |
||
38 | |||
39 | /** |
||
40 | * V1Hasher constructor. |
||
41 | * @param TransactionInterface $transaction |
||
42 | * @param int $amount |
||
43 | * @param OutPointSerializerInterface $outpointSerializer |
||
44 | * @param TransactionOutputSerializer|null $outputSerializer |
||
45 | */ |
||
46 | 48 | public function __construct( |
|
57 | |||
58 | /** |
||
59 | * @param int $sighashType |
||
60 | * @return BufferInterface |
||
61 | */ |
||
62 | 48 | public function hashPrevOuts(int $sighashType): BufferInterface |
|
63 | { |
||
64 | 48 | if (!($sighashType & SigHash::ANYONECANPAY)) { |
|
65 | 48 | $binary = ''; |
|
66 | 48 | foreach ($this->tx->getInputs() as $input) { |
|
67 | 48 | $binary .= $this->outpointSerializer->serialize($input->getOutPoint())->getBinary(); |
|
68 | } |
||
69 | 48 | return Hash::sha256d(new Buffer($binary)); |
|
70 | } |
||
71 | |||
72 | return new Buffer('', 32); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param int $sighashType |
||
77 | * @return BufferInterface |
||
78 | */ |
||
79 | 48 | public function hashSequences(int $sighashType): BufferInterface |
|
80 | { |
||
81 | 48 | if (!($sighashType & SigHash::ANYONECANPAY) && ($sighashType & 0x1f) !== SigHash::SINGLE && ($sighashType & 0x1f) !== SigHash::NONE) { |
|
82 | 48 | $binary = ''; |
|
83 | 48 | foreach ($this->tx->getInputs() as $input) { |
|
84 | 48 | $binary .= pack('V', $input->getSequence()); |
|
85 | } |
||
86 | |||
87 | 48 | return Hash::sha256d(new Buffer($binary)); |
|
88 | } |
||
89 | |||
90 | return new Buffer('', 32); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param int $sighashType |
||
95 | * @param int $inputToSign |
||
96 | * @return BufferInterface |
||
97 | */ |
||
98 | 48 | public function hashOutputs(int $sighashType, int $inputToSign): BufferInterface |
|
99 | { |
||
100 | 48 | if (($sighashType & 0x1f) !== SigHash::SINGLE && ($sighashType & 0x1f) !== SigHash::NONE) { |
|
101 | 48 | $binary = ''; |
|
102 | 48 | foreach ($this->tx->getOutputs() as $output) { |
|
103 | 48 | $binary .= $this->outputSerializer->serialize($output)->getBinary(); |
|
104 | } |
||
105 | 48 | return Hash::sha256d(new Buffer($binary)); |
|
106 | } elseif (($sighashType & 0x1f) === SigHash::SINGLE && $inputToSign < count($this->tx->getOutputs())) { |
||
107 | return Hash::sha256d($this->outputSerializer->serialize($this->tx->getOutput($inputToSign))); |
||
108 | } |
||
109 | |||
110 | return new Buffer('', 32); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Calculate the hash of the current transaction, when you are looking to |
||
115 | * spend $txOut, and are signing $inputToSign. The SigHashType defaults to |
||
116 | * SIGHASH_ALL |
||
117 | * |
||
118 | * @param ScriptInterface $txOutScript |
||
119 | * @param int $inputToSign |
||
120 | * @param int $sighashType |
||
121 | * @return BufferInterface |
||
122 | * @throws \Exception |
||
123 | */ |
||
124 | 48 | public function calculate( |
|
152 | } |
||
153 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..