/** * @param string[] $addressList * @param $coinSymbol * @param $token * @return AddressBalance[] */ public function getMultipleAddressBalance($addressList, $coinSymbol, $token) { $apiContext = $this->apiContextFactory->getApiContext($coinSymbol, $token); $addressClient = new AddressClient($apiContext); $addressBalances = $addressClient->getMultipleBalances($addressList); return $addressBalances; }
/** * @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; }
<?php // Run on console: // php -f .\sample\address-api\AddressEndpoint.php require __DIR__ . '/../bootstrap.php'; use BlockCypher\Auth\SimpleTokenCredential; use BlockCypher\Client\AddressClient; 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')); $addressClient = new AddressClient($apiContext); $address = $addressClient->get('1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD'); ResultPrinter::printResult("Get Address", "Address", $address->getAddress(), null, $address);
/** * @dataProvider mockProviderGetParamsValidation * @param AddressClient $obj * @param PHPUnit_Framework_MockObject_MockObject|ApiContext $mockApiContext * @param PHPUnit_Framework_MockObject_MockObject|BlockCypherRestCall $mockBlockCypherRestCall * @param $params * @expectedException \InvalidArgumentException */ public function testGetMultipleFullAddressesParamsValidationForParams($obj, $mockApiContext, $mockBlockCypherRestCall, $params) { $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue('[' . FullAddressTest::getJson() . ']')); $fullAddressList = array(FullAddressTest::getObject()->getAddress()); $obj->getMultipleFullAddresses($fullAddressList, $params, $mockApiContext, $mockBlockCypherRestCall); }
<?php // Make new address; returns private key/public key/address // Run on console: // php -f .\sample\introduction\GenerateBcyAddress.php require __DIR__ . '/../bootstrap.php'; use BlockCypher\Api\AddressKeyChain; use BlockCypher\Auth\SimpleTokenCredential; use BlockCypher\Client\AddressClient; use BlockCypher\Rest\ApiContext; $apiContext = ApiContext::create('test', 'bcy', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG')); // For Sample Purposes Only. $addressKeyChain = new AddressKeyChain(); $request = clone $addressKeyChain; $addressClient = new AddressClient($apiContext); $addressKeyChain = $addressClient->generateAddress(); ResultPrinter::printResult("Create Multisig Address", "AddressKeyChain", $addressKeyChain->getAddress(), $request, $addressKeyChain);
<?php // Run on console: // php -f .\sample\address-api\AddressBalanceEndpoint.php require __DIR__ . '/../bootstrap.php'; use BlockCypher\Auth\SimpleTokenCredential; use BlockCypher\Client\AddressClient; 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')); $addressClient = new AddressClient($apiContext); $addressBalance = $addressClient->getBalance('1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD'); ResultPrinter::printResult("Get Only Address Balance", "Address Balance", $addressBalance->getAddress(), null, $addressBalance);
<?php // Run on console: // php -f .\sample\address-api\GenerateMultisigAddressEndpoint.php require __DIR__ . '/../bootstrap.php'; use BlockCypher\Api\AddressKeyChain; use BlockCypher\Auth\SimpleTokenCredential; use BlockCypher\Client\AddressClient; 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')); $addressClient = new AddressClient($apiContext); $pubkeys = array("02c716d071a76cbf0d29c29cacfec76e0ef8116b37389fb7a3e76d6d32cf59f4d3", "033ef4d5165637d99b673bcdbb7ead359cee6afd7aaf78d3da9d2392ee4102c8ea", "022b8934cc41e76cb4286b9f3ed57e2d27798395b04dd23711981a77dc216df8ca"); $addressKeyChain = $addressClient->generateMultisigAddress($pubkeys, 'multisig-2-of-3'); // For Sample Purposes Only. $request = new AddressKeyChain(); $request->setPubkeys($pubkeys); $request->setScriptType('multisig-2-of-3'); ResultPrinter::printResult("Create Multisig Address", "AddressKeyChain", $addressKeyChain->getAddress(), $request, $addressKeyChain);