Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Bitcoin_Wallet
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_post_id
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_status
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_xpub
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_address_index
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_associated_gateways_details
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Bitcoin wallet stored as a WordPress custom post type.
4 *
5 * Represents a hierarchical deterministic (HD) wallet using an extended public key (xpub/ypub/zpub)
6 * that can derive multiple payment addresses for receiving Bitcoin payments.
7 *
8 * Custom post type in WordPress, keyed with GUID of the wallet.
9 *
10 * @package    brianhenryie/bh-wp-bitcoin-gateway
11 */
12
13namespace BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Wallet;
14
15use BrianHenryIE\WP_Bitcoin_Gateway\WP_Includes\Post_BH_Bitcoin_Wallet;
16
17/**
18 * @see Bitcoin_Wallet_WP_Post_Interface
19 * @see Post_BH_Bitcoin_Wallet
20 */
21class Bitcoin_Wallet implements Bitcoin_Wallet_Interface {
22
23    /**
24     * Constructor
25     *
26     * @param int                                                       $post_id The WordPress post ID where this wallet is stored in the database.
27     * @param string                                                    $xpub The extended public key (xpub/ypub/zpub) used to derive child addresses for this wallet.
28     * @param Bitcoin_Wallet_Status                                     $status The current operational status of the wallet (e.g. active, inactive).
29     * @param ?int                                                      $address_index The highest derivation path index used for generating addresses, or null before any addresses have been generated.
30     * @param array<array{integration:class-string, gateway_id:string}> $gateways The list of integration,gateway_id that are using this wallet.
31     */
32    public function __construct(
33        protected int $post_id,
34        protected string $xpub,
35        protected Bitcoin_Wallet_Status $status,
36        protected ?int $address_index, // null before any addresses have been generated.
37        protected array $gateways,
38    ) {
39    }
40
41    /**
42     * Used when adding this wallet as a parent of a generated address.
43     */
44    public function get_post_id(): int {
45        return $this->post_id;
46    }
47
48    /**
49     * The current status of the wallet.
50     *
51     * TODO: Mark wallets inactive when removed from a gateway.
52     */
53    public function get_status(): Bitcoin_Wallet_Status {
54        return $this->status;
55    }
56
57    /**
58     * Return the xpub/ypub/zpub this wallet represents.
59     */
60    public function get_xpub(): string {
61        return $this->xpub;
62    }
63
64    /**
65     * Get the index of the last generated address, so generating new addresses can start higher.
66     */
67    public function get_address_index(): ?int {
68        return $this->address_index;
69    }
70
71    /**
72     * @return array<array{integration:class-string, gateway_id:string}>
73     */
74    public function get_associated_gateways_details(): array {
75        return $this->gateways;
76    }
77}