aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md253
-rw-r--r--db/schema.sql88
-rw-r--r--routes/invoices.js2
-rw-r--r--routes/send.js1
-rw-r--r--routes/users.js8
5 files changed, 72 insertions, 280 deletions
diff --git a/README.md b/README.md
index 86920b91..1c94f46b 100644
--- a/README.md
+++ b/README.md
@@ -2,259 +2,48 @@
Coinos is a bitcoin wallet app that supports payments over the <a href="https://bitcoin.org">bitcoin</a>, <a href="https://blockstream.com/liquid/">liquid</a> and <a href="http://lightning.network/">lightning</a> networks. Try it out at <a href="https://coinos.io/">coinos.io</a>.
-This repository contains the code for the backend API server which is implemented as a NodeJS application. The code for the frontend UI is tracked separately <a href="https://github.com/asoltys/coinos.io">here</a> (but is automatically installed & started via the Docker way outlined below).
+This repository contains the code for the backend API server which is implemented as a NodeJS application. The code for the frontend UI is tracked separately <a href="https://github.com/asoltys/coinos.io">here</a>.
-## Install/Run (the Docker way)
+## Install
-### Requirements
-
-* <a href="https://docs.docker.com/get-docker/
-">docker</a> and <a href="https://docs.docker.com/compose/install/">docker-compose</a>
-* NodeJS (recommended version: 16)
-* ~7GB of hard drive space (which will go into /var/lib/docker; primarily for Liquid)
-
-### Getting Started
+The follow commands will set up bitcoin, liquid and lightning nodes in regtest mode, along with a coinos app server, database, and front end UI. You'll need to have <a href="https://docs.docker.com/get-docker/">docker</a> installed as a pre-requisite.
```bash
git clone https://github.com/coinos/coinos-server
cd coinos-server
cp -rf sampleconfig ./config
+sudo chown 1000:1000 config/liquid
+sudo chown 1000:1000 config/bitcoin
cp .env.sample .env
cp fx.sample fx
docker network create net --gateway 172.18.0.1 --subnet 172.18.0.0/16
-docker run -it -v $(pwd):/app --entrypoint yarn asoltys/coinos-server
+docker run -it -v $(pwd):/app --entrypoint pnpm asoltys/coinos-server i
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
docker exec -i mariadb mysql -u root -ppassword < db/schema.sql
-docker exec -it liquid elements-cli -conf=/home/elements/.elements/elements.conf sendtoaddress AzpsKhC6xE9FEK4aWAzMnbvueMLiSa5ym1xpuYogFkHzWgMHSt8B79aNNbFppQzCSQ2yZ9E4nL6RQJU7 1000000
-```
-
-then run this and keep reference to the result for the forthcoming [Config changes]
-
-```bash
-sudo base64 config/lnd/tls.cert | tr -d '\n'
-```
-then run this and type a password when prompted, and then 'n' to create new wallet:
-
-```bash
-docker exec -it lnd lncli create
-```
-(optionally write down the seed as backup in case you lose the wallet and/or password)
-
-then uncomment line 12 of [config/lnd/lnd.conf] and update the [pwd file] with the new wallet password you just set.
-
-then run this and keep reference to the result again:
-```bash
-sudo base64 config/lnd/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n'
-```
-
-then run:
-```bash
-docker-compose down --remove-orphans
-```
-and start it back up again with the same command from before:
-```bash
-docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
-```
-
-and finally, create a Bitcoin wallet:
-
-```
-docker exec -it bitcoin bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 createwallet coinos
-```
-
-then [generate some BTC] to fund the server.
-
-For reviewing output, you may run `docker-compose logs` or run the docker-compose up command above but without the `-d `flag
-
-### Setup pre-commit git hooks
-
- We have a pre-commit git hook for running prettier on all files to keep the formatting consistent.
-
- `git config core.hooksPath "./git_hooks"` - This will set the git config path to use this directory for hooks.
-
- `chmod +x ./git_hooks/pre-commit` - This will give the hook the necessary permissions to run.
-
-### Config changes
-
-Navigate to `./config/index.js`
-Under `lna`, update the values for `cert` and `macaroon` with the output from the respective commands you ran in the section above.
-
-### Wallet not found issues
-If your app logs complain that the wallet was not found, do the following:
-```bash
-docker-compose exec bitcoin bash
-bitcoin-cli createwallet coinos
-exit
-docker exec -it lnd lncli --network=regtest --chain=bitcoin unlock
+docker exec -it bitcoin bitcoin-cli createwallet coinos
+docker exec -it bitcoin bitcoin-cli generatetoaddress 1 bcrt1qwhrhu9feqkvmgdph0a4p248zzmy4grjr38a8uq
+docker exec -it liquid elements-cli createwallet coinos
+docker exec -it liquid elements-cli rescanblockchain
+docker exec -it liquid elements-cli sendtoaddress AzpsKhC6xE9FEK4aWAzMnbvueMLiSa5ym1xpuYogFkHzWgMHSt8B79aNNbFppQzCSQ2yZ9E4nL6RQJU7 1000000
+docker exec -it liquid elements-cli generatetoaddress 1 AzpsKhC6xE9FEK4aWAzMnbvueMLiSa5ym1xpuYogFkHzWgMHSt8B79aNNbFppQzCSQ2yZ9E4nL6RQJU7
+docker exec -it lnd lncli create # set password to "password"
+sed -i "s/# wallet/wallet/g" config/lnd/lnd.conf
+CERT=$(sudo base64 config/lnd/tls.cert | tr -d '\n')
+sed -i "s/LS0tL.*\"/$CERT\"/g" config/index.js
+MACAROON=$(sudo base64 config/lnd/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n')
+sed -i "s/AgED.*\"/$MACAROON\"/g" config/index.js
```
-### Spinning down coinos & services
-
-from the root of this repo, run:
-
-```bash
-docker-compose down --remove-orphans
-```
-
----
-
-
-Note the initial `docker-compose up` step will take some time on first run as it will download all of the necessary images.
-
-After successful creation of all docker containers coinos will be available at http://localhost:8085
-
-To shutdown coinos and all of its containers/services, run `docker-compose down --remove-orphans` again.
-
-At anypoint to purge the database and start with a new one run `rm -rf mysql` and then `mkdir mysql` and then the same steps following from that point as outlined above. Or run `purge-except-git.sh` from `./scripts`
-
-To review a log of individual containers use `docker-compose app` or `docker-compose maria` etc; container names are available in `docker-compose.yml` or via `docker-compose ps` when they are running. `docker images` will show you a list of the images installed on your system and `docker image rm [IMAGE ID]` removes them.
-
-#### Volumes and local filesystem changes
-
-The `docker-compose.yml` specifies volumes that map to the host (ie- your local machine). As per Docker's <a href="https://docs.docker.com/storage/volumes/">volume feature</a> these override what is in the container's 'virtual' filesystem for those folders and instead will map to what is on your local filesystem. As such, changes/developments that occur in these locations will be reflected without needing to restart the containers.
-
-Additionally <a href="https://github.com/remy/nodemon">Nodemon</a> is setup by default to watch coinos-server directory and will auto-restart the app as changes occur.
-
-Alternative to allowing nodemon to manage the app, you may enter bash on the docker to start/stop the node app manually ie:
-
- docker exec -it app bash
- node index.js
- # ^ starts app manually in a bash session inside the docker
- # ( reflecting your local coinos-server directory)
-
-
-To prevent nodemon from starting with the container change the `package.json` `"start"` script value to: `"tail -f /dev/null"` which will then keep the container alive so you may enter an interactive bash as above to start the app manually.
-
-#### Debugging
-
-To debug the node app while it is running via Docker, edit `docker-compose.yml` to add `9229` to the ports section for the `app` service:
-
- ports:
- - '3119:3119'
- - '9229'
-then get the IP of the app container:
+After successful creation of all docker containers coinos ui will be available at http://localhost:8085 and coinos server will be available at http://localhost:3119
- docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' app
- > 192.168.115.72 #outputs the coinos app container IP
-
-then edit `package.json` start script to:
-
- "start" : "nodemon --inspect=0.0.0.0 index.js",
-
-(or use the interactive bash technique above with this same inspect flag)
-
-restart with `docker-compose restart app`
-
-then open your browser (Chrome in this example) to the URL`chrome://inspect` then click "Configure" and add the IP address + debugger port to the list of targets ex- `192.168.115.72:92229`
-
-an inspect link will then display under 'Remote Target'!
-
- Note the IP address may change between restarts so you may have to rerun the docker inspect command above again to make sure you have the correct IP on following sessions.
-
-----
-
-### Install/Run (standalone)
-
-Note the Docker way outlined above is recommended as manual setup requirements/instructions shown below are out of date.
-
-
-#### Requirements
-
-* <a href="https://github.com/bitcoin/bitcoin">bitcoind</a> with zmq support
-* <a href="https://github.com/ElementsProject/elements">elementsd</a> with zmq support
-* <a href="https://github.com/lightningnetwork/lnd">lnd</a> or <a href="https://github.com/elementsproject/lightning">c-lightning</a>
-* a database that <a href="https://github.com/sequelize/sequelize">sequelize</a> can talk to
-
-The bitcoind and elementsd nodes can be a pruned if you want to limit the amount of disk space used.
-
-#### Getting Started
-
- git clone [email protected]:coinos/coinos-server.git
- cd coinos-server
- cp -rf sampleconfig ./config # edit config files as necessary for your local setup
- cp .env.sample .env
- yarn
- yarn start
- # or, alternatively
- yarn min # to run a stripped down development version that doesn't do payments or talk to any nodes
-
-#### Database Setup
-
-I've only tested with <a href="https://mariadb.org/">Maria</a>. Here's a [schema](https://github.com/asoltys/coinos-server/blob/master/db/schema.sql) to get you started.
-
- cat db/schema.sql | mysql -u root -p
-
----
-### Miscellaneous Commands
-
-#### Funding the regtest chain
-
-##### Bitcoin
-
-generate some blocks
-
- docker exec -it bitcoin bitcoin-cli generatetoaddress 1 $(docker exec -it bitcoin bitcoin-cli getnewaddress "" "legacy")
-
-get balance
-
- docker exec -it bitcoin bitcoin-cli getbalance
-
----
-##### Liquid
-
-The Liquid network gives you a starting balance of Bitcoin specified in the `config/liquid/elements.conf` file as `initialfreecoins`.
-
-generate some blocks
-
- docker exec -it liquid elements-cli generatetoaddress 1 $(docker exec -it liquid elements-cli getnewaddress)
-
-get balance
-
- docker exec -it liquid elements-cli getbalance
-
----
-##### Lightning
-
-get node id of clighting node
+### Setup Lightning Channels
docker exec -it cl lightning-cli getinfo
-
-connect to clightning node
-
docker exec -it lnd lncli --network=regtest --chain=bitcoin connect 029ba19ec5f65f82b1952fd535a86ff136ccc67ff7f91e19c3fcbc83a5224adaee@cl:9735
-
-open a channel
-
docker exec -it lnd lncli --network=regtest --chain=bitcoin openchannel 029ba19ec5f65f82b1952fd535a86ff136ccc67ff7f91e19c3fcbc83a5224adaee 10000000
-
-generate 10 btc blocks
-
docker exec -it bitcoin bitcoin-cli generatetoaddress 10 $(docker exec -it bitcoin bitcoin-cli getnewaddress "" "legacy")
----
-#### Test clightning payment
-
-payment request from clightning
-
- docker exec -it cl lightning-cli invoice 100000 "test payment" "test desc"
-
-get full payment request code from field bolt11
-
- something like this
-
- lnbcrt1u1p3qhle9pp5mzn7aezr59tmlmp5mg9x2sa45j8fec5ygmwx6mg2x29qpnnw3j9qdq0w3jhxapqv3jhxccxqyjw5qcqp2sp54tuk3ns3gd66w50hflkzwks0d9z9eelsa8284283zhkug9kevzqq9qyyssqjsprhd38eywg6kp8w7gmwf48hnx0mpd28465v9f595xfrec0dg2jnqdumrmeh9srw32u5t9g6tdy6tdpu47emhkfnu72fnzevvwd0acqxmurkx
-
-Use this botl11 address and paste in the UI to check
-
----
-#### Check if all three nodes are connected
-
- curl http://localhost:8085/api/info
-
-(look for nodes array at the end)
-
-
-### license
+### License
This code is [licensed]. Coinos is free for personal use. Anyone can fork as long as it stays AGPLv3.
diff --git a/db/schema.sql b/db/schema.sql
index 854bd2a8..9ea20660 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -1,13 +1,13 @@
--- MySQL dump 10.14 Distrib 5.5.68-MariaDB, for Linux (x86_64)
+-- MariaDB dump 10.19 Distrib 10.6.1-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: coinos
-- ------------------------------------------------------
--- Server version 5.5.68-MariaDB
+-- Server version 10.6.1-MariaDB-1:10.6.1+maria~focal
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
-/*!40101 SET NAMES utf8 */;
+/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
@@ -19,7 +19,6 @@
-- Current Database: `coinos`
--
-DROP DATABASE IF EXISTS `coinos`;
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `coinos` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `coinos`;
@@ -32,11 +31,11 @@ DROP TABLE IF EXISTS `SequelizeMeta`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `SequelizeMeta` (
- `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `name` varchar(255) COLLATE utf8mb3_unicode_ci NOT NULL,
PRIMARY KEY (`name`),
UNIQUE KEY `name` (`name`),
UNIQUE KEY `SequelizeMeta_name_unique` (`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -58,17 +57,20 @@ CREATE TABLE `accounts` (
`ticker` varchar(255) DEFAULT NULL,
`precision` int(11) DEFAULT NULL,
`domain` varchar(255) DEFAULT NULL,
- `contract` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
- `index` int(11) NOT NULL DEFAULT '0',
+ `contract` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
+ `index` int(11) NOT NULL DEFAULT 0,
`pubkey` varchar(255) DEFAULT NULL,
`hide` tinyint(1) DEFAULT NULL,
`seed` varchar(255) DEFAULT NULL,
`path` varchar(255) DEFAULT NULL,
`network` varchar(255) DEFAULT NULL,
`privkey` varchar(255) DEFAULT NULL,
+ `btc_credits` double NOT NULL DEFAULT 0,
+ `liquid_credits` double NOT NULL DEFAULT 0,
+ `lightning_credits` double NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `asset` (`asset`)
-) ENGINE=InnoDB AUTO_INCREMENT=21553 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=21593 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -80,7 +82,7 @@ DROP TABLE IF EXISTS `codes`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `codes` (
`code` varchar(255) NOT NULL DEFAULT '',
- `text` text,
+ `text` text DEFAULT NULL,
PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -116,7 +118,7 @@ DROP TABLE IF EXISTS `invoices`;
CREATE TABLE `invoices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
- `text` text,
+ `text` text DEFAULT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
`rate` double DEFAULT NULL,
@@ -127,11 +129,12 @@ CREATE TABLE `invoices` (
`tip` double DEFAULT NULL,
`network` varchar(255) DEFAULT NULL,
`unconfidential` varchar(255) DEFAULT NULL,
- `uuid` varchar(255) DEFAULT NULL,
- `memo` text,
+ `uuid` varchar(255) DEFAULT uuid(),
+ `memo` text DEFAULT NULL,
`account_id` int(11) DEFAULT NULL,
`path` varchar(255) DEFAULT NULL,
- `webhook` text,
+ `webhook` text DEFAULT NULL,
+ `status` varchar(255) DEFAULT 'unpaid',
PRIMARY KEY (`id`),
KEY `part_of_unconfidential` (`unconfidential`(10)),
KEY `text_index` (`text`(100)),
@@ -141,7 +144,7 @@ CREATE TABLE `invoices` (
KEY `invoices_account_id_foreign` (`account_id`),
CONSTRAINT `invoices_account_id_foreign` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`),
CONSTRAINT `invoices_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=46708 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=46953 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -158,7 +161,7 @@ CREATE TABLE `linkingkeys` (
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=12617 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=12623 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -172,9 +175,9 @@ CREATE TABLE `migrations` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`batch` int(11) DEFAULT NULL,
- `migration_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `migration_time` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
+) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -205,7 +208,7 @@ CREATE TABLE `orders` (
`user_id` int(11) DEFAULT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
- `accepted` tinyint(1) NOT NULL DEFAULT '0',
+ `accepted` tinyint(1) NOT NULL DEFAULT 0,
`a1_id` int(11) DEFAULT NULL,
`a2_id` int(11) DEFAULT NULL,
`completedAt` datetime DEFAULT NULL,
@@ -230,7 +233,7 @@ DROP TABLE IF EXISTS `payments`;
CREATE TABLE `payments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
- `hash` text,
+ `hash` text DEFAULT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
`rate` double DEFAULT NULL,
@@ -238,26 +241,29 @@ CREATE TABLE `payments` (
`address` varchar(255) DEFAULT NULL,
`received` tinyint(1) DEFAULT NULL,
`amount` double DEFAULT NULL,
- `tip` double NOT NULL DEFAULT '0',
+ `tip` double NOT NULL DEFAULT 0,
`confirmed` tinyint(1) NOT NULL,
- `fee` double NOT NULL DEFAULT '0',
+ `fee` double NOT NULL DEFAULT 0,
`network` varchar(255) DEFAULT NULL,
`account_id` int(11) DEFAULT NULL,
`preimage` varchar(255) DEFAULT NULL,
- `memo` text,
- `redeemed` tinyint(1) NOT NULL DEFAULT '0',
+ `memo` text DEFAULT NULL,
+ `redeemed` tinyint(1) NOT NULL DEFAULT 0,
`redeemcode` varchar(255) DEFAULT NULL,
`path` varchar(255) DEFAULT NULL,
`invoice_id` int(11) DEFAULT NULL,
+ `fee_payment_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_redeemcode` (`redeemcode`),
KEY `payments_invoice_id_foreign` (`invoice_id`),
KEY `payments_user_id_foreign` (`user_id`),
KEY `payments_account_id_foreign` (`account_id`),
+ KEY `fk_payments` (`fee_payment_id`),
+ CONSTRAINT `fk_payments` FOREIGN KEY (`fee_payment_id`) REFERENCES `payments` (`id`),
CONSTRAINT `payments_account_id_foreign` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`),
CONSTRAINT `payments_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`),
CONSTRAINT `payments_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=29225 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=29354 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -268,8 +274,8 @@ DROP TABLE IF EXISTS `prs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `prs` (
- `text` text,
- `preimage` text
+ `text` text DEFAULT NULL,
+ `preimage` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -314,16 +320,16 @@ CREATE TABLE `users` (
`updatedAt` datetime NOT NULL,
`twofa` tinyint(1) DEFAULT NULL,
`pin` varchar(255) DEFAULT NULL,
- `currencies` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
+ `currencies` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
`otpsecret` varchar(255) DEFAULT NULL,
`account_id` int(11) DEFAULT NULL,
`ip` int(10) unsigned DEFAULT NULL,
- `subscriptions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
+ `subscriptions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
`seed` varchar(255) DEFAULT NULL,
- `fiat` tinyint(1) NOT NULL DEFAULT '0',
- `index` int(11) NOT NULL DEFAULT '0',
+ `fiat` tinyint(1) NOT NULL DEFAULT 0,
+ `index` int(11) NOT NULL DEFAULT 0,
`verified` varchar(255) DEFAULT NULL,
- `locked` tinyint(1) DEFAULT '0',
+ `locked` tinyint(1) DEFAULT 0,
`authyId` varchar(255) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
@@ -331,7 +337,7 @@ CREATE TABLE `users` (
PRIMARY KEY (`id`),
KEY `ip` (`ip`),
KEY `username` (`username`)
-) ENGINE=InnoDB AUTO_INCREMENT=15377 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=15411 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -347,7 +353,7 @@ CREATE TABLE `waiting_list` (
`phone` varchar(255) NOT NULL,
`status` enum('pending','activated','expired','cancelled') NOT NULL,
`user_id` int(11) DEFAULT NULL,
- `notes` text,
+ `notes` text DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
@@ -373,7 +379,7 @@ CREATE TABLE `withdrawals` (
`transit` varchar(255) DEFAULT NULL,
`account` varchar(255) DEFAULT NULL,
`institution` varchar(255) DEFAULT NULL,
- `notes` text,
+ `notes` text DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `withdrawals_user_id_foreign` (`user_id`),
@@ -390,14 +396,4 @@ CREATE TABLE `withdrawals` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2021-08-12 16:26:08
-
-INSERT INTO migrations (name, batch) VALUES ('20210612181508_init_referrals.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210612192804_init_waiting_list.js.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210612203333_schema_diff_merges.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210625232223_add_invoice_id_to_payments.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210628221727_add_webhook_to_invoices.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210713174217_add_admin_to_users.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210714123455_data_fixes_merge.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210714123456_add_fks_merge.js', 1);
-INSERT INTO migrations (name, batch) VALUES ('20210814193811_fix_db_conflicts.js', 1);
+-- Dump completed on 2022-08-05 5:15:19
diff --git a/routes/invoices.js b/routes/invoices.js
index b5650735..02a8308d 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -12,7 +12,7 @@ app.get(
include: {
model: db.User,
as: "user",
- attributes: ['username']
+ attributes: ['username', 'currency']
}
});
diff --git a/routes/send.js b/routes/send.js
index 4c8afa34..653da87b 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -66,7 +66,6 @@ module.exports = ah(async (req, res, next) => {
};
if (!username) {
- throw new Error("Vouchers temporarily disabled");
l.info("creating redeemable payment");
params.redeemcode = uuidv4();
params.hash = `${req.get("origin")}/redeem/${params.redeemcode}`;
diff --git a/routes/users.js b/routes/users.js
index 4fe1362b..c9367c9a 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -634,12 +634,16 @@ app.post(
})
);
+let redeeming = {};
app.post(
"/redeem",
optionalAuth,
ah(async function(req, res) {
+ try {
await db.transaction(async transaction => {
const { redeemcode } = req.body;
+ if (redeeming[redeemcode]) fail("redemption in progress");
+ redeeming[redeemcode] = true;
if (!redeemcode) fail("no code provided");
let { user } = req;
@@ -652,6 +656,7 @@ app.post(
model: db.Account,
as: "account"
},
+ lock: transaction.LOCK.UPDATE,
transaction
});
@@ -717,6 +722,9 @@ app.post(
res.send({ payment });
});
+ } catch(e) {
+ l.error("problem redeeming", e.message);
+ return res.status(500).send("There was a problem redeeming the voucher");
})
);