1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Stratum\Api; |
4
|
|
|
|
5
|
|
|
use BitWasp\Stratum\Connection; |
6
|
|
|
|
7
|
|
|
class MiningClient |
8
|
|
|
{ |
9
|
|
|
const MINING_SUBSCRIBE = 'mining.subscribe'; |
10
|
|
|
const SET_DIFFICULTY = 'mining.set_difficulty'; |
11
|
|
|
const NOTIFY = 'mining.notify'; |
12
|
|
|
const AUTHORIZE = 'mining.authorize'; |
13
|
|
|
const SUBMIT = 'mining.submit'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var Connection |
17
|
|
|
*/ |
18
|
|
|
private $conn; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* MiningServer constructor. |
22
|
|
|
* @param Connection $connection |
23
|
|
|
*/ |
24
|
3 |
|
public function __construct(Connection $connection) |
25
|
|
|
{ |
26
|
3 |
|
$this->conn = $connection; |
27
|
3 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return \React\Promise\Promise|\React\Promise\PromiseInterface |
31
|
|
|
*/ |
32
|
1 |
|
public function subscribeMining() |
33
|
|
|
{ |
34
|
1 |
|
return $this->conn->request(self::MINING_SUBSCRIBE); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $user |
39
|
|
|
* @param string $password |
40
|
|
|
* @return \React\Promise\Promise|\React\Promise\PromiseInterface |
41
|
|
|
*/ |
42
|
1 |
|
public function authorize($user, $password) |
43
|
|
|
{ |
44
|
1 |
|
return $this->conn->request(self::AUTHORIZE, [$user, $password]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $worker_name |
49
|
|
|
* @param string $job_id |
50
|
|
|
* @param int $extranonce2 |
51
|
|
|
* @param int $ntime |
52
|
|
|
* @param int $nonce |
53
|
|
|
* @return \React\Promise\Promise|\React\Promise\PromiseInterface |
54
|
|
|
*/ |
55
|
1 |
|
public function submit($worker_name, $job_id, $extranonce2, $ntime, $nonce) |
56
|
|
|
{ |
57
|
1 |
|
return $this->conn->request(self::SUBMIT, [$worker_name, $job_id, $extranonce2, $ntime, $nonce]); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|