/**
  * @param CreateTransactionCommand $command
  * @throws \Exception
  */
 public function handle(CreateTransactionCommand $command)
 {
     $walletId = $command->getWalletId();
     $payToAddress = $command->getPayToAddress();
     $description = $command->getDescription();
     $amount = $command->getAmount();
     // Get wallet object from repository
     $wallet = $this->walletRepository->walletOfId(new WalletId($walletId));
     if (!$wallet) {
         throw new \Exception(sprintf("Wallet not found %s", $walletId));
     }
     // Call BlockCypher API to generate new transaction
     $txSkeleton = $this->blockCypherTransactionService->create($wallet->getId()->getValue(), $wallet->getCoinSymbol(), $wallet->getToken(), $payToAddress, $amount);
     // Create new app Transaction
     $transaction = new Transaction($this->transactionRepository->nextIdentity(), $wallet->getId(), null, $payToAddress, $description, $amount, $this->clock->now());
     // Get all addresses from all tx inputs.
     $allInputsAddresses = $txSkeleton->getInputsAddresses();
     // Get private keys from repository
     $privateKeys = $this->getPrivateKeysFromRepository($allInputsAddresses, $walletId);
     // Check private keys
     $this->checkPrivateKeys($privateKeys, $txSkeleton->getTosign());
     // Sign transaction
     $txSkeletonSigned = $this->blockCypherTransactionService->sign($txSkeleton, $privateKeys, $wallet->getCoinSymbol(), $wallet->getToken());
     // Send transaction to the network
     $txSkeletonSent = $this->blockCypherTransactionService->send($txSkeletonSigned, $wallet->getCoinSymbol(), $wallet->getToken());
     // Map real network tx with app transaction
     $transaction->assignNetworkTransactionHash($txSkeletonSent->getTx()->getHash());
     // Store new local app transaction
     $this->transactionRepository->insert($transaction);
 }
 /**
  * @param CreateTransactionCommand $createTransactionCommand
  * @param string $userId
  * @return Form The form
  */
 public function createCreateForm(CreateTransactionCommand $createTransactionCommand, $userId)
 {
     // TODO: Code Review. Pass array of user's wallets (with same the format as $walletChoices) like this:
     // array(
     //  'WALLET_ID' => 'WALLET_NAME
     // )
     // instead of $userId
     $walletChoices = $this->generateWalletHtmlSelectChoices($userId);
     $defaultSelectedWalletId = $createTransactionCommand->getWalletId();
     $form = $this->formFactory->create(new CreateTransactionType($walletChoices, $defaultSelectedWalletId), $createTransactionCommand, array('action' => $this->router->generate('bc_app_wallet_transaction.create', array('walletId' => $defaultSelectedWalletId)), 'method' => 'POST', 'csrf_protection' => true));
     //$form->add('submit', 'submit'); // Using bootstrap button
     return $form;
 }
 /**
  * @param CreateTransactionCommand $createTransactionCommand
  * @return void
  */
 public function validate($createTransactionCommand)
 {
     Assertion::integer($createTransactionCommand->getAmount());
 }