Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Bitcoin_Transaction_Query | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| get_post_type | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_wp_post_fields | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| get_meta_input | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Strongly typed object for querying Bitcoin_Transaction in wp_posts table. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wp-bitcoin-gateway |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WP_Bitcoin_Gateway\API\Repositories\Queries; |
| 9 | |
| 10 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Payments\Bitcoin_Transaction_WP_Post_Interface; |
| 11 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Payments\Transaction; |
| 12 | use BrianHenryIE\WP_Bitcoin_Gateway\WP_Includes\Post_BH_Bitcoin_Transaction; |
| 13 | use DateTimeInterface; |
| 14 | |
| 15 | /** |
| 16 | * @see Post_BH_Bitcoin_Transaction |
| 17 | */ |
| 18 | readonly class Bitcoin_Transaction_Query extends WP_Post_Query_Abstract { |
| 19 | |
| 20 | /** |
| 21 | * The Bitcoin_Transaction wp_post post_type. |
| 22 | */ |
| 23 | protected function get_post_type(): string { |
| 24 | return Bitcoin_Transaction_WP_Post_Interface::POST_TYPE; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @return array<string,mixed> $map to:from |
| 30 | */ |
| 31 | #[\Override] |
| 32 | protected function get_wp_post_fields(): array { |
| 33 | $fields = array(); |
| 34 | |
| 35 | if ( $this->tx_id ) { |
| 36 | $fields['post_name'] = $this->tx_id; // slug, indexed. |
| 37 | } |
| 38 | if ( $this->tx_id ) { |
| 39 | $fields['post_title'] = $this->tx_id; |
| 40 | } |
| 41 | if ( $this->transaction_object ) { |
| 42 | $fields['post_content'] = wp_json_encode( $this->transaction_object ); |
| 43 | } |
| 44 | |
| 45 | return $fields; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return array<string,mixed> |
| 50 | */ |
| 51 | protected function get_meta_input(): array { |
| 52 | return array_filter( |
| 53 | array( |
| 54 | Bitcoin_Transaction_WP_Post_Interface::BLOCK_HEIGHT_META_KEY => $this->block_height, |
| 55 | Bitcoin_Transaction_WP_Post_Interface::BLOCK_DATETIME_META_KEY => $this->block_datetime, |
| 56 | Bitcoin_Transaction_WP_Post_Interface::BITCOIN_ADDRESSES_POST_IDS_META_KEY => $this->updated_transaction_meta_bitcoin_address_post_ids, |
| 57 | ) |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Constructor for Bitcoin transaction query. |
| 63 | * |
| 64 | * @param ?Transaction $transaction_object The complete transaction object from the blockchain API to be serialized and stored in post_content. |
| 65 | * @param ?string $tx_id The transaction ID to search by, stored in both post_name (slug) and post_title for efficient lookups. |
| 66 | * @param ?int $block_height The blockchain height to query transactions by, stored in post meta for confirmation tracking. |
| 67 | * @param ?DateTimeInterface $block_datetime The timestamp when the transaction block was mined, stored as serialized DateTimeInterface in post meta. |
| 68 | * @param ?array<int,string> $updated_transaction_meta_bitcoin_address_post_ids Mapping of address post IDs to transaction IDs for tracking which addresses received funds. |
| 69 | */ |
| 70 | public function __construct( |
| 71 | public ?Transaction $transaction_object = null, |
| 72 | public ?string $tx_id = null, |
| 73 | public ?int $block_height = null, |
| 74 | public ?DateTimeInterface $block_datetime = null, // TODO: don't use serialized DateTimeInterface in meta, use something legible. |
| 75 | public ?array $updated_transaction_meta_bitcoin_address_post_ids = null, |
| 76 | ) { |
| 77 | parent::__construct(); |
| 78 | } |
| 79 | } |