Beispiel #1
0
 public function __construct(LoopInterface $loop)
 {
     $context = new \React\ZMQ\Context($loop);
     $pusher = new Pusher();
     $workers = $context->getSocket(\ZMQ::SOCKET_PUSH);
     $workers->bind("tcp://127.0.0.1:5557");
     // Listen for work from the web
     $receiver = $context->getSocket(\ZMQ::SOCKET_PULL);
     $receiver->bind("tcp://127.0.0.1:5555");
     $receiver->on('message', function ($msg) use($workers) {
         // Create
         echo "Received: " . $msg . "\n";
         $workers->send($msg);
     });
     $control = $context->getSocket(\ZMQ::SOCKET_PULL);
     $control->bind('tcp://127.0.0.1:5510');
     $control->on('message', function ($msg) use($pusher) {
         echo "CONTROL MESSAGE\n";
         $arr = json_decode($msg, true);
         $slug = $arr['slug'];
         $req = $arr['req'];
         $pusher->send($slug, $arr['req']);
     });
     $listener = $context->getSocket(\ZMQ::SOCKET_PULL);
     $listener->bind('tcp://127.0.0.1:5559');
     $listener->on('message', function ($msg) use($pusher) {
         echo " + - - - - - - - - - + \n";
         echo "       RESULTS         \n";
         print_r($msg);
         $message = json_decode($msg, true);
         if ($message['command'] == 'client.gotRequest') {
             $pusher->onClientGotRequest($message['slug']);
         } else {
             if ($message['command'] == 'client.gotPayment') {
                 $pusher->onClientGotPayment($message['slug']);
             } else {
                 if ($message['command'] == 'tx.complete') {
                     try {
                         $request = Request::find(['slug' => $message['slug']]);
                         $transaction = TransactionFactory::fromHex($message['tx']);
                         Transaction::create(['transaction' => $message['tx'], 'request_id' => $request->id, 'txid' => $transaction->getTransactionId()]);
                         $pusher->onCompleteTx($message['slug'], $message['tx']);
                     } catch (\Exception $e) {
                         return;
                     }
                 } else {
                     if ($message['command'] == 'tx.partial') {
                         $pusher->onCompleteTx($message['slug'], $message['tx']);
                     }
                 }
             }
         }
         echo "\n + - - - - - - - - - + \n\n";
     });
     // Set up our WebSocket server for clients wanting real-time updates
     $webSock = new \React\Socket\Server($loop);
     $webSock->listen(8080, '0.0.0.0');
     // Binding to 0.0.0.0 means remotes can connect
     $webServer = new \Ratchet\Server\IoServer(new \Ratchet\Http\HttpServer(new \Ratchet\WebSocket\WsServer(new \Ratchet\Wamp\WampServer($pusher))), $webSock);
 }
Beispiel #2
0
<?php

require "../vendor/autoload.php";
require "../db/bootstrap.php";
use BitWasp\Payments\Db\Request;
use BitWasp\Payments\Db\OutputRequirement;
Request::delete_all(array('conditions' => []));
OutputRequirement::delete_all(array('conditions' => []));
Beispiel #3
0
})->bind('info');
$app->match('/new', function (\Symfony\Component\HttpFoundation\Request $request) use($app) {
    // some default data for when the form is displayed the first time
    /** @var \Symfony\Component\Form\FormFactory $factory */
    $factory = $app['form.factory'];
    $form = $factory->createBuilder()->add('address', 'text', array('attr' => array('class' => 'form-control', 'placeholder' => 'Bitcoin address'), 'constraints' => [new \Symfony\Component\Validator\Constraints\NotBlank(), new \BitWasp\Payments\Application\Validator\BitcoinAddress()]))->add('value', 'text', array('attr' => array('class' => 'form-control', 'placeholder' => 'Amount in satoshis'), 'constraints' => new \Symfony\Component\Validator\Constraints\NotBlank()))->add('send', 'submit', array('attr' => array('class' => 'btn btn-lg btn-primary btn-block')))->getForm();
    if ('POST' == $request->getMethod()) {
        $form->bind($request);
        if ($form->isValid()) {
            $data = $form->getData();
            $address = \BitWasp\Bitcoin\Address\AddressFactory::fromString($data['address']);
            $script = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToAddress($address);
            $txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($data['value'], $script);
            $slug = bin2hex(openssl_random_pseudo_bytes(32));
            $signer = new \BitWasp\Bitcoin\PaymentProtocol\PaymentRequestSigner('none');
            $builder = new \BitWasp\Bitcoin\PaymentProtocol\PaymentRequestBuilder($signer, 'main', time());
            $builder->addOutput($txOut);
            $details = $builder->getPaymentDetails();
            $details->setPaymentUrl($app->url('request.payment', ['slug' => $slug]));
            $request = $builder->getPaymentRequest();
            $totalValue = $data['value'];
            $amount = new \BitWasp\Bitcoin\Amount();
            $dbRequest = \BitWasp\Payments\Db\Request::create(['slug' => $slug, 'value' => $totalValue, 'valueBtc' => $amount->toBtc($data['value']), 'payment_request' => $request->serialize()]);
            $output = \BitWasp\Payments\Db\OutputRequirement::create(['request_id' => $dbRequest->id, 'value' => $data['value'], 'valueBtc' => $amount->toBtc($data['value']), 'address' => $data['address'], 'script' => $txOut->getScript()->getBinary()]);
            $app['request_api']->pushRequest($slug, [$output]);
            return $app->redirect($app['url_generator']->generate('info', array('slug' => $dbRequest->slug)));
        }
    }
    return $app['twig']->render('new.twig', ['form' => $form->createView(), 'errors' => $form->getErrors()]);
})->bind('new');
$app->run();
<?php

require "../vendor/autoload.php";
require "../db/bootstrap.php";
$address = \BitWasp\Bitcoin\Address\AddressFactory::fromString('1J7jgWATD4Vfe9eUs7EL4YdadbPaM7cGgj');
$script = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToAddress($address);
/** @var \BitWasp\Bitcoin\Transaction\TransactionOutputInterface[] $outputs */
$outputs = [new \BitWasp\Bitcoin\Transaction\TransactionOutput(1000000, $script)];
$signer = new \BitWasp\Bitcoin\PaymentProtocol\PaymentRequestSigner('none');
$builder = new \BitWasp\Bitcoin\PaymentProtocol\PaymentRequestBuilder($signer, 'main', time());
foreach ($outputs as $output) {
    $builder->addOutput($output);
}
$request = $builder->getPaymentRequest();
$value = 1000000;
$amount = new \BitWasp\Bitcoin\Amount();
$list = \BitWasp\Payments\Db\Request::create(['slug' => bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)), 'value' => $value, 'valueBtc' => $amount->toBtc($value), 'payment_request' => $request->serialize()]);
$req = [];
foreach ($outputs as $output) {
    $req[] = \BitWasp\Payments\Db\OutputRequirement::create(['request_id' => $list->id, 'value' => $output->getValue(), 'valueBtc' => $amount->toBtc($value), 'script' => $output->getScript()->getBinary(), 'address' => $address->getAddress()]);
}
<?php

require "../vendor/autoload.php";
require "../db/bootstrap.php";
$list = \BitWasp\Payments\Db\Request::find('all');
print_r($list);
 /**
  * @param array $on
  * @return Request
  * @throws \ActiveRecord\RecordNotFound
  */
 private function getRequest(array $on)
 {
     return Request::find($on);
 }