/**
  * @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 Transaction|null $transaction
  * @param TransactionListItem $transactionListItem
  * @param string $apiUrl
  * @param string $explorerUrl
  * @return $this
  */
 public static function from($transaction, TransactionListItem $transactionListItem, $apiUrl, $explorerUrl)
 {
     $transactionListItemDto = new self();
     // From local app transaction
     if ($transaction !== null) {
         $transactionListItemDto->setDescription($transaction->getDescription());
     } else {
         $transactionListItemDto->setDescription($transactionListItem->getTxHash());
     }
     // From BlockCypher TXRef
     $transactionListItemDto->setTxHash($transactionListItem->getTxHash());
     //$transactionListItemDto->setTxInputN($transactionListItem->getTxInputN());
     //$transactionListItemDto->setValue($transactionListItem->getValue());
     $transactionListItemDto->setConfirmations($transactionListItem->getConfirmations());
     if ($transactionListItem->getReceived() !== null) {
         $transactionListItemDto->setReceived($transactionListItem->getReceived());
     }
     if ($transactionListItem->getConfirmed() !== null) {
         $transactionListItemDto->setConfirmed($transactionListItem->getConfirmed());
     }
     $transactionListItemDto->setBlockHeight($transactionListItem->getBlockHeight());
     $transactionListItemDto->setTotal($transactionListItem->getFinalTotal());
     $transactionListItemDto->setApiUrl($apiUrl);
     $transactionListItemDto->setExplorerUrl($explorerUrl);
     return $transactionListItemDto;
 }
 /**
  * @param array $encryptedTransactions
  * @return EncryptedTransaction[]
  */
 public static function ArrayToObjectArray($encryptedTransactions)
 {
     $result = array();
     foreach ($encryptedTransactions as $transaction) {
         $result[] = Transaction::FromArray($transaction);
     }
     return $result;
 }
 /**
  * @param Transaction $transaction
  * @return bool
  */
 public function equals(Transaction $transaction)
 {
     if ($this->id->equals($transaction->getId())) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * @param Transaction $transaction
  * @throws \Exception
  */
 public function delete(Transaction $transaction)
 {
     $this->encryptedTransactionRepository->delete($transaction->encryptUsing($this->encryptor));
 }