|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the ngutech/lnd-adapter 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\Lnd\Message; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Interop\Assertion; |
|
12
|
|
|
use Daikon\ValueObject\IntValue; |
|
13
|
|
|
use Daikon\ValueObject\Text; |
|
14
|
|
|
use Daikon\ValueObject\Timestamp; |
|
15
|
|
|
|
|
16
|
|
|
trait LndHtlcMessageTrait |
|
17
|
|
|
{ |
|
18
|
|
|
private Text $incomingChannelId; |
|
19
|
|
|
|
|
20
|
|
|
private Text $outgoingChannelId; |
|
21
|
|
|
|
|
22
|
|
|
private Text $incomingHtlcId; |
|
23
|
|
|
|
|
24
|
|
|
private Text $outgoingHtlcId; |
|
25
|
|
|
|
|
26
|
|
|
private Timestamp $timestamp; |
|
27
|
|
|
|
|
28
|
|
|
private IntValue $eventType; |
|
29
|
|
|
|
|
30
|
|
|
/** @param array $state */ |
|
31
|
|
|
public static function fromNative($state): self |
|
32
|
|
|
{ |
|
33
|
|
|
Assertion::isArray($state); |
|
34
|
|
|
Assertion::keyExists($state, 'incomingChannelId'); |
|
35
|
|
|
Assertion::keyExists($state, 'outgoingChannelId'); |
|
36
|
|
|
Assertion::keyExists($state, 'incomingHtlcId'); |
|
37
|
|
|
Assertion::keyExists($state, 'outgoingHtlcId'); |
|
38
|
|
|
Assertion::keyExists($state, 'timestamp'); |
|
39
|
|
|
Assertion::keyExists($state, 'eventType'); |
|
40
|
|
|
|
|
41
|
|
|
return new self( |
|
42
|
|
|
Text::fromNative($state['incomingChannelId']), |
|
43
|
|
|
Text::fromNative($state['outgoingChannelId']), |
|
44
|
|
|
Text::fromNative($state['incomingHtlcId']), |
|
45
|
|
|
Text::fromNative($state['outgoingHtlcId']), |
|
46
|
|
|
Timestamp::fromString($state['timestamp']), |
|
47
|
|
|
IntValue::fromNative($state['eventType']), |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getIncomingChannelId(): Text |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->incomingChannelId; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getOutgoingChannelId(): Text |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->outgoingChannelId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getIncomingHtlcId(): Text |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->incomingHtlcId; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getOutgoingHtlcId(): Text |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->outgoingHtlcId; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getTimestamp(): Timestamp |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->timestamp; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getEventType(): IntValue |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->eventType; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function toNative(): array |
|
82
|
|
|
{ |
|
83
|
|
|
return [ |
|
84
|
|
|
'incomingChannelId' => (string)$this->incomingChannelId, |
|
85
|
|
|
'outgoingChannelId' => (string)$this->outgoingChannelId, |
|
86
|
|
|
'incomingHtlcId' => (string)$this->incomingHtlcId, |
|
87
|
|
|
'outgoingHtlcId' => (string)$this->outgoingHtlcId, |
|
88
|
|
|
'timestamp' => (string)$this->timestamp, |
|
89
|
|
|
'eventType' => $this->eventType->toNative(), |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
private function __construct( |
|
94
|
|
|
Text $incomingChannelId, |
|
95
|
|
|
Text $outgoingChannelId, |
|
96
|
|
|
Text $incomingHtlcId, |
|
97
|
|
|
Text $outgoingHtlcId, |
|
98
|
|
|
Timestamp $timestamp, |
|
99
|
|
|
IntValue $eventType |
|
100
|
|
|
) { |
|
101
|
|
|
$this->incomingChannelId = $incomingChannelId; |
|
102
|
|
|
$this->outgoingChannelId = $outgoingChannelId; |
|
103
|
|
|
$this->incomingHtlcId = $incomingHtlcId; |
|
104
|
|
|
$this->outgoingHtlcId = $outgoingHtlcId; |
|
105
|
|
|
$this->timestamp = $timestamp; |
|
106
|
|
|
$this->eventType = $eventType; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|