Remove legacy backend and update license
This commit is contained in:
parent
b8ea3e79cf
commit
c40c742b81
15 changed files with 182 additions and 787 deletions
7
COPYING
Normal file
7
COPYING
Normal file
|
@ -0,0 +1,7 @@
|
|||
Copyright (c) 2022 Vergara Technologies LLC
|
||||
|
||||
This package ("Original Work") is licensed under the terms of the Bootstrap
|
||||
Open Source License, version 1.0, or at your option, any later version
|
||||
("BOSL"). See the file ./LICENSE for the terms of the Bootstrap Open Source
|
||||
Licence, version 1.0.
|
||||
|
192
LICENSE
192
LICENSE
|
@ -1,20 +1,178 @@
|
|||
The MIT License (MIT)
|
||||
Copyright © 2022 Vergara Technologies LLC
|
||||
Copyright (c) 2022 Vergara Technologies
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
=======================================================
|
||||
Bootstrap Open Source Licence ("BOSL") v. 1.0
|
||||
=======================================================
|
||||
This Bootstrap Open Source Licence (the "License") applies to any original work
|
||||
of authorship (the "Original Work") whose owner (the "Licensor") has placed the
|
||||
following licensing notice adjacent to the copyright notice for the Original
|
||||
Work:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
*Licensed under the Bootstrap Open Source Licence version 1.0*
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1. **Grant of Copyright License.** Licensor grants You a worldwide,
|
||||
royalty-free, non-exclusive, sublicensable license, for the duration of the
|
||||
copyright in the Original Work, to do the following:
|
||||
|
||||
a. to reproduce the Original Work in copies, either alone or as part of
|
||||
a collective work;
|
||||
|
||||
b. to translate, adapt, alter, transform, modify, or arrange the
|
||||
Original Work, thereby creating derivative works ("Derivative Works")
|
||||
based upon the Original Work;
|
||||
|
||||
c. to distribute or communicate copies of the Original Work and
|
||||
Derivative Works to the public, provided that prior to any such
|
||||
distribution or communication You first place a machine-readable copy
|
||||
of the Source Code of the Original Work and such Derivative Works that
|
||||
You intend to distribute or communicate in an information repository
|
||||
reasonably calculated to permit inexpensive and convenient access
|
||||
thereto by the public (“Information Repository”) for as long as You
|
||||
continue to distribute or communicate said copies, accompanied by an
|
||||
irrevocable offer to license said copies to the public free of charge
|
||||
under this License, said offer valid starting no later than 12 months
|
||||
after You first distribute or communicate said copies;
|
||||
|
||||
d. to perform the Original Work publicly; and
|
||||
|
||||
e. to display the Original Work publicly.
|
||||
|
||||
2. **Grant of Patent License.** Licensor grants You a worldwide, royalty-free,
|
||||
non-exclusive, sublicensable license, under patent claims owned or controlled
|
||||
by the Licensor that are embodied in the Original Work as furnished by the
|
||||
Licensor, for the duration of the patents, to make, use, sell, offer for sale,
|
||||
have made, and import the Original Work and Derivative Works.
|
||||
|
||||
3. **Grant of Source Code License.** The "Source Code" for a work means the
|
||||
preferred form of the work for making modifications to it and all available
|
||||
documentation describing how to modify the work. Licensor agrees to provide a
|
||||
machine-readable copy of the Source Code of the Original Work along with each
|
||||
copy of the Original Work that Licensor distributes. Licensor reserves the
|
||||
right to satisfy this obligation by placing a machine-readable copy of said
|
||||
Source Code in an Information Repository for as long as Licensor continues to
|
||||
distribute the Original Work.
|
||||
|
||||
4. **Exclusions From License Grant.** Neither the names of Licensor, nor the
|
||||
names of any contributors to the Original Work, nor any of their trademarks or
|
||||
service marks, may be used to endorse or promote products derived from this
|
||||
Original Work without express prior permission of the Licensor. Except as
|
||||
expressly stated herein, nothing in this License grants any license to
|
||||
Licensor's trademarks, copyrights, patents, trade secrets or any other
|
||||
intellectual property. No patent license is granted to make, use, sell, offer
|
||||
for sale, have made, or import embodiments of any patent claims other than the
|
||||
licensed claims defined in Section 2. No license is granted to the trademarks
|
||||
of Licensor even if such marks are included in the Original Work. Nothing in
|
||||
this License shall be interpreted to prohibit Licensor from licensing under
|
||||
terms different from this License any Original Work that Licensor otherwise
|
||||
would have a right to license.
|
||||
|
||||
5. **External Deployment.** The term "External Deployment" means the use,
|
||||
distribution, or communication of the Original Work or Derivative Works in any
|
||||
way such that the Original Work or Derivative Works may be used by anyone other
|
||||
than You, whether those works are distributed or communicated to those persons
|
||||
or made available as an application intended for use over a network. As an
|
||||
express condition for the grants of license hereunder, You must treat any
|
||||
External Deployment by You of the Original Work or a Derivative Work as a
|
||||
distribution under section 1(c).
|
||||
|
||||
6. **Attribution Rights.** You must retain, in the Source Code of any
|
||||
Derivative Works that You create, all copyright, patent, or trademark notices
|
||||
from the Source Code of the Original Work, as well as any notices of licensing
|
||||
and any descriptive text identified therein as an "Attribution Notice." You
|
||||
must cause the Source Code for any Derivative Works that You create to carry a
|
||||
prominent Attribution Notice reasonably calculated to inform recipients that
|
||||
You have modified the Original Work.
|
||||
|
||||
7. **Warranty of Provenance and Disclaimer of Warranty.** Licensor warrants
|
||||
that the copyright in and to the Original Work and the patent rights granted
|
||||
herein by Licensor are owned by the Licensor or are sublicensed to You under
|
||||
the terms of this License with the permission of the contributor(s) of those
|
||||
copyrights and patent rights. Except as expressly stated in the immediately
|
||||
preceding sentence, the Original Work is provided under this License on an "AS
|
||||
IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without
|
||||
limitation, the warranties of non-infringement, merchantability or fitness for
|
||||
a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS
|
||||
WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this
|
||||
License. No license to the Original Work is granted by this License except
|
||||
under this disclaimer.
|
||||
|
||||
8. **Limitation of Liability.** Under no circumstances and under no legal
|
||||
theory, whether in tort (including negligence), contract, or otherwise, shall
|
||||
the Licensor be liable to anyone for any indirect, special, incidental, or
|
||||
consequential damages of any character arising as a result of this License or
|
||||
the use of the Original Work including, without limitation, damages for loss of
|
||||
goodwill, work stoppage, computer failure or malfunction, or any and all other
|
||||
commercial damages or losses. This limitation of liability shall not apply to
|
||||
the extent applicable law prohibits such limitation.
|
||||
|
||||
9. **Acceptance and Termination.** If, at any time, You expressly assented to
|
||||
this License, that assent indicates your clear and irrevocable acceptance of
|
||||
this License and all of its terms and conditions. If You distribute or
|
||||
communicate copies of the Original Work or a Derivative Work, You must make a
|
||||
reasonable effort under the circumstances to obtain the express assent of
|
||||
recipients to the terms of this License. This License conditions your rights to
|
||||
undertake the activities listed in Section 1, including your right to create
|
||||
Derivative Works based upon the Original Work, and doing so without honoring
|
||||
these terms and conditions is prohibited by copyright law and international
|
||||
treaty. Nothing in this License is intended to affect copyright exceptions and
|
||||
limitations (including 'fair use' or 'fair dealing'). This License shall
|
||||
terminate immediately and You may no longer exercise any of the rights granted
|
||||
to You by this License upon your failure to honor the conditions in Section
|
||||
1(c).
|
||||
|
||||
10. **Termination for Patent Action.** This License shall terminate
|
||||
automatically and You may no longer exercise any of the rights granted to You
|
||||
by this License as of the date You commence an action, including a cross-claim
|
||||
or counterclaim, against Licensor or any licensee alleging that the Original
|
||||
Work infringes a patent. This termination provision shall not apply for an
|
||||
action alleging patent infringement by combinations of the Original Work with
|
||||
other software or hardware.
|
||||
|
||||
11. **Jurisdiction, Venue and Governing Law.** Any action or suit relating to
|
||||
this License may be brought only in the courts of a jurisdiction wherein the
|
||||
Licensor resides or in which Licensor conducts its primary business, and under
|
||||
the laws of that jurisdiction excluding its conflict-of-law provisions. The
|
||||
application of the United Nations Convention on Contracts for the International
|
||||
Sale of Goods is expressly excluded. Any use of the Original Work outside the
|
||||
scope of this License or after its termination shall be subject to the
|
||||
requirements and penalties of copyright or patent law in the appropriate
|
||||
jurisdiction. This section shall survive the termination of this License.
|
||||
|
||||
12. **Attorneys' Fees.** In any action to enforce the terms of this License or
|
||||
seeking damages relating thereto, the prevailing party shall be entitled to
|
||||
recover its costs and expenses, including, without limitation, reasonable
|
||||
attorneys' fees and costs incurred in connection with such action, including
|
||||
any appeal of such action. This section shall survive the termination of this
|
||||
License.
|
||||
|
||||
13. **Miscellaneous.** If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent necessary to
|
||||
make it enforceable.
|
||||
|
||||
14. **Definition of "You" in This License.** "You" throughout this License,
|
||||
whether in upper or lower case, means an individual or a legal entity
|
||||
exercising rights under, and complying with all of the terms of, this License.
|
||||
For legal entities, "You" includes any entity that controls, is controlled by,
|
||||
or is under common control with you. For purposes of this definition, "control"
|
||||
means (i) the power, direct or indirect, to cause the direction or management
|
||||
of such entity, whether by contract or otherwise, or (ii) ownership of fifty
|
||||
percent (50%) or more of the outstanding shares, or (iii) beneficial ownership
|
||||
of such entity.
|
||||
|
||||
15. **Right to Use.** You may use the Original Work in all ways not otherwise
|
||||
restricted or conditioned by this License or by law, and Licensor promises not
|
||||
to interfere with or be responsible for such uses by You.
|
||||
|
||||
16. **Modification of This License.** This License is Copyright © 2007 Zooko
|
||||
Wilcox-O'Hearn. Permission is granted to copy, distribute, or communicate this
|
||||
License without modification. Nothing in this License permits You to modify
|
||||
this License as applied to the Original Work or to Derivative Works. However,
|
||||
You may modify the text of this License and copy, distribute or communicate
|
||||
your modified version (the "Modified License") and apply it to other original
|
||||
works of authorship subject to the following conditions: (i) You may not
|
||||
indicate in any way that your Modified License is the "Bootstrap Open Source
|
||||
Licence" or "BOSL" and you may not use those names in the name of your Modified
|
||||
License; and (ii) You must replace the notice specified in the first paragraph
|
||||
above with the notice "Licensed under <insert your license name here>" or with
|
||||
a notice of your own that is not confusingly similar to the notice in this
|
||||
License.
|
||||
|
|
631
backend/app.js
631
backend/app.js
|
@ -1,631 +0,0 @@
|
|||
const express = require('express');
|
||||
const app = express();
|
||||
const bodyparser = require('body-parser');
|
||||
const cors = require('cors');
|
||||
const crypto = require('crypto');
|
||||
const postmodel = require('./models/post');
|
||||
const usermodel = require('./models/user');
|
||||
const ownermodel = require('./models/owner');
|
||||
const itemmodel = require('./models/item');
|
||||
const ordermodel = require('./models/order');
|
||||
const pricemodel = require('./models/price');
|
||||
const txmodel = require('./models/tx');
|
||||
const paymentmodel = require('./models/payment');
|
||||
const zecTxModel = require('./models/zectxs.js');
|
||||
const countryModel = require('./models/country.js');
|
||||
const mongoose = require('mongoose');
|
||||
const stdrpc = require('stdrpc');
|
||||
const CoinGecko = require('coingecko-api');
|
||||
var URLSafeBase64 = require('urlsafe-base64');
|
||||
var Buffer = require('buffer/').Buffer;
|
||||
|
||||
var db = require('./config/db');
|
||||
mongoose.connect('mongodb://'+db.user+':'+db.password+'@'+db.server+'/'+db.database).then(() => {
|
||||
console.log("connecting-- ", db.database);
|
||||
}).catch(() => {
|
||||
console.log("connection failed!");
|
||||
});
|
||||
|
||||
var fullnode = require('./config/fullnode');
|
||||
const rpc = stdrpc({
|
||||
url: fullnode.url,
|
||||
username: fullnode.username,
|
||||
password: fullnode.password
|
||||
});
|
||||
|
||||
var async = require('async');
|
||||
|
||||
const CoinGeckoClient = new CoinGecko();
|
||||
|
||||
var intervalObject = setInterval( function() {
|
||||
CoinGeckoClient.simple.price({
|
||||
ids: ['zcash'],
|
||||
vs_currencies: ['usd', 'gbp', 'eur', 'cad', 'aud']
|
||||
}).then((data) => {
|
||||
pricemodel.findOneAndUpdate({currency: 'usd'}, { price: data.data.zcash.usd, timestamp: Date.now()}, {new:true, upsert:true}, function(err,docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
pricemodel.findOneAndUpdate({currency: 'gbp'}, { price: data.data.zcash.gbp, timestamp: Date.now()}, {new:true, upsert:true}, function(err,docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
pricemodel.findOneAndUpdate({currency: 'eur'}, { price: data.data.zcash.eur, timestamp: Date.now()}, {new:true, upsert:true}, function(err,docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
pricemodel.findOneAndUpdate({currency: 'cad'}, { price: data.data.zcash.cad, timestamp: Date.now()}, {new:true, upsert:true}, function(err,docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
pricemodel.findOneAndUpdate({currency: 'aud'}, { price: data.data.zcash.aud, timestamp: Date.now()}, {new:true, upsert:true}, function(err,docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}, 90000);
|
||||
|
||||
function hexToString(hexString) {
|
||||
var str = '';
|
||||
for (var n=0; n < hexString.length; n +=2) {
|
||||
str += String.fromCharCode(parseInt(hexString.substr(n, 2), 16));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function sendPin(pin, address) {
|
||||
//var memo = URLSafeBase64.encode(Buffer.from('ZGO pin: '.concat(pin)));
|
||||
var memo = Buffer.from('ZGo PIN: '.concat(pin)).toString('hex');
|
||||
//console.log(typeof(memo));
|
||||
var amounts = [
|
||||
{
|
||||
address: address,
|
||||
amount: 0.00000001,
|
||||
memo: memo
|
||||
}
|
||||
];
|
||||
rpc.z_sendmany(fullnode.addr, amounts).catch((err) => {
|
||||
console.log('Sendmany', err);
|
||||
});
|
||||
}
|
||||
|
||||
var blockInterval = setInterval( function() {
|
||||
console.log('Node periodic Zcash scan');
|
||||
rpc.z_listreceivedbyaddress(fullnode.addr, 1).then(txs => {
|
||||
var re = /.*ZGO::(.*)\sReply-To:\s(z\w+)/;
|
||||
var pay = /.*ZGOp::(.*)/;
|
||||
async.each (txs, function(txData, callback) {
|
||||
var memo = hexToString(txData.memo).replace(/\0/g, '');
|
||||
if (!txData.change) {
|
||||
zecTxModel.updateOne({txid: txData.txid}, { txid: txData.txid, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (re.test(memo) && txData.confirmations < 100) {
|
||||
//console.log('Processing tx:', memo);
|
||||
var match = re.exec(memo);
|
||||
if (match != null) {
|
||||
var address = match[2];
|
||||
var session = match[1];
|
||||
var blocktime = txData.blocktime;
|
||||
var amount = txData.amount;
|
||||
var expiration = blocktime;
|
||||
//console.log(' ', session, blocktime);
|
||||
txmodel.updateOne({txid: txData.txid}, { txid: txData.txid, address: address, session: session, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
if (txData.confirmations >= 2 ) {
|
||||
usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){
|
||||
if (doc == null){
|
||||
console.log('User not found', session, blocktime);
|
||||
const n = crypto.randomInt(0, 10000000);
|
||||
const pin = n.toString().padStart(6, '0');
|
||||
sendPin(pin, address);
|
||||
var user = new usermodel({
|
||||
address: address,
|
||||
session: session,
|
||||
blocktime: blocktime,
|
||||
pin: pin,
|
||||
validated: false
|
||||
});
|
||||
user.save(function(error) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
console.log('User saved');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
var exptime = 0;
|
||||
if (pay.test(memo) && txData.confirmations < 100) {
|
||||
var match2 = pay.exec(memo);
|
||||
if (match2 != null) {
|
||||
var session = match2[1];
|
||||
}
|
||||
if (txData.amount >= 0.001 && txData.amount < 0.005){
|
||||
exptime = txData.blocktime + 3600;
|
||||
} else if (txData.amount >= 0.005 && txData.amount < 0.025){
|
||||
exptime = txData.blocktime + 24*3600;
|
||||
} else if (txData.amount >= 0.025 && txData.amount < 0.1) {
|
||||
exptime = txData.blocktime + 7*24*3600;
|
||||
} else if (txData.amount >= 0.1) {
|
||||
exptime = txData.blocktime + 4*7*24*3600;
|
||||
}
|
||||
|
||||
usermodel.findOne({session: session}).then(function(doc){
|
||||
if(doc != null) {
|
||||
paymentmodel.findOne({address: doc.address, blocktime: txData.blocktime, amount: txData.amount}).then(function(payments){
|
||||
if(payments == null){
|
||||
var payment = new paymentmodel({
|
||||
address: doc.address,
|
||||
blocktime: txData.blocktime,
|
||||
expiration: new Date(exptime * 1000),
|
||||
amount: txData.amount,
|
||||
session: doc.session
|
||||
});
|
||||
|
||||
payment.save(function(error) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log('Payment saved');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
console.log('Txs synced');
|
||||
});
|
||||
|
||||
});
|
||||
}, 75000);
|
||||
|
||||
var payCheck = setInterval( function() {
|
||||
|
||||
ownermodel.find({}).then((documents) => {
|
||||
if(documents.length > 0){
|
||||
//console.log(documents);
|
||||
async.each (documents, function(document, callback) {
|
||||
paymentmodel.findOne({ address: document.address, expiration: {$gt: Date.now()}}).then(payment => {
|
||||
if (payment != null){
|
||||
document.paid = true;
|
||||
document.save();
|
||||
} else {
|
||||
document.paid = false;
|
||||
document.save();
|
||||
}
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("Owners checked for payment");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
app.use(cors());
|
||||
app.options('*', cors());
|
||||
|
||||
app.use(bodyparser.json());
|
||||
|
||||
app.use((req, res, next) => {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS");
|
||||
next();
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.headers.authorization !== 'Le2adeic8Thah4Aeng4daem6i' ) {
|
||||
return res.status(401).send('Authorization required.');
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
app.get('/api/countries', (req, res, next) => {
|
||||
console.log('Get: /api/countries');
|
||||
countryModel.find({}).then((documents) => {
|
||||
if (documents != null) {
|
||||
res.status(200).json({
|
||||
message: 'Country data found',
|
||||
countries: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'No country data available'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/users', (req, res, next) => {
|
||||
console.log('Get: /api/users');
|
||||
usermodel.find({'address': req.query.address, 'session': req.query.session, 'expired': { $ne: true}}).
|
||||
then((documents) => {
|
||||
if (documents != null) {
|
||||
res.status(200).json({
|
||||
message: 'Users found successfully',
|
||||
users: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'User not found',
|
||||
users: null
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/pending', (req, res, next) => {
|
||||
console.log('Get: /api/pending', req.query.session);
|
||||
txmodel.find({'session': req.query.session, 'confirmations': {$lt: 10}}).
|
||||
then((documents) => {
|
||||
if (documents.length > 0) {
|
||||
//console.log('pending', documents);
|
||||
res.status(200).json({
|
||||
message: 'Found pending txs',
|
||||
txs: documents
|
||||
});
|
||||
} else {
|
||||
//console.log('pending not found', documents);
|
||||
res.status(204).json({
|
||||
message: 'No txs found',
|
||||
txs: null
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/getuser', (req, res, next) => {
|
||||
console.log('Get: /api/getuser/', req.query.session);
|
||||
usermodel.find({'session': req.query.session, 'expired': { $ne: true }}).
|
||||
then((documents) => {
|
||||
if(documents.length > 0){
|
||||
//console.log(documents);
|
||||
console.log(' found user');
|
||||
res.status(200).json({
|
||||
message: 'User found!',
|
||||
user: documents
|
||||
});
|
||||
} else {
|
||||
console.log(' did not find user');
|
||||
res.status(204).json({
|
||||
message: 'User not found!',
|
||||
user: null
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/blockheight', (req, res, next) => {
|
||||
console.log('Get: /api/blockheight');
|
||||
rpc.getblock("-1", 1).then(block => {
|
||||
res.status(200).json({
|
||||
message: 'Found block',
|
||||
height: block.height
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/txs', (req, res, next) => {
|
||||
console.log('Get: /api/txs');
|
||||
rpc.z_listreceivedbyaddress(fullnode.addr, 10).then(txs => {
|
||||
res.status(200).json({
|
||||
message: 'Transactions found',
|
||||
txs: txs
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/getaddr', (req, res, next) => {
|
||||
console.log('Get: /api/getaddr');
|
||||
res.status(200).json({
|
||||
message: 'Sending address',
|
||||
addr: fullnode.addr
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/getowner', (req, res, next) => {
|
||||
console.log('Get: /api/getowner');
|
||||
ownermodel.find({'address': req.query.address}).then((documents) => {
|
||||
if(documents.length > 0){
|
||||
//console.log(documents);
|
||||
res.status(200).json({
|
||||
message: 'Owner found!',
|
||||
owner: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'Owner not found!',
|
||||
owner: null
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.post('/api/addowner', (req, res, next) => {
|
||||
console.log('Post: /api/addowner');
|
||||
const owner = new ownermodel(req.body.owner);
|
||||
owner.save();
|
||||
res.status(201).json({
|
||||
message: 'Owner added successfully'
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/validateuser', (req, res, next) => {
|
||||
console.log('Post: /api/validateuser');
|
||||
usermodel.findByIdAndUpdate(req.body.user._id, req.body.user,
|
||||
function(err, docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(201).json({
|
||||
message: 'User Validated',
|
||||
user: docs
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/updateowner', (req, res, next) => {
|
||||
console.log('Post: /api/updateowner');
|
||||
ownermodel.findByIdAndUpdate(req.body.owner._id, req.body.owner,
|
||||
function(err, docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log(docs);
|
||||
res.status(201).json({
|
||||
message: 'Owner updated',
|
||||
owner: docs
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/getitems', (req, res, next) => {
|
||||
console.log('Get: /api/getitems');
|
||||
//console.log('getitems', req.query.address);
|
||||
if (req.query.address.length > 0 ) {
|
||||
const items = itemmodel.find({user: req.query.address}).then((documents) => {
|
||||
if(documents.length > 0){
|
||||
//console.log(documents);
|
||||
res.status(200).json({
|
||||
message: 'items found!',
|
||||
items: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'items not found!',
|
||||
items: []
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no address',
|
||||
items: []
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/item', (req, res, next) => {
|
||||
console.log('Post: /api/item', req.body.item);
|
||||
if ( req.body.item._id == null ) {
|
||||
const item = new itemmodel(req.body.item);
|
||||
item.save();
|
||||
res.status(201).json({
|
||||
message: 'Item added'
|
||||
});
|
||||
} else {
|
||||
console.log('Editing', req.body.item._id);
|
||||
itemmodel.findByIdAndUpdate(req.body.item._id, {'name': req.body.item.name, 'description': req.body.item.description, 'cost': req.body.item.cost},
|
||||
function(err, docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(201).json({
|
||||
message: 'Item updated'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/item/:id', (req, res, next) => {
|
||||
console.log('delete endpoint', req.params.id);
|
||||
itemmodel.findByIdAndDelete(req.params.id, function (err, docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(200).json({
|
||||
message: 'Item deleted'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.delete('/api/user/:id', (req, res, next) => {
|
||||
console.log("Delete user", req.params.id);
|
||||
usermodel.findByIdAndUpdate(req.params.id, {expired: true}, function(err, docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(200).json({
|
||||
message: 'User session deleted'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/price', (req, res, next) => {
|
||||
console.log('Get /api/price');
|
||||
const price = pricemodel.findOne({currency: req.query.currency}).then((document) => {
|
||||
if (document != null) {
|
||||
res.status(200).json({
|
||||
message: 'price found!',
|
||||
price: document
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no price found!',
|
||||
order: null
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/allorders', (req, res, next) => {
|
||||
console.log('Get /api/allorders');
|
||||
if (req.query.address.length > 0) {
|
||||
const orders = ordermodel.find({address: req.query.address, closed: true}).then((documents) => {
|
||||
if (documents != null) {
|
||||
res.status(200).json({
|
||||
message: 'orders found!',
|
||||
orders: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no orders found',
|
||||
orders: null
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/receipt', (req, res, next) => {
|
||||
console.log('Get /api/receipt');
|
||||
if (req.query.id.length > 0) {
|
||||
const order = ordermodel.findOne({_id: req.query.id}).then((documents) => {
|
||||
if (documents != null) {
|
||||
console.log(documents);
|
||||
res.status(200).json({
|
||||
message: 'order found!',
|
||||
order: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no order found!',
|
||||
order: null
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no valid ID received',
|
||||
order: null
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/order', (req, res, next) => {
|
||||
console.log('Get /api/order');
|
||||
if (req.query.session.length > 0) {
|
||||
const order = ordermodel.findOne({session: req.query.session, closed: false}).then((documents) => {
|
||||
if (documents != null) {
|
||||
console.log(documents);
|
||||
res.status(200).json({
|
||||
message: 'order found!',
|
||||
order: documents
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no order found!',
|
||||
order: null
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(204).json({
|
||||
message: 'no session received',
|
||||
order: null
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/order', (req, res, next) => {
|
||||
console.log('Post /api/order', req.body);
|
||||
if(req.body.order._id == null) {
|
||||
const order = new ordermodel(req.body.order);
|
||||
order.save();
|
||||
res.status(200).json({
|
||||
message: 'Order added',
|
||||
order: order
|
||||
});
|
||||
} else {
|
||||
ordermodel.findByIdAndUpdate(req.body.order._id, {
|
||||
address: req.body.order.address,
|
||||
session: req.body.order.session,
|
||||
price: req.body.order.price,
|
||||
total: req.body.order.total,
|
||||
currency: req.body.order.currency,
|
||||
totalZec: req.body.order.totalZec,
|
||||
closed: req.body.order.closed
|
||||
}, function(err, docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(200).json({
|
||||
message: 'Order updated'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/lineitem', (req, res, next) => {
|
||||
console.log('Post /api/lineitem');
|
||||
ordermodel.findByIdAndUpdate(req.body.order_id, { $push: {lines: req.body.line}}, function(err,docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(200).json({
|
||||
message: 'Item added to order'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.delete('/api/order/:id', (req, res, next) => {
|
||||
console.log('delete order endpoint', req.params.id);
|
||||
ordermodel.findByIdAndDelete(req.params.id, function (err, docs) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log(docs);
|
||||
res.status(200).json({
|
||||
message: 'Order deleted'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
|
@ -1,6 +0,0 @@
|
|||
module.exports = {
|
||||
server : 'localhost:27017',
|
||||
user: 'zgo',
|
||||
password: 'zcashrules',
|
||||
database: 'zgo'
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
module.exports = {
|
||||
url: 'http://localhost:8232',
|
||||
username: 'zecwallet',
|
||||
password: 'rdsxlun6v4a',
|
||||
addr: 'zs1xnpqd2tae9d95f8fhe4l0q7j44a5vf993m0pcnnvr56uqr4lgqlamesk5v4c5rhtvywc6lvlduy'
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const countrySchema = mongoose.Schema({
|
||||
name: {type: String, required: true},
|
||||
code: {type: Number, required: true}
|
||||
});
|
||||
|
||||
|
||||
module.exports = mongoose.model('Country', countrySchema);
|
|
@ -1,10 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const itemSchema = mongoose.Schema({
|
||||
name: {type: String, required: true},
|
||||
description: {type: String, required: true},
|
||||
user: {type: String, required: true},
|
||||
cost: {type: Number, required: true}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Item', itemSchema);
|
|
@ -1,19 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const orderSchema = mongoose.Schema({
|
||||
address: {type: String, required: true},
|
||||
session: {type: String, required: true},
|
||||
timestamp: {type: Date, required: true, default: Date.now},
|
||||
closed: { type: Boolean, required: true, default:false },
|
||||
price: { type: Number, required: true},
|
||||
currency: {type: String, required: true},
|
||||
total: { type: Number},
|
||||
totalZec: {type: Number},
|
||||
lines: [{
|
||||
qty: {type: Number, required: true, default: 1},
|
||||
name: { type: String, required: true},
|
||||
cost: { type: Number, required: true, default: 0}
|
||||
}]
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Order', orderSchema);
|
|
@ -1,25 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const ownerSchema = mongoose.Schema({
|
||||
address: {type: String, required:true, unique:true},
|
||||
name: {type: String, required:true},
|
||||
currency: {type: String, required:true, default: 'usd'},
|
||||
tax: {type: Boolean, required: true, default: false},
|
||||
taxValue: {type: Number },
|
||||
vat: {type: Boolean, required:true, default: false},
|
||||
vatValue: {type: Number },
|
||||
first: {type: String, required:true},
|
||||
last: {type: String, required:true},
|
||||
email: {type: String, required:true},
|
||||
street: {type: String, required:true},
|
||||
city: {type: String, required: true},
|
||||
state: {type: String, required: true},
|
||||
postal: {type: String, required: true},
|
||||
phone: {type: String},
|
||||
website: {type: String},
|
||||
country: {type: String},
|
||||
paid: {type: Boolean, required: true, default: false},
|
||||
zats: {type: Boolean, required: true, default: false}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Owner', ownerSchema);
|
|
@ -1,11 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const paymentSchema = mongoose.Schema({
|
||||
address: {type: String, required: true},
|
||||
blocktime: {type: Number, required: true},
|
||||
expiration: {type: Date, required: true},
|
||||
amount: {type: Number, required: true},
|
||||
session: {type: String, required: true}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Payment', paymentSchema);
|
|
@ -1,8 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const postSchema = mongoose.Schema({
|
||||
title: {type: String, required:true},
|
||||
content: {type: String, required:true}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Post', postSchema);
|
|
@ -1,10 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const priceSchema = mongoose.Schema({
|
||||
currency: {type: String, required: true},
|
||||
price: {type: Number, required: true},
|
||||
timestamp: {type: Date, required: true, default: Date.now}
|
||||
});
|
||||
|
||||
|
||||
module.exports = mongoose.model('Price', priceSchema);
|
|
@ -1,12 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const txSchema = mongoose.Schema({
|
||||
address: {type: String},
|
||||
session: {type: String, required:true},
|
||||
confirmations: {type: Number, required:true},
|
||||
amount: {type: Number, required:true},
|
||||
txid: {type:String, required:true, unique: true},
|
||||
memo: {type:String}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Tx', txSchema);
|
|
@ -1,11 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const userSchema = mongoose.Schema({
|
||||
address: {type: String, required:true},
|
||||
session: {type: String, required:true},
|
||||
blocktime: {type: Number, required:true},
|
||||
pin: {type: String, required:true},
|
||||
validated: {type: Boolean, required:true},
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('User', userSchema);
|
|
@ -1,12 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const ZecTxSchema = mongoose.Schema({
|
||||
address: {type: String},
|
||||
session: {type: String, required:true},
|
||||
confirmations: {type: Number, required:true},
|
||||
amount: {type: Number, required:true},
|
||||
txid: {type:String, required:true, unique: true},
|
||||
memo: {type:String}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('ZecTx', ZecTxSchema);
|
Loading…
Reference in a new issue