/**
  * @param CreateAddressCommand $createAddressCommand
  * @return Form The form
  */
 public function createCreateForm(CreateAddressCommand $createAddressCommand = null)
 {
     $walletChoices = $this->generateWalletHtmlSelectChoices();
     $defaultSelectedWalletId = $createAddressCommand->getWalletId();
     $form = $this->formFactory->create(new CreateAddressType($walletChoices, $defaultSelectedWalletId), $createAddressCommand, array('action' => $this->router->generate('bc_app_wallet_address.generate', array('walletId' => $defaultSelectedWalletId)), 'method' => 'POST', 'csrf_protection' => true));
     //$form->add('submit', 'submit'); // Using bootstrap button
     return $form;
 }
 /**
  * @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);
 }