1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the ngutech/bitcoin-interop project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace NGUtech\Bitcoin\Message; |
10
|
|
|
|
11
|
|
|
use Daikon\Interop\Assertion; |
12
|
|
|
use Daikon\ValueObject\Timestamp; |
13
|
|
|
use NGUtech\Bitcoin\ValueObject\Hash; |
14
|
|
|
|
15
|
|
|
final class BitcoinTransactionHashReceived implements BitcoinMessageInterface |
16
|
|
|
{ |
17
|
|
|
private Hash $hash; |
18
|
|
|
|
19
|
|
|
private Timestamp $receivedAt; |
20
|
|
|
|
21
|
|
|
/** @param array $state */ |
22
|
|
|
public static function fromNative($state): self |
23
|
|
|
{ |
24
|
|
|
Assertion::isArray($state); |
25
|
|
|
Assertion::keyExists($state, 'hash'); |
26
|
|
|
Assertion::keyExists($state, 'receivedAt'); |
27
|
|
|
|
28
|
|
|
return new self( |
29
|
|
|
Hash::fromNative($state['hash']), |
30
|
|
|
Timestamp::fromNative($state['receivedAt']) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function toNative(): array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'hash' => (string)$this->hash, |
38
|
|
|
'receivedAt' => (string)$this->receivedAt |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getHash(): Hash |
43
|
|
|
{ |
44
|
|
|
return $this->hash; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getReceivedAt(): Timestamp |
48
|
|
|
{ |
49
|
|
|
return $this->receivedAt; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function __toString(): string |
53
|
|
|
{ |
54
|
|
|
return (string)$this->hash; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function __construct(Hash $hash, Timestamp $receivedAt) |
58
|
|
|
{ |
59
|
|
|
$this->hash = $hash; |
60
|
|
|
$this->receivedAt = $receivedAt; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|