Exemple #1
0
 /**
  * Get all addresses in a given wallet.
  *
  * @deprecated since version 1.2. Use WalletClient.
  * @param string $walletName
  * @param array $params Parameters.
  * @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 Wallet
  */
 public static function getOnlyAddresses($walletName, $params = array(), $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($walletName, 'walletName');
     ArgumentGetParamsValidator::validate($params, 'params');
     $allowedParams = array();
     $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
     $payLoad = "";
     $chainUrlPrefix = self::getChainUrlPrefix($apiContext);
     $json = self::executeCall("{$chainUrlPrefix}/wallets/{$walletName}/addresses?" . http_build_query($params), "GET", $payLoad, null, $apiContext, $restCall);
     $ret = new AddressList();
     $ret->fromJson($json);
     return $ret;
 }
<?php

// # Remove Addresses from Wallet
//
// This sample code demonstrate how you can removes addresses from a wallet, as documented here at:
// <a href="http://dev.blockcypher.com/#wallets">http://dev.blockcypher.com/#wallets</a>
//
// API used: DELETE /v1/btc/main/wallets/Wallet-Name/addresses?address=13cj1Qtf...gQiRM6j
// In samples we are using CreateWallet.php sample to get the created instance of wallet
// and AddAddressesToWallet to add the address which is going to be removed.
// You have to run that sample before running this one.
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'alice';
    // Default wallet name for samples
}
$walletClient = new \BlockCypher\Client\WalletClient($apiContexts['BTC.main']);
/// List of addresses to be removed from the wallet
$addressList = \BlockCypher\Api\AddressList::fromAddressesArray(array("13cj1QtfW61kQHoqXm3khVRYPJrgQiRM6j"));
try {
    /// Remove addresses from wallet
    $output = $walletClient->removeAddresses($walletName, $addressList);
} catch (Exception $ex) {
    ResultPrinter::printError("Remove Addresses from a Wallet", "Wallet", $walletName, $addressList, $ex);
    exit(1);
}
ResultPrinter::printResult("Remove Addresses from a Wallet", "Wallet", $walletName, $addressList, $output);
return $output;
<?php

// Run on console:
// php -f .\sample\wallet-api\AddAddressesToWalletEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\AddressList;
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\WalletClient;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('main', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$walletClient = new WalletClient($apiContext);
$addressList = AddressList::fromAddressesArray(array("13cj1QtfW61kQHoqXm3khVRYPJrgQiRM6j"));
$wallet = $walletClient->addAddresses('alice', $addressList);
ResultPrinter::printResult("Add Addresses to a Wallet Endpoint", "Wallet", 'alice', $addressList, $wallet);
 public function testFromAddressesArray()
 {
     $addressList = \BlockCypher\Api\AddressList::fromAddressesArray(array("13cj1QtfW61kQHoqXm3khVRYPJrgQiRM6j"));
     $this->assertEquals(array("13cj1QtfW61kQHoqXm3khVRYPJrgQiRM6j"), $addressList->getAddresses());
 }
 /**
  * Get all addresses in a given wallet.
  *
  * @param string $walletName
  * @param array $params Parameters.
  * @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 AddressList
  */
 public function getWalletAddresses($walletName, $params = array(), $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($walletName, 'walletName');
     ArgumentGetParamsValidator::validate($params, 'params');
     $allowedParams = array('used' => 1, 'zerobalance' => 1);
     $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
     $payLoad = "";
     $chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
     $json = $this->executeCall("{$chainUrlPrefix}/wallets/hd/{$walletName}/addresses?" . http_build_query($params), "GET", $payLoad, null, $apiContext, $restCall);
     $addressList = new AddressList();
     $addressList->fromJson($json);
     return $addressList;
 }