|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/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 Daikon\Bitcoin\Entity; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Bitcoin\ValueObject\Address; |
|
12
|
|
|
use Daikon\Bitcoin\ValueObject\Bitcoin; |
|
13
|
|
|
use Daikon\Bitcoin\ValueObject\Hash; |
|
14
|
|
|
use Daikon\Entity\Attribute; |
|
15
|
|
|
use Daikon\Entity\AttributeMap; |
|
16
|
|
|
use Daikon\Entity\EntityTrait; |
|
17
|
|
|
use Daikon\Money\Entity\TransactionInterface; |
|
18
|
|
|
use Daikon\ValueObject\BoolValue; |
|
19
|
|
|
use Daikon\ValueObject\FloatValue; |
|
20
|
|
|
use Daikon\ValueObject\IntValue; |
|
21
|
|
|
use Daikon\ValueObject\Text; |
|
22
|
|
|
|
|
23
|
|
|
final class BitcoinTransaction implements TransactionInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use EntityTrait; |
|
26
|
|
|
|
|
27
|
|
|
public static function getAttributeMap(): AttributeMap |
|
28
|
|
|
{ |
|
29
|
|
|
return new AttributeMap([ |
|
30
|
|
|
Attribute::define('id', Hash::class), |
|
31
|
|
|
Attribute::define('address', Address::class), |
|
32
|
|
|
Attribute::define('label', Text::class), |
|
33
|
|
|
Attribute::define('amount', Bitcoin::class), |
|
34
|
|
|
Attribute::define('feeRate', FloatValue::class), |
|
35
|
|
|
Attribute::define('feeEstimate', Bitcoin::class), |
|
36
|
|
|
Attribute::define('feeSettled', Bitcoin::class), |
|
37
|
|
|
Attribute::define('comment', Text::class), |
|
38
|
|
|
Attribute::define('confTarget', IntValue::class), |
|
39
|
|
|
Attribute::define('confirmations', IntValue::class), |
|
40
|
|
|
Attribute::define('rbf', BoolValue::class), |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getIdentity(): Hash |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->getId(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getId(): Hash |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->get('id') ?? Hash::makeEmpty(); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getAddress(): Address |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->get('address') ?? Address::makeEmpty(); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getLabel(): Text |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->get('label') ?? Text::makeEmpty(); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getAmount(): Bitcoin |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->get('amount') ?? Bitcoin::makeEmpty(); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getFeeRate(): FloatValue |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->get('feeRate') ?? FloatValue::makeEmpty(); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getFeeEstimate(): Bitcoin |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->get('feeEstimate') ?? Bitcoin::makeEmpty(); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getFeeSettled(): Bitcoin |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->get('feeSettled') ?? Bitcoin::makeEmpty(); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getFeeRefund(): Bitcoin |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getFeeEstimate()->subtract($this->getFeeSettled()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getComment(): Text |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->get('comment') ?? Text::makeEmpty(); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getConfTarget(): IntValue |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->get('confTarget') ?? IntValue::fromNative(3); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getConfirmations(): IntValue |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->get('confirmations') ?? IntValue::zero(); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function getRbf(): BoolValue |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->get('rbf') ?? BoolValue::false(); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|