1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script\Interpreter; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
6
|
|
|
use BitWasp\Bitcoin\Serializer\Transaction\TransactionSerializer; |
7
|
|
|
use BitWasp\Bitcoin\Transaction\SignatureHash\Hasher; |
8
|
|
|
use BitWasp\Bitcoin\Transaction\SignatureHash\SigHash; |
9
|
|
|
use BitWasp\Bitcoin\Transaction\SignatureHash\V1Hasher; |
10
|
|
|
use BitWasp\Buffertools\Buffer; |
11
|
|
|
use BitWasp\Buffertools\BufferInterface; |
12
|
|
|
|
13
|
|
|
class BitcoinCashChecker extends Checker |
14
|
|
|
{ |
15
|
|
|
protected $sigHashOptionalBits = SigHash::ANYONECANPAY | SigHash::BITCOINCASH; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param ScriptInterface $script |
19
|
|
|
* @param int $sigHashType |
20
|
|
|
* @param int $sigVersion |
21
|
|
|
* @return BufferInterface |
22
|
|
|
*/ |
23
|
2 |
|
public function getSigHash(ScriptInterface $script, $sigHashType, $sigVersion) |
24
|
|
|
{ |
25
|
2 |
|
if ($sigVersion !== 0) { |
26
|
|
|
throw new \RuntimeException("SigVersion must be 0"); |
27
|
|
|
} |
28
|
|
|
|
29
|
2 |
|
$cacheCheck = $sigVersion . $sigHashType . $script->getBuffer()->getBinary(); |
30
|
2 |
|
if (!isset($this->sigHashCache[$cacheCheck])) { |
31
|
2 |
|
if ($sigHashType & SigHash::BITCOINCASH) { |
32
|
2 |
|
$hasher = new V1Hasher($this->transaction, $this->amount); |
33
|
|
|
} else { |
34
|
|
|
if ($this->hasherV0) { |
35
|
|
|
$hasher = $this->hasherV0; |
36
|
|
|
} else { |
37
|
|
|
$hasher = $this->hasherV0 = new Hasher($this->transaction, new TransactionSerializer()); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
2 |
|
$hash = $hasher->calculate($script, $this->nInput, $sigHashType); |
42
|
2 |
|
$this->sigHashCache[$cacheCheck] = $hash->getBinary(); |
43
|
|
|
} else { |
44
|
|
|
$hash = new Buffer($this->sigHashCache[$cacheCheck], 32, $this->adapter->getMath()); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
return $hash; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.