/**
  * @param $coinSymbol
  * @param $token
  * @return \BlockCypher\Rest\ApiContext
  * @throws \BlockCypher\Exception\BlockCypherConfigurationException
  */
 public function getApiContext($coinSymbol, $token)
 {
     $coin = BlockCypherCoinSymbolConstants::getBlockCypherCode($coinSymbol);
     $chain = BlockCypherCoinSymbolConstants::getBlockCypherNetwork($coinSymbol);
     $apiContext = $this->getApiContextUsingConfigArray($token, $chain, $coin);
     return $apiContext;
 }
 /**
  * @param string $walletName
  * @param string $coinSymbol
  * @param string $token
  * @return string
  * @throws \BlockCypher\Exception\BlockCypherConfigurationException
  */
 public function wallet($walletName, $coinSymbol, $token)
 {
     // http://api.blockcypher.com/v1/btc/test3/addrs/559AC33394F28292099183?token=c0afcccdde5081d6429de37d16166ead
     $coin = BlockCypherCoinSymbolConstants::getBlockCypherCode($coinSymbol);
     $chain = BlockCypherCoinSymbolConstants::getBlockCypherNetwork($coinSymbol);
     $apiUrl = "https://api.blockcypher.com/v1/{$coin}/{$chain}/addrs/{$walletName}?token={$token}";
     return $apiUrl;
 }
 public static function positiveProvider()
 {
     BlockCypherCoinSymbolConstants::COIN_SYMBOL_LIST();
     $positiveValues = array();
     foreach (BlockCypherCoinSymbolConstants::COIN_SYMBOL_LIST() as $coinSymbol) {
         $positiveValues[] = array($coinSymbol);
     }
     return array(array('btc'), array('btc-testnet'), array('ltc'), array('doge'), array('bcy'));
 }
 public static function positiveProvider()
 {
     BlockCypherCoinSymbolConstants::COIN_SYMBOL_LIST();
     $positiveValues = array();
     foreach (BlockCypherCoinSymbolConstants::COIN_SYMBOL_LIST() as $coinSymbol) {
         $positiveValues[] = array($coinSymbol);
     }
     return $positiveValues;
 }
Exemple #5
0
/**
 * Create an ApiContext for each chain
 * @param $token
 * @return array
 */
function createApiContextForAllChains($token)
{
    $version = 'v1';
    $chainNames = BlockCypherCoinSymbolConstants::CHAIN_NAMES();
    $apiContexts = array();
    foreach ($chainNames as $chainName) {
        list($coin, $chain) = explode(".", $chainName);
        $coin = strtolower($coin);
        $apiContexts[$chainName] = getApiContextUsingConfigArray($token, $chain, $coin, $version);
    }
    return $apiContexts;
}
 private static function throwException($argument, $argumentName)
 {
     throw new \InvalidArgumentException("Argument with name {$argumentName} and value '{$argument}' is not a valid coin symbol value. Allowed values: " . implode(', ', BlockCypherCoinSymbolConstants::COIN_SYMBOL_LIST()));
 }
 /**
  * @test
  */
 public function testCHAIN_NAMES()
 {
     $expectedChainNames = array('BTC.main', 'BTC.test3', 'LTC.main', 'DOGE.main', 'URO.main', 'BCY.test');
     $this->assertEquals($expectedChainNames, BlockCypherCoinSymbolConstants::CHAIN_NAMES());
 }
Exemple #8
0
 /**
  * Map coin and chain to coin symbol
  * @return string
  */
 public function getCoinSymbol()
 {
     return BlockCypherCoinSymbolConstants::getCoinSymbolFrom($this->coin, $this->chain);
 }
 /**
  * @param $walletName
  * @param $coinSymbol
  * @param $token
  * @return BigMoney|null
  * @throws BlockCypherConnectionException
  * @throws \BlockCypher\Exception\BlockCypherConfigurationException
  * @throws \Exception
  */
 public function getWalletFinalBalance($walletName, $coinSymbol, $token)
 {
     $apiContext = $this->apiContextFactory->getApiContext($coinSymbol, $token);
     $addressClient = new AddressClient($apiContext);
     $balance = null;
     $address = null;
     try {
         $address = $addressClient->get($walletName);
     } catch (BlockCypherConnectionException $e) {
         if ($e->getCode() == self::ERROR_WALLET_NOT_FOUND) {
             // return null
         } else {
             throw $e;
         }
     }
     if ($address !== null) {
         $currencyAbbrev = BlockCypherCoinSymbolConstants::getCurrencyAbbrev($coinSymbol);
         $currency = new Currency($currencyAbbrev);
         $balance = BigMoney::fromInteger($address->getFinalBalance(), $currency);
     }
     return $balance;
 }
 /**
  * @param string $coinSymbol
  * @return string
  */
 public function coinSymbolToWssFilter($coinSymbol)
 {
     $blockcypherCode = BlockCypherCoinSymbolConstants::getBlockCypherCode($coinSymbol);
     $blockcypherNetwork = BlockCypherCoinSymbolConstants::getBlockCypherNetwork($coinSymbol);
     return BlockCypherConstants::WEB_SOCKET_LIVE_ENDPOINT . "v1/{$blockcypherCode}/{$blockcypherNetwork}";
 }