|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the ngutech/lightning-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\Lightning\Entity; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Entity\Attribute; |
|
12
|
|
|
use Daikon\Entity\AttributeMap; |
|
13
|
|
|
use Daikon\Entity\Entity; |
|
14
|
|
|
use Daikon\Money\Entity\TransactionInterface; |
|
15
|
|
|
use Daikon\ValueObject\IntValue; |
|
16
|
|
|
use Daikon\ValueObject\Text; |
|
17
|
|
|
use Daikon\ValueObject\Timestamp; |
|
|
|
|
|
|
18
|
|
|
use NGUtech\Bitcoin\ValueObject\Hash; |
|
19
|
|
|
use NGUtech\Bitcoin\ValueObject\Bitcoin; |
|
20
|
|
|
use NGUtech\Lightning\ValueObject\InvoiceState; |
|
21
|
|
|
use NGUtech\Lightning\ValueObject\Request; |
|
22
|
|
|
|
|
23
|
|
|
final class LightningInvoice extends Entity implements TransactionInterface |
|
24
|
|
|
{ |
|
25
|
|
|
public static function getAttributeMap(): AttributeMap |
|
26
|
|
|
{ |
|
27
|
|
|
return new AttributeMap([ |
|
28
|
|
|
Attribute::define('preimage', Hash::class), |
|
29
|
|
|
Attribute::define('preimageHash', Hash::class), |
|
30
|
|
|
Attribute::define('request', Request::class), |
|
31
|
|
|
Attribute::define('destination', Text::class), |
|
32
|
|
|
Attribute::define('amount', Bitcoin::class), |
|
33
|
|
|
Attribute::define('label', Text::class), |
|
34
|
|
|
Attribute::define('description', Text::class), |
|
35
|
|
|
Attribute::define('expiry', IntValue::class), |
|
36
|
|
|
Attribute::define('cltvExpiry', IntValue::class), |
|
37
|
|
|
Attribute::define('blockHeight', IntValue::class), |
|
38
|
|
|
Attribute::define('state', InvoiceState::class), |
|
39
|
|
|
Attribute::define('createdAt', Timestamp::class), |
|
40
|
|
|
Attribute::define('settledAt', Timestamp::class), |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getIdentity(): Hash |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->getPreimageHash(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getPreimage(): Hash |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->get('preimage') ?? Hash::makeEmpty(); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getPreimageHash(): Hash |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->get('preimageHash') ?? Hash::makeEmpty(); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getRequest(): Request |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->get('request') ?? Request::makeEmpty(); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getDestination(): Text |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->get('destination') ?? Text::makeEmpty(); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getAmount(): Bitcoin |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->get('amount') ?? Bitcoin::makeEmpty(); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getLabel(): Text |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->get('label') ?? Text::makeEmpty(); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getDescription(): Text |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->get('description') ?? Text::makeEmpty(); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getExpiry(): IntValue |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->get('expiry') ?? IntValue::fromNative(86400); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getCltvExpiry(): IntValue |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->get('cltvExpiry') ?? IntValue::fromNative(10); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getBlockHeight(): IntValue |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->get('blockHeight') ?? IntValue::makeEmpty(); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getExpiryHeight(): IntValue |
|
100
|
|
|
{ |
|
101
|
|
|
//@todo handle error cases |
|
102
|
|
|
return $this->getBlockHeight()->add($this->getCltvExpiry()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getState(): InvoiceState |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->get('state') ?? InvoiceState::makeEmpty(); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getCreatedAt(): Timestamp |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->get('createdAt') ?? Timestamp::makeEmpty(); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getExpiresAt(): Timestamp |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->getCreatedAt()->modify("+{$this->getExpiry()} seconds"); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function hasExpired(Timestamp $time): bool |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->getExpiresAt()->isBefore($time); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function getSettledAt(): Timestamp |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->get('settledAt') ?? Timestamp::makeEmpty(); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths