/** * @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 TXOutput */ public function build() { $txOutput = new TXOutput(); $txOutput->setAddresses($this->addresses); $txOutput->setScriptType($this->scryptType); $txOutput->setValue($this->value); return $txOutput; }
/** * @depends testSerializationDeserialization * @param TXOutput $obj */ public function testGetters($obj) { $this->assertEquals($obj->getValue(), 70320221545); $this->assertEquals($obj->getScript(), "76a914e6aad9d712c419ea8febf009a3f3bfdd8d222fac88ac"); $this->assertEquals($obj->getSpentBy(), "35832d6c70b98b54e9a53ab2d51176eb19ad11bc4505d6bb1ea6c51a68cb92ee"); $this->assertEquals($obj->getAddress(), "1N2f642sbgCMbNtXFajz9XDACDFnFzdXzV"); $this->assertEquals($obj->getAddresses(), array("1N2f642sbgCMbNtXFajz9XDACDFnFzdXzV")); $this->assertEquals($obj->getScriptType(), "pay-to-pubkey-hash"); }
<?php // Run on console: // php -f .\sample\transaction-api\CreateTransactionToFundMultisigAddressEndpoint.php 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(); $input->addAddress("n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4"); $output = new TXOutput(); $output->setAddresses(array("03798be8162d7d6bc5c4e3b236100fcc0dfee899130f84c97d3a49faf83450fd81", "03dd9f1d4a39951013b4305bf61887ada66439ab84a9a2f8aca9dc736041f815f1", "03c8e6e99c1d0b42120d5cf40c963e5e8048fd2d2a184758784a041a9d101f1f02")); $output->setScriptType("multisig-2-of-3"); $output->setValue(1000); // Satoshis $tx = new TX(); $tx->addInput($input); $tx->addOutput($output); $txClient = new TXClient($apiContext); $txSkeleton = $txClient->create($tx); ResultPrinter::printResult("Created Multisig TX", "TXSkeleton", $txSkeleton->getTx()->getHash(), $tx, $txSkeleton);