/** * @param CreateWalletCommand $command * @throws \Exception */ public function handle(CreateWalletCommand $command) { // DEBUG //var_dump($command); $walletOwnerId = $command->getWalletOwnerId(); $walletName = $command->getName(); $walletCoinSymbol = $command->getCoinSymbol(); $walletToken = $command->getToken(); // Create app wallet $wallet = new Wallet($this->walletRepository->nextIdentity(), new UserId($walletOwnerId), $walletName, $walletCoinSymbol, $walletToken, $this->clock->now(), array()); $this->walletRepository->insert($wallet); // Create BlockCypher wallet $this->blockCypherWalletService->createWallet($wallet->getId()->getValue(), $wallet->getCoinSymbol(), $wallet->getToken()); }
/** * @param CreateAddressCommand $command * @throws \Exception */ public function handle(CreateAddressCommand $command) { // DEBUG //var_dump($command); $walletId = $command->getWalletId(); $addressTag = $command->getTag(); $addressCallbackUrl = $command->getCallbackUrl(); // DEBUG: create a sample wallet //$wallet = $this->walletRepository->loadFixtures(); $wallet = $this->walletRepository->walletOfId(new WalletId($walletId)); // DEBUG //var_dump($wallet); //die(); if ($wallet === null) { // TODO: create domain exception throw new \Exception(sprintf("Wallet not found %s", $walletId)); } // 1.- Call BlockCypher API to generate new address $walletGenerateAddressResponse = $this->blockCypherWalletService->generateAddress($wallet->getId()->getValue(), $wallet->getCoinSymbol(), $wallet->getToken()); // 2.- Create new app Address $address = new Address($this->addressRepository->nextIdentity(), new WalletId($walletId), $walletGenerateAddressResponse->getAddress(), $addressTag, $walletGenerateAddressResponse->getPrivate(), $walletGenerateAddressResponse->getPublic(), $walletGenerateAddressResponse->getWif(), $addressCallbackUrl, $this->clock->now()); $this->addressRepository->insert($address); }
/** * @param WalletId $walletId * @return \string[] */ public function getAddresses(WalletId $walletId) { $wallet = $this->walletRepository->walletOfId($walletId); $addresses = $this->blockCypherWalletService->getWalletAddresses($wallet->getId()->getValue(), $wallet->getCoinSymbol(), $wallet->getToken()); return $addresses; }
/** * @param Wallet $wallet * @return BigMoney|null */ private function getWalletBalance(Wallet $wallet) { $balance = $this->blockCypherWalletService->getWalletFinalBalance($wallet->getId()->getValue(), $wallet->getCoinSymbol(), $wallet->getToken()); return $balance; }