/**
  * @param $hashOrHeight
  * @param $coinSymbol
  * @param $token
  * @return Block
  */
 public function getBlock($hashOrHeight, $coinSymbol, $token)
 {
     $apiContext = $this->apiContextFactory->getApiContext($coinSymbol, $token);
     $blockClient = new BlockClient($apiContext);
     $block = $blockClient->get($hashOrHeight);
     return $block;
 }
<?php

// Run on console:
// php -f .\sample\block-api\BlockHeightEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\BlockClient;
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'));
$blockClient = new BlockClient($apiContext);
$params = array('txstart' => 1, 'limit' => 1);
$block = $blockClient->get('293000', $params);
ResultPrinter::printResult("Get Block With Paging", "Block", $block->getHash(), null, $block);
Example #3
0
<?php

// Run on console:
// php -f .\sample\introduction\Batching.php
// Batching blocks 5, 6, and 7
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\BlockClient;
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'));
$blockClient = new BlockClient($apiContext);
$blockList = array('5', '6', '7');
$blocks = $blockClient->getMultiple($blockList);
ResultPrinter::printResult("Batching", "Block[]", implode(",", $blockList), null, $blocks);
 /**
  * @dataProvider mockProviderGetParamsValidation
  * @param BlockClient $obj
  * @param PHPUnit_Framework_MockObject_MockObject|ApiContext $mockApiContext
  * @param PHPUnit_Framework_MockObject_MockObject|BlockCypherRestCall $mockBlockCypherRestCall
  * @param $params
  * @expectedException \InvalidArgumentException
  */
 public function testGetParamsValidationForParams($obj, $mockApiContext, $mockBlockCypherRestCall, $params)
 {
     $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue(BlockchainTest::getJson()));
     $obj->get(BlockchainTest::getObject()->getName(), $params, $mockApiContext, $mockBlockCypherRestCall);
 }
Example #5
0
<?php

// Run on console:
// php -f .\sample\block-api\BlockHashEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\BlockClient;
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'));
$blockClient = new BlockClient($apiContext);
$block = $blockClient->get('0000000000000000189bba3564a63772107b5673c940c16f12662b3e8546b412');
ResultPrinter::printResult("Get Block", "Block", $block->getHash(), null, $block);
Example #6
0
 /**
  * @dataProvider mockProvider
  * @param BlockClient $obj
  * @param PHPUnit_Framework_MockObject_MockObject|ApiContext $mockApiContext
  * @param PHPUnit_Framework_MockObject_MockObject|BlockCypherRestCall $mockBlockCypherRestCall
  */
 public function testGetMultipleWithParams($obj, $mockApiContext, $mockBlockCypherRestCall)
 {
     $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue('[' . BlockTest::getJson() . ']'));
     $blockList = array(BlockTest::getObject()->getHeight());
     $params = array('txstart' => 1, 'limit' => 1);
     $result = $obj->getMultiple($blockList, $params, $mockApiContext, $mockBlockCypherRestCall);
     $this->assertNotNull($result);
     $this->assertEquals($result[0], BlockTest::getObject());
 }