/** * @param Wallet $wallet * @param BlockCypherAddress $blockCypherAddress * @return WalletDto */ public static function from(Wallet $wallet, BlockCypherAddress $blockCypherAddress) { $walletDto = new WalletDto(); // From Wallet $walletDto->setUserId($wallet->getUserId()->getValue()); $walletDto->setName($wallet->getName()); // From BlockCypherAddress $walletDto->setId($blockCypherAddress->getWallet()->getName()); $walletDto->setTotalSent($blockCypherAddress->getTotalSent()); $walletDto->setTotalReceived($blockCypherAddress->getTotalReceived()); $walletDto->setUnconfirmedBalance($blockCypherAddress->getUnconfirmedBalance()); $walletDto->setBalance($blockCypherAddress->getBalance()); $walletDto->setFinalBalance($blockCypherAddress->getFinalBalance()); $walletDto->setNTx($blockCypherAddress->getNTx()); $walletDto->setUnconfirmedNTx($blockCypherAddress->getUnconfirmedNTx()); $walletDto->setFinalNTx($blockCypherAddress->getFinalNTx()); return $walletDto; }
/** * @param Wallet $wallet * @param Transaction[]|null $transactions * @param BlockCypherAddress $blockCypherAddress * @param ApiRouter $apiRouter * @param ExplorerRouter $explorerRouter * @return TransactionListDto */ public static function from(Wallet $wallet, $transactions, BlockCypherAddress $blockCypherAddress, ApiRouter $apiRouter, ExplorerRouter $explorerRouter) { $transactionListDto = new self(); // From BlockCypher Address $transactionListDto->setTotalSent($blockCypherAddress->getTotalSent()); $transactionListDto->setTotalReceived($blockCypherAddress->getTotalReceived()); $transactionListDto->setUnconfirmedBalance($blockCypherAddress->getUnconfirmedBalance()); $transactionListDto->setBalance($blockCypherAddress->getBalance()); $transactionListDto->setFinalBalance($blockCypherAddress->getFinalBalance()); $transactionListDto->setNTx($blockCypherAddress->getNTx()); $transactionListDto->setUnconfirmedNTx($blockCypherAddress->getUnconfirmedNTx()); $transactionListDto->setFinalNTx($blockCypherAddress->getFinalNTx()); $blockCypherTXRefs = $blockCypherAddress->getAllTxrefs(); // Confirmed and unconfirmed $transactionListItems = TransactionListItemArray::from($blockCypherTXRefs); $transactionListItemDtos = TransactionListItemDtoArray::from($wallet, $transactions, $transactionListItems, $apiRouter, $explorerRouter); $transactionListDto->setTransactionListItemDtos($transactionListItemDtos); return $transactionListDto; }
/** * Obtain multiple Addresses resources for the given identifiers. * * @deprecated since version 1.2. Use AddressClient. * @param string[] $array * @param array $params Parameters. Options: unspentOnly, and before * @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 Address[] */ public static function getMultiple($array, $params = array(), $apiContext = null, $restCall = null) { ArgumentArrayValidator::validate($array, 'array'); ArgumentGetParamsValidator::validate($params, 'params'); $allowedParams = array('unspentOnly' => 1, 'before' => 1); $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams); $addressList = implode(";", $array); $payLoad = ""; $chainUrlPrefix = self::getChainUrlPrefix($apiContext); $json = self::executeCall("{$chainUrlPrefix}/addrs/{$addressList}?" . http_build_query($params), "GET", $payLoad, null, $apiContext, $restCall); return Address::getList($json); }
/** * @dataProvider mockProvider * @param Address $obj */ public function testGet($obj, $mockApiContext) { $mockBlockCypherRestCall = $this->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock(); $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue(WalletAsAddressTest::getJson())); /** @noinspection PhpParamsInspection */ $result = $obj->get("alice", array(), $mockApiContext, $mockBlockCypherRestCall); $this->assertNotNull($result); $this->assertInstanceOf('BlockCypher\\Api\\Address', $result); }
/** * @dataProvider mockProvider * @param Address $obj */ public function testGetMultipleWithParams($obj, $mockApiContext) { $mockBlockCypherRestCall = $this->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock(); $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue('[' . AddressTest::getJson() . ']')); $addressList = array(AddressTest::getObject()->getAddress()); $params = array('unspentOnly' => 'true', 'before' => 300000); $result = $obj->getMultiple($addressList, $params, $mockApiContext, $mockBlockCypherRestCall); $this->assertNotNull($result); $this->assertEquals($result[0], AddressTest::getObject()); }
/** * @return Address */ public function testGetWithUnspentOnly() { $request = $this->operation['response']['body']; $address = new Address($request); $params = array('unspentOnly' => 'true'); $result = Address::get($address->getAddress(), $params, $this->apiContext, $this->mockBlockCypherRestCall); $this->assertNotNull($result); $this->assertInstanceOf('\\BlockCypher\\Api\\Address', $result); // Assert only immutable values. $this->assertEquals($address->getAddress(), $result->getAddress()); $this->assertEquals($address->getTxUrl(), $result->getTxUrl()); $this->assertEquals(count($address->getTxrefs()), count($result->getTxrefs())); $this->assertContainsOnlyInstancesOf('\\BlockCypher\\Api\\Txref', $result->getTxrefs()); return $result; }
/** * Obtain multiple Addresses resources for the given identifiers. * * @param string[] $array * @param array $params Parameters. Options: unspentOnly, and before * @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 Address[] */ public function getMultiple($array, $params = array(), $apiContext = null, $restCall = null) { ArgumentArrayValidator::validate($array, 'array'); ArgumentGetParamsValidator::validate($params, 'params'); $allowedParams = array('unspentOnly' => 1, 'includeScript' => 1, 'includeConfidence' => 1, 'before' => 1, 'after' => 1, 'limit' => 1, 'confirmations' => 1, 'confidence' => 1, 'omitWalletAddresses' => 1); $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams); $addressList = implode(";", $array); $payLoad = ""; $chainUrlPrefix = $this->getChainUrlPrefix($apiContext); $json = $this->executeCall("{$chainUrlPrefix}/addrs/{$addressList}?" . http_build_query($params), "GET", $payLoad, null, $apiContext, $restCall); return Address::getList($json); }