1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Crypto\EcAdapter\Adapter\EcAdapterInterface; |
6
|
|
|
use BitWasp\Bitcoin\Flags; |
7
|
|
|
use BitWasp\Bitcoin\Script\Consensus\BitcoinConsensus; |
8
|
|
|
use BitWasp\Bitcoin\Script\Consensus\ConsensusInterface; |
9
|
|
|
use BitWasp\Bitcoin\Script\Consensus\NativeConsensus; |
10
|
|
|
use BitWasp\Bitcoin\Script\Interpreter\InterpreterInterface; |
11
|
|
|
|
12
|
|
|
class ConsensusFactory |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var EcAdapterInterface |
16
|
|
|
*/ |
17
|
|
|
private $ecAdapter; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param EcAdapterInterface $ecAdapter |
21
|
|
|
*/ |
22
|
30 |
|
public function __construct(EcAdapterInterface $ecAdapter) |
23
|
|
|
{ |
24
|
30 |
|
$this->ecAdapter = $ecAdapter; |
25
|
30 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param $int |
29
|
|
|
* @return Flags |
30
|
|
|
*/ |
31
|
30 |
|
public function flags($int) |
32
|
|
|
{ |
33
|
30 |
|
return new Flags($int); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return Flags |
38
|
|
|
*/ |
39
|
24 |
|
public function defaultFlags() |
40
|
|
|
{ |
41
|
24 |
|
return $this->flags( |
42
|
24 |
|
InterpreterInterface::VERIFY_P2SH | InterpreterInterface::VERIFY_STRICTENC | InterpreterInterface::VERIFY_DERSIG | |
43
|
24 |
|
InterpreterInterface::VERIFY_LOW_S | InterpreterInterface::VERIFY_NULL_DUMMY | InterpreterInterface::VERIFY_SIGPUSHONLY | |
44
|
24 |
|
InterpreterInterface::VERIFY_DISCOURAGE_UPGRADABLE_NOPS | InterpreterInterface::VERIFY_CLEAN_STACK |
45
|
24 |
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param Flags $flags |
50
|
|
|
* @return NativeConsensus |
51
|
|
|
*/ |
52
|
12 |
|
public function getNativeConsensus(Flags $flags) |
53
|
|
|
{ |
54
|
12 |
|
return new NativeConsensus($this->ecAdapter, $flags); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param Flags $flags |
59
|
|
|
* @return BitcoinConsensus |
60
|
|
|
*/ |
61
|
|
|
public function getBitcoinConsensus(Flags $flags) |
62
|
|
|
{ |
63
|
|
|
return new BitcoinConsensus($flags); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Flags $flags |
68
|
|
|
* @return ConsensusInterface |
69
|
|
|
*/ |
70
|
6 |
|
public function getConsensus(Flags $flags) |
71
|
|
|
{ |
72
|
6 |
|
if (extension_loaded('bitcoinconsensus')) { |
73
|
|
|
return $this->getBitcoinConsensus($flags); |
74
|
|
|
} else { |
75
|
6 |
|
return $this->getNativeConsensus($flags); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|