1 | <?php |
||
16 | class Version extends NetworkSerializable |
||
17 | { |
||
18 | /** |
||
19 | * @var int|string |
||
20 | */ |
||
21 | private $version; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $services; |
||
27 | |||
28 | /** |
||
29 | * @var int|string |
||
30 | */ |
||
31 | private $timestamp; |
||
32 | |||
33 | /** |
||
34 | * @var NetworkAddressInterface |
||
35 | */ |
||
36 | private $addrRecv; |
||
37 | |||
38 | /** |
||
39 | * @var NetworkAddressInterface |
||
40 | */ |
||
41 | private $addrFrom; |
||
42 | |||
43 | /** |
||
44 | * @var BufferInterface |
||
45 | */ |
||
46 | private $userAgent; |
||
47 | |||
48 | /** |
||
49 | * @var int|string |
||
50 | */ |
||
51 | private $startHeight; |
||
52 | |||
53 | /** |
||
54 | * @var bool |
||
55 | */ |
||
56 | private $relay; |
||
57 | |||
58 | /** |
||
59 | * @var integer|string |
||
60 | */ |
||
61 | private $nonce; |
||
62 | |||
63 | /** |
||
64 | * @param int $version |
||
65 | * @param int $services |
||
66 | * @param int $timestamp |
||
67 | * @param NetworkAddressInterface $addrRecv |
||
68 | * @param NetworkAddressInterface $addrFrom |
||
69 | * @param int $nonce |
||
70 | * @param BufferInterface $userAgent |
||
71 | * @param int $startHeight |
||
72 | * @param bool $relay |
||
73 | */ |
||
74 | 63 | public function __construct( |
|
75 | $version, |
||
76 | $services, |
||
77 | $timestamp, |
||
78 | NetworkAddressInterface $addrRecv, |
||
79 | NetworkAddressInterface $addrFrom, |
||
80 | $nonce, |
||
81 | BufferInterface $userAgent, |
||
82 | $startHeight, |
||
83 | $relay |
||
84 | ) { |
||
85 | |||
86 | 63 | if ($addrRecv instanceof NetworkAddressTimestamp) { |
|
87 | $addrRecv = $addrRecv->withoutTimestamp(); |
||
88 | } |
||
89 | 63 | if ($addrFrom instanceof NetworkAddressTimestamp) { |
|
90 | $addrFrom = $addrFrom->withoutTimestamp(); |
||
91 | } |
||
92 | |||
93 | 63 | $random = new Random(); |
|
94 | 63 | $this->nonce = $random->bytes(8)->getInt(); |
|
95 | 63 | $this->version = $version; |
|
96 | 63 | $this->services = $services; |
|
97 | 63 | $this->timestamp = $timestamp; |
|
98 | 63 | $this->addrRecv = $addrRecv; |
|
99 | 63 | $this->nonce = $nonce; |
|
100 | 63 | $this->addrFrom = $addrFrom; |
|
101 | 63 | $this->userAgent = $userAgent; |
|
102 | 63 | $this->startHeight = $startHeight; |
|
103 | 63 | if (! is_bool($relay)) { |
|
104 | 3 | throw new \InvalidArgumentException('Relay must be a boolean'); |
|
105 | } |
||
106 | 60 | $this->relay = $relay; |
|
107 | 60 | } |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | * @see \BitWasp\Bitcoin\Network\NetworkSerializableInterface::getNetworkCommand() |
||
112 | */ |
||
113 | 24 | public function getNetworkCommand() |
|
117 | |||
118 | /** |
||
119 | * @return Buffer|int|string |
||
120 | */ |
||
121 | 24 | public function getNonce() |
|
125 | |||
126 | /** |
||
127 | * @return int|string |
||
128 | */ |
||
129 | 27 | public function getVersion() |
|
133 | |||
134 | /** |
||
135 | * @return int |
||
136 | */ |
||
137 | 24 | public function getServices() |
|
141 | |||
142 | /** |
||
143 | * @return int|string |
||
144 | */ |
||
145 | 27 | public function getTimestamp() |
|
149 | |||
150 | /** |
||
151 | * @return NetworkAddress |
||
152 | */ |
||
153 | 30 | public function getRecipientAddress() |
|
157 | |||
158 | /** |
||
159 | * @return NetworkAddress |
||
160 | */ |
||
161 | 39 | public function getSenderAddress() |
|
165 | |||
166 | /** |
||
167 | * @return BufferInterface |
||
168 | */ |
||
169 | 27 | public function getUserAgent() |
|
173 | |||
174 | /** |
||
175 | * @return int|string |
||
176 | */ |
||
177 | 30 | public function getStartHeight() |
|
181 | |||
182 | /** |
||
183 | * @return bool |
||
184 | */ |
||
185 | 27 | public function getRelay() |
|
189 | |||
190 | /** |
||
191 | * @return BufferInterface |
||
192 | */ |
||
193 | 21 | public function getBuffer() |
|
197 | } |
||
198 |