Esempio n. 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);
 }
Esempio n. 2
0
})->bind('request.payment');
$app->get('/info/{slug}', function (\Silex\Application $app, $slug) {
    /** @var \BitWasp\Payments\Db\Request $request */
    $request = \BitWasp\Payments\Db\Request::find(['slug' => $slug]);
    if ($request == null) {
        return '404';
    }
    /** @var \BitWasp\Payments\Db\OutputRequirement[] $requirements */
    $requirements = \BitWasp\Payments\Db\OutputRequirement::find('all', ['request_id' => $request->id]);
    $reqs = [];
    foreach ($requirements as $req) {
        $info = $req->to_array();
        $info['scriptHex'] = bin2hex($info['script']);
        $reqs[] = $info;
    }
    $transactions = \BitWasp\Payments\Db\Transaction::find(['request_id' => $request->id]);
    print_r($transactions);
    // bitcoin:1Git6aSVJKHK34VGS2AFubnPK92rt9Wjg?amount=0.000377&r=https%3A%2F%2Fbitpay.com%2Fi%2FHztrqbJH3piKUskxkBfr8b
    $url = urlencode($app->url('request.request', ['slug' => $request->slug]));
    $bitcoinUrl = "bitcoin:" . $requirements[0]->address . "?amount=" . $request->valuebtc . "&r=" . $url;
    //$bitcoinUrl = "bitcoin:?r=" . $url;
    //echo $bitcoinUrl . "\n";
    return $app['twig']->render('info.html.twig', ['request' => $request->to_array(), 'requirements' => $reqs, 'address' => $reqs[0]['address'], 'url' => $url, 'bitcoinUrl' => $bitcoinUrl]);
})->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);