|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script\Interpreter; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
|
7
|
|
|
use BitWasp\Bitcoin\Serializer\Transaction\TransactionSerializer; |
|
8
|
|
|
use BitWasp\Bitcoin\Transaction\SignatureHash\Hasher; |
|
9
|
|
|
use BitWasp\Bitcoin\Transaction\SignatureHash\SigHash; |
|
10
|
|
|
use BitWasp\Bitcoin\Transaction\SignatureHash\V1Hasher; |
|
11
|
|
|
use BitWasp\Buffertools\Buffer; |
|
12
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
13
|
|
|
|
|
14
|
|
|
class BitcoinCashChecker extends Checker |
|
15
|
|
|
{ |
|
16
|
|
|
protected $sigHashOptionalBits = SigHash::ANYONECANPAY | SigHash::BITCOINCASH; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param ScriptInterface $script |
|
20
|
|
|
* @param int $sigHashType |
|
21
|
|
|
* @param int $sigVersion |
|
22
|
|
|
* @return BufferInterface |
|
23
|
|
|
*/ |
|
24
|
2 |
|
public function getSigHash(ScriptInterface $script, $sigHashType, $sigVersion) |
|
25
|
|
|
{ |
|
26
|
2 |
|
if ($sigVersion !== 0) { |
|
27
|
|
|
throw new \RuntimeException("SigVersion must be 0"); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
2 |
|
$cacheCheck = $sigVersion . $sigHashType . $script->getBuffer()->getBinary(); |
|
31
|
2 |
|
if (!isset($this->sigHashCache[$cacheCheck])) { |
|
32
|
2 |
|
if ($sigHashType & SigHash::BITCOINCASH) { |
|
33
|
2 |
|
$hasher = new V1Hasher($this->transaction, $this->amount); |
|
34
|
|
|
} else { |
|
35
|
|
|
if ($this->hasherV0) { |
|
36
|
|
|
$hasher = $this->hasherV0; |
|
37
|
|
|
} else { |
|
38
|
|
|
$hasher = $this->hasherV0 = new Hasher($this->transaction, new TransactionSerializer()); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
$hash = $hasher->calculate($script, $this->nInput, $sigHashType); |
|
43
|
2 |
|
$this->sigHashCache[$cacheCheck] = $hash->getBinary(); |
|
44
|
|
|
} else { |
|
45
|
|
|
$hash = new Buffer($this->sigHashCache[$cacheCheck], 32, $this->adapter->getMath()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
return $hash; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|