subscribe(target, callback, options = [], subId = '') { this.connect(); if (subId === '') { subId = Random.hex()(Random.engines.nativeMath, 64); } if (this.connected) { return this.session.subscribe(target, callback, options).then(function(subscription) { this.client.subscriptionMap.set(this.subId, subscription); return this.subId; }.bind({ client: this, subId: subId, })); } let deferred = when.defer(); this.queuedCalls.push(deferred); return deferred.promise.then(function() { return this.client.subscribe(this.target, this.callback, this.options); }.bind({ client: this, target: target, callback: callback, options: options, })); }
"use strict"; var express = require('express'); var router = express.Router(); var Wallet = require('../lib/wallet'); var Random = require('random-js'); var engine = Random.engines.nativeMath; var distribution = Random.hex(false); var Orders = require('../models').Order; var MoneroPrices = require('monero-prices'); var Q = require('q'); var uuid = require('node-uuid'); var padding = "000000000000000000000000000000000000000000000000"; var sanitize = require('../lib/sanitizer'); /* GET /order */ router.get('/', function(req, res, next){ res.render('form'); }); /* POST /order */ router.post('/', function(req, res, next){ var order = sanitize(req); order.payment_id = generatePaymentID(); order.uuid = uuid.v4(); Q.spawn(function* () { // generate the integrated address for the unique payment id order.integrated_address = yield generateIntegratedAddress(order.payment_id); // calculate the exchange rate of order based on $2.50 USD order.amount = yield calculatePrice(); // add zero padding to make the special payment id compatible for searching