/**
  * @param string $token
  * @return bool
  */
 public function authenticate($token)
 {
     $apiContext = $this->apiContextFactory->getApiContext(self::AUTH_WALLET_COIN_SYMBOL, $token);
     $walletClient = new WalletClient($apiContext);
     try {
         // Create BlockCypher wallet
         $bcWallet = new BlockCypherWallet();
         $bcWallet->setToken($token);
         $bcWallet->setName(self::AUTH_WALLET_NAME);
         $bcWallet = $walletClient->create($bcWallet);
         if ($bcWallet && $bcWallet->getName() == self::AUTH_WALLET_NAME) {
             return true;
         } else {
             return false;
         }
     } catch (BlockCypherConnectionException $e) {
         if ($e->getCode() == self::ERROR_WALLET_ALREADY_EXISTS) {
             return true;
         } else {
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * @param $walletName
  * @param $coinSymbol
  * @param $token
  * @return BlockCypherWallet
  */
 public function createWallet($walletName, $coinSymbol, $token)
 {
     $apiContext = $this->apiContextFactory->getApiContext($coinSymbol, $token);
     $walletClient = new WalletClient($apiContext);
     // Create BlockCypher wallet
     $bcWallet = new BlockCypherWallet();
     $bcWallet->setToken($token);
     $bcWallet->setName($walletName);
     return $walletClient->create($bcWallet);
 }
예제 #3
0
 /**
  * Obtain the Wallet resource for the given identifier.
  *
  * @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 get($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}?" . http_build_query($params), "GET", $payLoad, null, $apiContext, $restCall);
     $ret = new Wallet();
     $ret->fromJson($json);
     return $ret;
 }
 /**
  * @param $apiContext
  */
 private function deleteWalletIfExists($walletName, $apiContext)
 {
     // Delete wallet if exists
     try {
         $wallet = Wallet::get($walletName, array(), $apiContext);
         $wallet->delete(array(), $apiContext);
     } catch (\Exception $ex) {
     }
 }
예제 #5
0
 /**
  * Remove Addresses to the Wallet. Addresses will no longer be associated with the wallet.
  *
  * @param string $walletName
  * @param AddressList $addressList
  * @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 function removeAddresses($walletName, $addressList, $params = array(), $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($addressList, 'addressList');
     ArgumentGetParamsValidator::validate($params, 'params');
     $allowedParams = array();
     $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
     $payLoad = '';
     // Using 'address' url parameter
     if (!isset($params['address'])) {
         $params['address'] = implode(';', $addressList->getAddresses());
     } else {
         $params['address'] .= ';' . implode(';', $addressList->getAddresses());
     }
     $chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
     $json = $this->executeCall("{$chainUrlPrefix}/wallets/{$walletName}/addresses?" . http_build_query($params), "DELETE", $payLoad, null, $apiContext, $restCall);
     $returnedWallet = new Wallet();
     $returnedWallet->fromJson($json);
     return $returnedWallet;
 }
예제 #6
0
 /**
  * @dataProvider mockProvider
  * @param Wallet $obj
  * @param $mockApiContext
  */
 public function testDelete($obj, $mockApiContext)
 {
     $mockBlockCypherRestCall = $this->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock();
     $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue(true));
     /** @noinspection PhpParamsInspection */
     $result = $obj->delete(array(), $mockApiContext, $mockBlockCypherRestCall);
     $this->assertNotNull($result);
 }
예제 #7
0
<?php

// Run on console:
// php -f .\sample\wallet-api\CreateWalletEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\Wallet;
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'));
// Create a new instance of Wallet object
$wallet = new Wallet();
$wallet->setName('alice');
$wallet->setAddresses(array("1JcX75oraJEmzXXHpDjRctw3BX6qDmFM8e"));
// For Sample Purposes Only.
$request = clone $wallet;
$walletClient = new WalletClient($apiContext);
$createdWallet = $walletClient->create($wallet);
ResultPrinter::printResult("Created Wallet End Point", "Wallet", $createdWallet->getName(), $request, $createdWallet);