/** * Send the transaction to the network. * * @param TXSkeleton $txSkeleton * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls * @return TXSkeleton */ public function send(TXSkeleton $txSkeleton, $apiContext = null, $restCall = null) { $payLoad = $txSkeleton->toJSON(); $chainUrlPrefix = $this->getChainUrlPrefix($apiContext); $json = $this->executeCall("{$chainUrlPrefix}/txs/send", "POST", $payLoad, null, $apiContext, $restCall); $returnedTXSkeleton = new TXSkeleton(); $returnedTXSkeleton->fromJson($json); return $returnedTXSkeleton; }
/** * Create a new TX. * * @deprecated since version 1.2. Use TXClient. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls * @return TXSkeleton */ public function create($apiContext = null, $restCall = null) { $payLoad = $this->toJSON(); $chainUrlPrefix = self::getChainUrlPrefix($apiContext); $json = self::executeCall("{$chainUrlPrefix}/txs/new", "POST", $payLoad, null, $apiContext, $restCall); $ret = new TXSkeleton(); $ret->fromJson($json); return $ret; }
/** * @dataProvider mockProvider * @param TXSkeleton $obj */ public function testSend($obj, $mockApiContext) { $mockBlockCypherRestCall = $this->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock(); $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue(self::getJson())); $result = $obj->send($mockApiContext, $mockBlockCypherRestCall); $this->assertNotNull($result); }
/** * @param string $walletName * @param string $coinSymbol * @param string $token * @param string $payToAddress * @param int $amount * @return TXSkeleton */ public function create($walletName, $coinSymbol, $token, $payToAddress, $amount) { $apiContext = $this->apiContextFactory->getApiContext($coinSymbol, $token); $txClient = new TXClient($apiContext); // DEBUG //var_dump($amount); //die(); $tx = new TX(); // Tx inputs $input = new TXInput(); $input->setWalletName($walletName); $input->setWalletToken($token); $tx->addInput($input); // Tx outputs $output = new TXOutput(); $output->addAddress($payToAddress); $tx->addOutput($output); // Tx amount $output->setValue($amount); // Satoshis try { $txSkeleton = $txClient->create($tx); } catch (BlockCypherConnectionException $e) { $data = $e->getData(); //DEBUG //var_export($data); //die(); $txSkeleton = new TXSkeleton($data); //DEBUG //var_dump($txSkeleton); //die(); throw new InvalidTransaction($txSkeleton->getAllErrorMessages()); } return $txSkeleton; }