Skip to content
This repository was archived by the owner on Oct 24, 2020. It is now read-only.

Commit cc74db7

Browse files
committed
HDWalletClient
1 parent 95bd4c6 commit cc74db7

24 files changed

Lines changed: 627 additions & 203 deletions

lib/BlockCypher/Api/HDWallet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class HDWallet extends BlockCypherResourceModel
2828
/**
2929
* Obtain the Wallet resource for the given identifier.
3030
*
31+
* @deprecated since version 1.2. Use HDWalletClient.
3132
* @param string $walletName
3233
* @param array $params Parameters.
3334
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -61,6 +62,7 @@ public static function get($walletName, $params = array(), $apiContext = null, $
6162
/**
6263
* Get all addresses in a given wallet.
6364
*
65+
* @deprecated since version 1.2. Use HDWalletClient.
6466
* @param string $walletName
6567
* @param array $params Parameters.
6668
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -95,6 +97,7 @@ public static function getOnlyAddresses($walletName, $params = array(), $apiCont
9597
/**
9698
* Create a new HDWallet.
9799
*
100+
* @deprecated since version 1.2. Use HDWalletClient.
98101
* @param array $params Parameters
99102
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
100103
* @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -125,6 +128,7 @@ public function create($params = array(), $apiContext = null, $restCall = null)
125128
/**
126129
* Deletes the HDWallet identified by wallet_id for the application associated with access token.
127130
*
131+
* @deprecated since version 1.2. Use HDWalletClient.
128132
* @param array $params Parameters
129133
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
130134
* @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -162,6 +166,7 @@ public function getName()
162166
/**
163167
* A new address is generated similar to Address Generation and associated it with the given wallet.
164168
*
169+
* @deprecated since version 1.2. Use HDWalletClient.
165170
* @param array $params Parameters
166171
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
167172
* @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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+
}

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v1.2.0
1414
* TXClient
1515
* TXSkeleton::sign changed function signature
1616
* WalletClient
17+
* HDWalletClient
1718

1819
v1.1.0
1920
------

0 commit comments

Comments
 (0)