diff options
| author | Adam Soltys <[email protected]> | 2018-02-07 22:39:37 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2018-02-07 22:39:37 -0800 |
| commit | ebd061cf34aff30033511f9f1ec10ac21d1dcd94 (patch) | |
| tree | c2540e93df53707cad4a8874b836b367b9407e44 | |
| parent | cf5a62c26205fa2e9e36d788d4bfb7ec9f96cc66 (diff) | |
| download | coinos-server-ebd061cf34aff30033511f9f1ec10ac21d1dcd94.tar.gz coinos-server-ebd061cf34aff30033511f9f1ec10ac21d1dcd94.zip | |
sendPayment endpoint
| -rw-r--r-- | db.js | 7 | ||||
| -rw-r--r-- | ecosystem.config.js | 2 | ||||
| -rw-r--r-- | index.js | 14 | ||||
| -rw-r--r-- | migrations/20180206033508-create-transaction.js | 39 | ||||
| -rw-r--r-- | models/transaction.js | 17 |
5 files changed, 76 insertions, 3 deletions
@@ -22,7 +22,11 @@ const auto = new SequelizeAuto( config.development.password, config.auto ) -const tables = { 'User': 'users' } + +const tables = { + User: 'users', + Transaction: 'transactions', +} const db = new Sequelize( config.development.database, @@ -36,6 +40,7 @@ const db = new Sequelize( operatorsAliases: false, }, ) + const gqlfields = {} const gqltypes = {} diff --git a/ecosystem.config.js b/ecosystem.config.js index a44c0de5..1093c494 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -5,7 +5,7 @@ module.exports = { script: 'index.js', exec_interpreter: './node_modules/.bin/babel-node', exec_mode: 'fork', - watch: ['*.js'], + watch: ['index.js'], env: { COMMON_VARIABLE: 'true' }, @@ -30,7 +30,7 @@ const l = console.log const restClient = ba.restfulClient(process.env.BITCOINAVERAGE_PUBLIC, process.env.BITCOINAVERAGE_SECRET) const lnrpc = await require('lnrpc')({ server: 'localhost:10001' }) - const adminMacaroon = fs.readFileSync('/home/adam/.lnd/data/core_test/admin.macaroon'); + const adminMacaroon = fs.readFileSync('/home/adam/.lnd.testa/admin.macaroon'); const meta = new grpc.Metadata(); meta.add('macaroon', adminMacaroon.toString('hex')); @@ -38,6 +38,18 @@ const l = console.log res.json(await lnrpc.walletBalance({witness_only: true}, meta)) }) + app.post('/sendPayment', async (req, res) => { + let payments = lnrpc.sendPayment(meta, {}) + payments.on('data', msg => l(msg)) + payments.write({ + payment_request: req.body.payreq + }) + }) + + app.get('/addinvoice', async (req, res) => { + res.json(await lnrpc.walletBalance({witness_only: true}, meta)) + }) + let fetchRates (fetchRates = () => { restClient.tickerGlobalPerSymbol('BTCCAD', (data) => { diff --git a/migrations/20180206033508-create-transaction.js b/migrations/20180206033508-create-transaction.js new file mode 100644 index 00000000..06863a43 --- /dev/null +++ b/migrations/20180206033508-create-transaction.js @@ -0,0 +1,39 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('transactions', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + hash: { + type: Sequelize.STRING + }, + address: { + type: Sequelize.STRING + }, + date: { + type: Sequelize.DATE + }, + amount: { + type: Sequelize.FLOAT + }, + rate: { + type: Sequelize.FLOAT + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('transactions'); + } +}; diff --git a/models/transaction.js b/models/transaction.js new file mode 100644 index 00000000..f4b696a7 --- /dev/null +++ b/models/transaction.js @@ -0,0 +1,17 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + var Transaction = sequelize.define('Transaction', { + hash: DataTypes.STRING, + address: DataTypes.STRING, + date: DataTypes.DATE, + amount: DataTypes.FLOAT, + rate: DataTypes.FLOAT + }, { + classMethods: { + associate: function(models) { + // associations can be defined here + } + } + }); + return Transaction; +};
\ No newline at end of file |
