|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* User: delboy1978uk |
|
4
|
|
|
* Date: 14/08/15 |
|
5
|
|
|
* Time: 15:56 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Del; |
|
9
|
|
|
|
|
10
|
|
|
use Exception; |
|
11
|
|
|
use Del\Bitcoin\Api\Blockchain; |
|
12
|
|
|
use Del\Bitcoin\Api\Control; |
|
13
|
|
|
use Del\Bitcoin\Api\Generating; |
|
14
|
|
|
use Del\Bitcoin\Api\Mining; |
|
15
|
|
|
use Del\Bitcoin\Api\Network; |
|
16
|
|
|
use Del\Bitcoin\Api\RawTransaction; |
|
17
|
|
|
use Del\Bitcoin\Api\Utility; |
|
18
|
|
|
use Del\Bitcoin\Api\Wallet; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
class Bitcoin |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var array */ |
|
24
|
|
|
private $config; |
|
25
|
|
|
|
|
26
|
|
|
/** @var array */ |
|
27
|
|
|
private $api; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct($config = null) |
|
30
|
|
|
{ |
|
31
|
|
|
is_array($config) ? $this->setConfig($config) : null; |
|
32
|
|
|
$this->api = []; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return array |
|
38
|
|
|
* @throws \Exception |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getConfig() |
|
41
|
|
|
{ |
|
42
|
|
|
if(!is_array($this->config)) |
|
43
|
|
|
{ |
|
44
|
|
|
throw new Exception('No configuration'); |
|
45
|
|
|
} |
|
46
|
|
|
if(isset($this->config['username']) && isset($this->config['password'])) |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->config; |
|
49
|
|
|
} |
|
50
|
|
|
throw new Exception('Insufficient config data'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param array $config |
|
56
|
|
|
* @return $this |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setConfig(array $config) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->config = $config; |
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return Blockchain |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getBlockchainApi() |
|
68
|
|
|
{ |
|
69
|
|
|
if(!isset($this->api['blockchain'])){ |
|
70
|
|
|
$this->api['blockchain'] = new Blockchain($this->getConfig()); |
|
71
|
|
|
} |
|
72
|
|
|
return $this->api['blockchain']; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return Control |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getControlApi() |
|
79
|
|
|
{ |
|
80
|
|
|
if(!isset($this->api['control'])){ |
|
81
|
|
|
$this->api['control'] = new Control($this->getConfig()); |
|
82
|
|
|
} |
|
83
|
|
|
return $this->api['control']; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return Generating |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getGeneratingApi() |
|
90
|
|
|
{ |
|
91
|
|
|
if(!isset($this->api['generate'])){ |
|
92
|
|
|
$this->api['generate'] = new Generating($this->getConfig()); |
|
93
|
|
|
} |
|
94
|
|
|
return $this->api['generate']; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return Mining |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getMiningApi() |
|
101
|
|
|
{ |
|
102
|
|
|
if(!isset($this->api['mining'])){ |
|
103
|
|
|
$this->api['mining'] = new Mining($this->getConfig()); |
|
104
|
|
|
} |
|
105
|
|
|
return $this->api['mining']; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return Network |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getNetworkApi() |
|
112
|
|
|
{ |
|
113
|
|
|
if(!isset($this->api['network'])){ |
|
114
|
|
|
$this->api['network'] = new Network($this->getConfig()); |
|
115
|
|
|
} |
|
116
|
|
|
return $this->api['network']; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return RawTransaction |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getRawTransactionApi() |
|
123
|
|
|
{ |
|
124
|
|
|
if(!isset($this->api['raw_transaction'])){ |
|
125
|
|
|
$this->api['raw_transaction'] = new RawTransaction($this->getConfig()); |
|
126
|
|
|
} |
|
127
|
|
|
return $this->api['raw_transaction']; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return Utility |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getUtilityApi() |
|
134
|
|
|
{ |
|
135
|
|
|
if(!isset($this->api['utility'])){ |
|
136
|
|
|
$this->api['utility'] = new Utility($this->getConfig()); |
|
137
|
|
|
} |
|
138
|
|
|
return $this->api['utility']; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return Wallet |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getWalletApi() |
|
145
|
|
|
{ |
|
146
|
|
|
if(!isset($this->api['wallet'])){ |
|
147
|
|
|
$this->api['wallet'] = new Wallet($this->getConfig()); |
|
148
|
|
|
} |
|
149
|
|
|
return $this->api['wallet']; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
} |