This repository has been archived by the owner on Oct 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathFaucetClient.php
69 lines (61 loc) · 2.15 KB
/
FaucetClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace BlockCypher\Client;
use BlockCypher\Api\Faucet;
use BlockCypher\Api\FaucetResponse;
use BlockCypher\Rest\ApiContext;
use BlockCypher\Transport\BlockCypherRestCall;
use BlockCypher\Validation\ArgumentValidator;
use BlockCypher\Validation\NumericValidator;
/**
* Class FaucetClient
*
* @package BlockCypher\Client
*
*/
class FaucetClient extends BlockCypherClient
{
/**
* Fund an address with faucet.
* The faucet endpoint is only available on BlockCypher’s Test Blockchain and Bitcoin Testnet3
*
* @param string $address Address to fund
* @param int $amount
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return FaucetResponse
*/
public function fundAddress($address, $amount, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($address, 'address');
NumericValidator::validate($amount, 'amount');
$faucet = new Faucet();
$faucet->setAddress($address);
$faucet->setAmount($amount);
return $this->turnOn($faucet, $apiContext, $restCall);
}
/**
* Fund an address with faucet.
* The faucet endpoint is only available on BlockCypher’s Test Blockchain and Bitcoin Testnet3
*
* @param Faucet $faucet
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return FaucetResponse
*/
public function turnOn(Faucet $faucet, $apiContext = null, $restCall = null)
{
$payLoad = $faucet->toJSON();
$chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
$json = $this->executeCall(
"$chainUrlPrefix/faucet",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new FaucetResponse();
$ret->fromJson($json);
return $ret;
}
}