1+ <?php
2+
3+ namespace BlockCypher \Client ;
4+
5+ use BlockCypher \Api \AddressList ;
6+ use BlockCypher \Api \HDWallet ;
7+ use BlockCypher \Api \HDWalletGenerateAddressResponse ;
8+ use BlockCypher \Rest \ApiContext ;
9+ use BlockCypher \Transport \BlockCypherRestCall ;
10+ use BlockCypher \Validation \ArgumentArrayValidator ;
11+ use BlockCypher \Validation \ArgumentGetParamsValidator ;
12+ use BlockCypher \Validation \ArgumentValidator ;
13+
14+ /**
15+ * Class HDWalletClient
16+ *
17+ * @package BlockCypher\Client
18+ *
19+ */
20+ class HDWalletClient extends BlockCypherClient
21+ {
22+ /**
23+ * Obtain the Wallet resource for the given identifier.
24+ *
25+ * @param string $walletName
26+ * @param array $params Parameters.
27+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
28+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
29+ * @return HDWallet
30+ */
31+ public function get ($ walletName , $ params = array (), $ apiContext = null , $ restCall = null )
32+ {
33+ ArgumentValidator::validate ($ walletName , 'walletName ' );
34+ ArgumentGetParamsValidator::validate ($ params , 'params ' );
35+ $ allowedParams = array ();
36+ $ params = ArgumentGetParamsValidator::sanitize ($ params , $ allowedParams );
37+
38+ $ payLoad = "" ;
39+
40+ $ chainUrlPrefix = $ this ->getChainUrlPrefix ($ apiContext );
41+
42+ $ json = $ this ->executeCall (
43+ "$ chainUrlPrefix/wallets/hd/ $ walletName? " . http_build_query ($ params ),
44+ "GET " ,
45+ $ payLoad ,
46+ null ,
47+ $ apiContext ,
48+ $ restCall
49+ );
50+ $ ret = new HDWallet ();
51+ $ ret ->fromJson ($ json );
52+ return $ ret ;
53+ }
54+
55+ /**
56+ * Obtain multiple HDWallet resources for the given wallet names list.
57+ *
58+ * @param string[] $walletNames
59+ * @param array $params Parameters. Options: txstart, and limit
60+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
61+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
62+ * @return HDWallet[]
63+ */
64+ public function getMultiple ($ walletNames , $ params = array (), $ apiContext = null , $ restCall = null )
65+ {
66+ ArgumentArrayValidator::validate ($ walletNames , 'walletNames ' );
67+ ArgumentGetParamsValidator::validate ($ params , 'params ' );
68+ $ allowedParams = array ();
69+ $ params = ArgumentGetParamsValidator::sanitize ($ params , $ allowedParams );
70+
71+ $ walletList = implode ("; " , $ walletNames );
72+ $ payLoad = "" ;
73+
74+ $ chainUrlPrefix = $ this ->getChainUrlPrefix ($ apiContext );
75+
76+ $ json = $ this ->executeCall (
77+ "$ chainUrlPrefix/wallets/hd/ $ walletList? " . http_build_query ($ params ),
78+ "GET " ,
79+ $ payLoad ,
80+ null ,
81+ $ apiContext ,
82+ $ restCall
83+ );
84+ return HDWallet::getList ($ json );
85+ }
86+
87+ /**
88+ * Get all addresses in a given wallet.
89+ *
90+ * @deprecated changed name to getWalletAddresses.
91+ * @param string $walletName
92+ * @param array $params Parameters.
93+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
94+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
95+ * @return AddressList
96+ */
97+ public function getOnlyAddresses ($ walletName , $ params = array (), $ apiContext = null , $ restCall = null )
98+ {
99+ return $ this ->getWalletAddresses ($ walletName , $ params , $ apiContext , $ restCall );
100+ }
101+
102+ /**
103+ * Get all addresses in a given wallet.
104+ *
105+ * @param string $walletName
106+ * @param array $params Parameters.
107+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
108+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
109+ * @return AddressList
110+ */
111+ public function getWalletAddresses ($ walletName , $ params = array (), $ apiContext = null , $ restCall = null )
112+ {
113+ ArgumentValidator::validate ($ walletName , 'walletName ' );
114+ ArgumentGetParamsValidator::validate ($ params , 'params ' );
115+ $ allowedParams = array ();
116+ $ params = ArgumentGetParamsValidator::sanitize ($ params , $ allowedParams );
117+
118+ $ payLoad = "" ;
119+
120+ $ chainUrlPrefix = $ this ->getChainUrlPrefix ($ apiContext );
121+
122+ $ json = $ this ->executeCall (
123+ "$ chainUrlPrefix/wallets/hd/ $ walletName/addresses? " . http_build_query ($ params ),
124+ "GET " ,
125+ $ payLoad ,
126+ null ,
127+ $ apiContext ,
128+ $ restCall
129+ );
130+
131+ $ addressList = new AddressList ();
132+ $ addressList ->fromJson ($ json );
133+ return $ addressList ;
134+ }
135+
136+ /**
137+ * Create a new HDWallet.
138+ *
139+ * @param HDWallet $hdWallet
140+ * @param array $params Parameters
141+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
142+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
143+ * @return HDWallet
144+ */
145+ public function create (HDWallet $ hdWallet , $ params = array (), $ apiContext = null , $ restCall = null )
146+ {
147+ ArgumentGetParamsValidator::validate ($ params , 'params ' );
148+ $ allowedParams = array ();
149+ $ params = ArgumentGetParamsValidator::sanitize ($ params , $ allowedParams );
150+
151+ $ payLoad = $ hdWallet ->toJSON ();
152+
153+ $ chainUrlPrefix = $ this ->getChainUrlPrefix ($ apiContext );
154+
155+ $ json = $ this ->executeCall (
156+ "$ chainUrlPrefix/wallets/hd? " . http_build_query ($ params ),
157+ "POST " ,
158+ $ payLoad ,
159+ null ,
160+ $ apiContext ,
161+ $ restCall
162+ );
163+
164+ $ returnedHDWallet = new HDWallet ();
165+ $ returnedHDWallet ->fromJson ($ json );
166+ return $ returnedHDWallet ;
167+ }
168+
169+ /**
170+ * Deletes the HDWallet identified by wallet_id for the application associated with access token.
171+ *
172+ * @param string $walletName
173+ * @param array $params Parameters
174+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
175+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
176+ * @return bool
177+ */
178+ public function delete ($ walletName , $ params = array (), $ apiContext = null , $ restCall = null )
179+ {
180+ ArgumentGetParamsValidator::validate ($ params , 'params ' );
181+ $ allowedParams = array ();
182+ $ params = ArgumentGetParamsValidator::sanitize ($ params , $ allowedParams );
183+
184+ $ payLoad = "" ;
185+
186+ $ chainUrlPrefix = $ this ->getChainUrlPrefix ($ apiContext );
187+
188+ $ this ->executeCall (
189+ "$ chainUrlPrefix/wallets/hd/ $ walletName " . http_build_query ($ params ),
190+ "DELETE " ,
191+ $ payLoad ,
192+ null ,
193+ $ apiContext ,
194+ $ restCall
195+ );
196+ return true ;
197+ }
198+
199+ /**
200+ * A new address is generated similar to Address Generation and associated it with the given wallet.
201+ *
202+ * @param string $walletName
203+ * @param array $params Parameters
204+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
205+ * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
206+ * @return HDWalletGenerateAddressResponse
207+ */
208+ public function generateAddress ($ walletName , $ params = array (), $ apiContext = null , $ restCall = null )
209+ {
210+ ArgumentGetParamsValidator::validate ($ params , 'params ' );
211+ $ allowedParams = array (
212+ 'subchain_index ' => 1
213+ );
214+ $ params = ArgumentGetParamsValidator::sanitize ($ params , $ allowedParams );
215+
216+ $ payLoad = "" ;
217+
218+ $ chainUrlPrefix = $ this ->getChainUrlPrefix ($ apiContext );
219+
220+ $ json = $ this ->executeCall (
221+ "$ chainUrlPrefix/wallets/hd/ $ walletName/addresses/generate? " . http_build_query ($ params ),
222+ "POST " ,
223+ $ payLoad ,
224+ null ,
225+ $ apiContext ,
226+ $ restCall
227+ );
228+
229+ $ ret = new HDWalletGenerateAddressResponse ();
230+ $ ret ->fromJson ($ json );
231+ return $ ret ;
232+ }
233+ }
0 commit comments