|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script\Consensus; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Bitcoin; |
|
6
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Adapter\EcAdapterInterface; |
|
7
|
|
|
use BitWasp\Bitcoin\Script\Interpreter\Checker; |
|
8
|
|
|
use BitWasp\Bitcoin\Script\Interpreter\Interpreter; |
|
9
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
|
10
|
|
|
use BitWasp\Bitcoin\Script\ScriptWitnessInterface; |
|
11
|
|
|
use BitWasp\Bitcoin\Transaction\TransactionInterface; |
|
12
|
|
|
|
|
13
|
|
|
class NativeConsensus implements ConsensusInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var EcAdapterInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $adapter; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* NativeConsensus constructor. |
|
22
|
|
|
* @param EcAdapterInterface $ecAdapter |
|
23
|
|
|
*/ |
|
24
|
36 |
|
public function __construct(EcAdapterInterface $ecAdapter = null) |
|
25
|
|
|
{ |
|
26
|
36 |
|
$this->adapter = $ecAdapter ?: Bitcoin::getEcAdapter(); |
|
27
|
36 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param TransactionInterface $tx |
|
31
|
|
|
* @param ScriptInterface $scriptPubKey |
|
32
|
|
|
* @param int $nInputToSign |
|
33
|
|
|
* @param int $flags |
|
34
|
|
|
* @param int $amount |
|
35
|
|
|
* @param ScriptWitnessInterface|null $witness |
|
36
|
|
|
* @return bool |
|
37
|
|
|
*/ |
|
38
|
27 |
|
public function verify(TransactionInterface $tx, ScriptInterface $scriptPubKey, $flags, $nInputToSign, $amount, ScriptWitnessInterface $witness = null) |
|
39
|
|
|
{ |
|
40
|
27 |
|
$inputs = $tx->getInputs(); |
|
41
|
27 |
|
$interpreter = new Interpreter($this->adapter); |
|
42
|
27 |
|
return $interpreter->verify( |
|
43
|
27 |
|
$inputs[$nInputToSign]->getScript(), |
|
44
|
9 |
|
$scriptPubKey, |
|
45
|
9 |
|
$flags, |
|
46
|
27 |
|
new Checker($this->adapter, $tx, $nInputToSign, $amount), |
|
47
|
|
|
$witness |
|
48
|
9 |
|
); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|