Exemple #1
0
 /**
  * @return TX
  */
 public function build()
 {
     $tx = new TX();
     $tx->setInputs($this->inputs);
     $tx->setOutputs($this->outputs);
     return $tx;
 }
 /**
  * @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;
 }
 /**
  * @return TX
  */
 public function testGetWithPaging()
 {
     $request = $this->operation['response']['body'];
     $transaction = new TX($request);
     $params = array('instart' => 1, 'outstart' => 1, 'limit' => 1);
     $result = TX::get($transaction->getHash(), $params, $this->apiContext, $this->mockBlockCypherRestCall);
     $this->assertNotNull($result);
     $this->assertInstanceOf('\\BlockCypher\\Api\\TX', $result);
     // Assert only immutable values.
     $this->assertEquals($transaction->getHash(), $result->getHash());
     $this->assertEquals($transaction->getAddresses(), $result->getAddresses());
     $transactionInputs = $transaction->getInputs();
     $resultInputs = $result->getInputs();
     $this->assertEquals($transactionInputs[0]->getPrevHash(), $resultInputs[0]->getPrevHash());
     return $result;
 }
<?php

// Run on console:
// php -f .\sample\transaction-api\NewTransactionEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\TX;
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\TXClient;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('test', 'bcy', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
// Create a new instance of TX object
$tx = new TX();
// Tx inputs
$input = new \BlockCypher\Api\TXInput();
$input->addAddress("C5vqMGme4FThKnCY44gx1PLgWr86uxRbDm");
$tx->addInput($input);
// Tx outputs
$output = new \BlockCypher\Api\TXOutput();
$output->addAddress("C4MYFr4EAdqEeUKxTnPUF3d3whWcPMz1Fi");
$tx->addOutput($output);
// Tx amount
$output->setValue(1000);
// Satoshis
// For Sample Purposes Only.
$request = clone $tx;
$txClient = new TXClient($apiContext);
$txSkeleton = $txClient->create($tx);
ResultPrinter::printResult("New TX Endpoint", "TXSkeleton", $txSkeleton->getTx()->getHash(), $request, $txSkeleton);
Exemple #5
0
 /**
  * @dataProvider mockProvider
  * @param TX $obj
  */
 public function testCreate($obj, $mockApiContext)
 {
     $mockBlockCypherRestCall = $this->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock();
     $mockBlockCypherRestCall->expects($this->any())->method('execute')->will($this->returnValue(TXSkeletonTest::getJson()));
     $result = $obj->create($mockApiContext, $mockBlockCypherRestCall);
     $this->assertNotNull($result);
     $this->assertInstanceOf('\\BlockCypher\\Api\\TXSkeleton', $result);
 }
Exemple #6
0
 /**
  * Create a new TX.
  *
  * @param TX $tx
  * @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(TX $tx, $apiContext = null, $restCall = null)
 {
     $payLoad = $tx->toJSON();
     $chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
     $json = $this->executeCall("{$chainUrlPrefix}/txs/new", "POST", $payLoad, null, $apiContext, $restCall);
     $txSkeleton = new TXSkeleton();
     $txSkeleton->fromJson($json);
     return $txSkeleton;
 }
Exemple #7
0
 /**
  * Create a new TX.
  *
  * @param TX $tx
  * @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(TX $tx, $apiContext = null, $restCall = null)
 {
     // TODO: change signature. Add $params = array() after TX $tx
     //ArgumentGetParamsValidator::validate($params, 'params');
     //$allowedParams = array(
     //    'includeToSignTx' => 1,
     //);
     //$params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
     $payLoad = $tx->toJSON();
     $chainUrlPrefix = $this->getChainUrlPrefix($apiContext);
     $json = $this->executeCall("{$chainUrlPrefix}/txs/new", "POST", $payLoad, null, $apiContext, $restCall);
     $txSkeleton = new TXSkeleton();
     $txSkeleton->fromJson($json);
     return $txSkeleton;
 }
Exemple #8
0
 /**
  * Push the raw transaction to the network.
  *
  * @deprecated since version 1.2. Use TXClient.
  * @param string $hexRawTx
  * @param array $params Parameters. Options: instart, outstart and limit
  * @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 TX
  */
 public static function push($hexRawTx, $params = array(), $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($hexRawTx, 'hexRawTx');
     ArgumentGetParamsValidator::validate($params, 'params');
     $allowedParams = array();
     $params = ArgumentGetParamsValidator::sanitize($params, $allowedParams);
     $txHex = new TXHex();
     $txHex->setTx($hexRawTx);
     $payLoad = $txHex->toJSON();
     $chainUrlPrefix = self::getChainUrlPrefix($apiContext);
     $json = self::executeCall("{$chainUrlPrefix}/txs/push?" . http_build_query($params), "POST", $payLoad, null, $apiContext, $restCall);
     $ret = new TX();
     $ret->fromJson($json);
     return $ret;
 }
<?php

// Run on console:
// php -f .\sample\transaction-api\CreateTxToFundMultisigAddrEndpoint.php
// You can also use builders, see CreateTxToFundMultisigAddrWithBuilderEndpoint.php sample
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\TX;
use BlockCypher\Api\TXInput;
use BlockCypher\Api\TXOutput;
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\TXClient;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('test3', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$input = new TXInput();
$output = new TXOutput();
$tx = new TX();
$tx->setInputs(array($input->addAddress("n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4")))->setOutputs(array($output->setAddresses(array("03798be8162d7d6bc5c4e3b236100fcc0dfee899130f84c97d3a49faf83450fd81", "03dd9f1d4a39951013b4305bf61887ada66439ab84a9a2f8aca9dc736041f815f1", "03c8e6e99c1d0b42120d5cf40c963e5e8048fd2d2a184758784a041a9d101f1f02"))->setScriptType("multisig-2-of-3")->setValue(1000)));
$txClient = new TXClient($apiContext);
$txSkeleton = $txClient->create($tx);
ResultPrinter::printResult("Created Multisig TX", "TXSkeleton", $txSkeleton->getTx()->getHash(), $tx, $txSkeleton);
Exemple #10
0
 public function testMultipleEmptyArrayConversion()
 {
     /** @noinspection SpellCheckingInspection */
     $json = '{"block_hash":"0000000000000000c504bdea36e531d8089d324f2d936c86e3274f97f8a44328","inputs":[{"related_resources":[{},{}]}]}';
     $transaction = new TX($json);
     $result = $transaction->toJSON();
     $this->assertContains('"related_resources":[{},{}]', $result);
     $this->assertNotNull($result);
 }