Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
Transaction
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_txid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_version
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_v_in
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_v_out
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_block_height
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_block_time
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Bitcoin transaction data model.
4 *
5 * @package brianhenryie/bh-wp-bitcoin-gateway
6 */
7
8namespace BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Payments;
9
10use DateTimeInterface;
11
12/**
13 * Represents a Bitcoin transaction received from blockchain APIs.
14 *
15 * Contains transaction ID, version, block height/time, and input/output vectors.
16 */
17readonly class Transaction implements Transaction_Interface {
18
19    /**
20     * Constructor.
21     *
22     * @param string             $tx_id The transaction ID (txid) uniquely identifying this transaction on the Bitcoin blockchain.
23     * @param DateTimeInterface  $block_time The timestamp when the block containing this transaction was mined.
24     * @param int                $version The Bitcoin transaction version number indicating which validation rules apply.
25     * @param Transaction_VIn[]  $v_in Array of transaction inputs (vector-in) showing which previous outputs are being spent.
26     * @param Transaction_VOut[] $v_out Array of transaction outputs (vector-out) showing which addresses received funds and how much.
27     * @param int|null           $block_height The block height in the blockchain where this transaction was confirmed, or null if unconfirmed.
28     */
29    public function __construct(
30        public string $tx_id,
31        public DateTimeInterface $block_time,
32        public int $version,
33        public array $v_in,
34        public array $v_out,
35        public ?int $block_height = null,
36    ) {
37    }
38
39    /**
40     * Get the transaction ID (txid/hash).
41     *
42     * @return string The unique transaction identifier on the blockchain.
43     */
44    public function get_txid(): string {
45        return $this->tx_id;
46    }
47
48    /**
49     * Get the Bitcoin protocol version number this transaction was created under.
50     */
51    public function get_version(): int {
52        return $this->version;
53    }
54
55    /**
56     * @return Transaction_VIn[]
57     */
58    public function get_v_in(): array {
59        return $this->v_in;
60    }
61
62    /**
63     * Get the transaction outputs.
64     *
65     * @return Transaction_VOut[] Array of transaction outputs showing destination addresses and amounts.
66     */
67    public function get_v_out(): array {
68        return $this->v_out;
69    }
70
71    /**
72     * Get the block height where this transaction was confirmed.
73     *
74     * @return ?int The blockchain height, or null if the transaction is unconfirmed (in mempool).
75     */
76    public function get_block_height(): ?int {
77        return $this->block_height;
78    }
79
80    /**
81     * Get the timestamp when the transaction block was mined.
82     *
83     * TODO: Can this be null since `::get_block_time()` can be null?
84     */
85    public function get_block_time(): DateTimeInterface {
86        return $this->block_time;
87    }
88}