|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Stratum\Notification; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Stratum\Api\ElectrumClient; |
|
6
|
|
|
use BitWasp\Stratum\Request\Request; |
|
7
|
|
|
|
|
8
|
|
|
class HeadersNotification implements NotificationInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var int |
|
12
|
|
|
*/ |
|
13
|
|
|
private $version; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $prevBlock; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $merkleRoot; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var int |
|
27
|
|
|
*/ |
|
28
|
|
|
private $timestamp; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var int |
|
32
|
|
|
*/ |
|
33
|
|
|
private $bits; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var int |
|
37
|
|
|
*/ |
|
38
|
|
|
private $nonce; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var int |
|
42
|
|
|
*/ |
|
43
|
|
|
private $height; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $utxoRoot; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* HeadersNotification constructor. |
|
52
|
|
|
* @param int $nonce |
|
53
|
|
|
* @param string $prevBlock |
|
54
|
|
|
* @param int $timestamp |
|
55
|
|
|
* @param string $merkleroot |
|
56
|
|
|
* @param int $height |
|
57
|
|
|
* @param string $utxoRoot |
|
58
|
|
|
* @param int $version |
|
59
|
|
|
* @param int $bits |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function __construct($nonce, $prevBlock, $timestamp, $merkleroot, $height, $utxoRoot, $version, $bits) |
|
62
|
|
|
{ |
|
63
|
3 |
|
$this->nonce = $nonce; |
|
64
|
3 |
|
$this->prevBlock = $prevBlock; |
|
65
|
3 |
|
$this->timestamp = $timestamp; |
|
66
|
3 |
|
$this->merkleRoot = $merkleroot; |
|
67
|
3 |
|
$this->height = $height; |
|
68
|
3 |
|
$this->utxoRoot = $utxoRoot; |
|
69
|
3 |
|
$this->version = $version; |
|
70
|
3 |
|
$this->bits = $bits; |
|
71
|
3 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return int |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function getVersion() |
|
77
|
|
|
{ |
|
78
|
1 |
|
return $this->version; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function getPrevBlock() |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->prevBlock; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function getMerkleRoot() |
|
93
|
|
|
{ |
|
94
|
1 |
|
return $this->merkleRoot; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return int |
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function getTimestamp() |
|
101
|
|
|
{ |
|
102
|
1 |
|
return $this->timestamp; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return int |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function getBits() |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->bits; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return int |
|
115
|
|
|
*/ |
|
116
|
1 |
|
public function getNonce() |
|
117
|
|
|
{ |
|
118
|
1 |
|
return $this->nonce; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return int |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function getHeight() |
|
125
|
|
|
{ |
|
126
|
1 |
|
return $this->height; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
1 |
|
public function getUtxoRoot() |
|
133
|
|
|
{ |
|
134
|
1 |
|
return $this->utxoRoot; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return Request |
|
139
|
|
|
*/ |
|
140
|
2 |
|
public function toRequest() |
|
141
|
|
|
{ |
|
142
|
2 |
|
return new Request(null, ElectrumClient::HEADERS_SUBSCRIBE, [[ |
|
143
|
2 |
|
$this->nonce, $this->prevBlock, $this->timestamp, |
|
144
|
2 |
|
$this->merkleRoot, $this->height, $this->utxoRoot, |
|
145
|
2 |
|
$this->version, $this->bits |
|
146
|
2 |
|
]]); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|