/**
  * @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);
 }
 /**
  * Returns an array of choices for to be used in a form select type listing wallets.
  * @param string $userId
  * @return array
  */
 private function generateWalletHtmlSelectChoices($userId)
 {
     $walletChoices = array();
     $wallets = $this->walletRepository->walletsOfUserId(new UserId($userId));
     foreach ($wallets as $wallet) {
         $walletChoices[$wallet->getId()->getValue()] = $wallet->getName();
     }
     return $walletChoices;
 }
 /**
  * @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);
 }
Ejemplo n.º 5
0
 /**
  * @param WalletId $walletId
  * @return Wallet
  */
 public function getWallet(WalletId $walletId)
 {
     $wallet = $this->walletRepository->walletOfId($walletId);
     return $wallet;
 }