NGUtech /
bitcoin-interop
| 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\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\BoolValue; |
||
| 16 | use Daikon\ValueObject\FloatValue; |
||
| 17 | use Daikon\ValueObject\Natural; |
||
| 18 | use Daikon\ValueObject\Text; |
||
| 19 | use NGUtech\Bitcoin\Service\BitcoinCurrencies; |
||
| 20 | use NGUtech\Bitcoin\Service\SatoshiCurrencies; |
||
| 21 | use NGUtech\Bitcoin\ValueObject\Bitcoin; |
||
| 22 | use NGUtech\Bitcoin\ValueObject\Hash; |
||
| 23 | use NGUtech\Bitcoin\ValueObject\OutputList; |
||
| 24 | |||
| 25 | final class BitcoinTransaction extends Entity implements TransactionInterface |
||
| 26 | { |
||
| 27 | public const AMOUNT_MIN = '1'.SatoshiCurrencies::SAT; |
||
| 28 | public const AMOUNT_MAX = '21000000'.BitcoinCurrencies::BTC; |
||
| 29 | |||
| 30 | public static function getAttributeMap(): AttributeMap |
||
| 31 | { |
||
| 32 | return new AttributeMap([ |
||
| 33 | Attribute::define('id', Hash::class), |
||
| 34 | Attribute::define('label', Text::class), |
||
| 35 | Attribute::define('amount', Bitcoin::class), |
||
| 36 | Attribute::define('outputs', OutputList::class), |
||
| 37 | Attribute::define('feeRate', FloatValue::class), |
||
| 38 | Attribute::define('feeEstimate', Bitcoin::class), |
||
| 39 | Attribute::define('feeSettled', Bitcoin::class), |
||
| 40 | Attribute::define('comment', Text::class), |
||
| 41 | Attribute::define('confTarget', Natural::class), |
||
| 42 | Attribute::define('confirmations', Natural::class), |
||
| 43 | Attribute::define('rbf', BoolValue::class), |
||
| 44 | ]); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getIdentity(): Hash |
||
| 48 | { |
||
| 49 | return $this->getId(); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getId(): Hash |
||
| 53 | { |
||
| 54 | return $this->get('id') ?? Hash::makeEmpty(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 55 | } |
||
| 56 | |||
| 57 | public function getLabel(): Text |
||
| 58 | { |
||
| 59 | return $this->get('label') ?? Text::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 60 | } |
||
| 61 | |||
| 62 | public function getAmount(): Bitcoin |
||
| 63 | { |
||
| 64 | return $this->get('amount') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('amoun...ct\Bitcoin::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Bitcoin. Consider adding an additional type-check to rule them out.
Loading history...
|
|||
| 65 | } |
||
| 66 | |||
| 67 | public function getOutputs(): OutputList |
||
| 68 | { |
||
| 69 | return $this->get('outputs') ?? OutputList::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('outpu...OutputList::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\OutputList. Consider adding an additional type-check to rule them out.
Loading history...
|
|||
| 70 | } |
||
| 71 | |||
| 72 | public function getFeeRate(): FloatValue |
||
| 73 | { |
||
| 74 | return $this->get('feeRate') ?? FloatValue::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 75 | } |
||
| 76 | |||
| 77 | public function getFeeEstimate(): Bitcoin |
||
| 78 | { |
||
| 79 | return $this->get('feeEstimate') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('feeEs...ct\Bitcoin::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Bitcoin. Consider adding an additional type-check to rule them out.
Loading history...
|
|||
| 80 | } |
||
| 81 | |||
| 82 | public function getFeeSettled(): Bitcoin |
||
| 83 | { |
||
| 84 | return $this->get('feeSettled') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('feeSe...ct\Bitcoin::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Bitcoin. Consider adding an additional type-check to rule them out.
Loading history...
|
|||
| 85 | } |
||
| 86 | |||
| 87 | public function getFeeRefund(): Bitcoin |
||
| 88 | { |
||
| 89 | return $this->getFeeEstimate()->subtract($this->getFeeSettled()); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getComment(): Text |
||
| 93 | { |
||
| 94 | return $this->get('comment') ?? Text::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 95 | } |
||
| 96 | |||
| 97 | public function getConfTarget(): Natural |
||
| 98 | { |
||
| 99 | return $this->get('confTarget') ?? Natural::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 100 | } |
||
| 101 | |||
| 102 | public function getConfirmations(): Natural |
||
| 103 | { |
||
| 104 | return $this->get('confirmations') ?? Natural::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 105 | } |
||
| 106 | |||
| 107 | public function getRbf(): BoolValue |
||
| 108 | { |
||
| 109 | return $this->get('rbf') ?? BoolValue::false(); |
||
|
0 ignored issues
–
show
|
|||
| 110 | } |
||
| 111 | } |
||
| 112 |