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\Natural; |
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('amountPaid', Bitcoin::class), |
34
|
|
|
Attribute::define('label', Text::class), |
35
|
|
|
Attribute::define('description', Text::class), |
36
|
|
|
Attribute::define('expiry', Natural::class), |
37
|
|
|
Attribute::define('cltvExpiry', Natural::class), |
38
|
|
|
Attribute::define('blockHeight', Natural::class), |
39
|
|
|
Attribute::define('state', InvoiceState::class), |
40
|
|
|
Attribute::define('createdAt', Timestamp::class), |
41
|
|
|
Attribute::define('settledAt', Timestamp::class), |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getIdentity(): Hash |
46
|
|
|
{ |
47
|
|
|
return $this->getPreimageHash(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getPreimage(): Hash |
51
|
|
|
{ |
52
|
|
|
return $this->get('preimage') ?? Hash::makeEmpty(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getPreimageHash(): Hash |
56
|
|
|
{ |
57
|
|
|
return $this->get('preimageHash') ?? Hash::makeEmpty(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getRequest(): Request |
61
|
|
|
{ |
62
|
|
|
return $this->get('request') ?? Request::makeEmpty(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getDestination(): Text |
66
|
|
|
{ |
67
|
|
|
return $this->get('destination') ?? Text::makeEmpty(); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getAmount(): Bitcoin |
71
|
|
|
{ |
72
|
|
|
return $this->get('amount') ?? Bitcoin::makeEmpty(); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getAmountPaid(): Bitcoin |
76
|
|
|
{ |
77
|
|
|
return $this->get('amountPaid') ?? Bitcoin::makeEmpty(); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getLabel(): Text |
81
|
|
|
{ |
82
|
|
|
return $this->get('label') ?? Text::makeEmpty(); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getDescription(): Text |
86
|
|
|
{ |
87
|
|
|
return $this->get('description') ?? Text::makeEmpty(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getExpiry(): Natural |
91
|
|
|
{ |
92
|
|
|
return $this->get('expiry') ?? Natural::fromNative(86400); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getCltvExpiry(): Natural |
96
|
|
|
{ |
97
|
|
|
return $this->get('cltvExpiry') ?? Natural::fromNative(10); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getBlockHeight(): Natural |
101
|
|
|
{ |
102
|
|
|
return $this->get('blockHeight') ?? Natural::makeEmpty(); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getExpiryHeight(): Natural |
106
|
|
|
{ |
107
|
|
|
//@todo handle error cases |
108
|
|
|
return $this->getBlockHeight()->add($this->getCltvExpiry()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getState(): InvoiceState |
112
|
|
|
{ |
113
|
|
|
return $this->get('state') ?? InvoiceState::makeEmpty(); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getCreatedAt(): Timestamp |
117
|
|
|
{ |
118
|
|
|
return $this->get('createdAt') ?? Timestamp::makeEmpty(); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getExpiresAt(): Timestamp |
122
|
|
|
{ |
123
|
|
|
return $this->getCreatedAt()->modify("+{$this->getExpiry()} seconds"); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function hasExpired(Timestamp $time): bool |
127
|
|
|
{ |
128
|
|
|
return $this->getExpiresAt()->isBefore($time); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getSettledAt(): Timestamp |
132
|
|
|
{ |
133
|
|
|
return $this->get('settledAt') ?? Timestamp::makeEmpty(); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
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