Browse Source

add actions file, remote keysend route for JS demo

push-params
Evan Feenstra 5 years ago
parent
commit
ed73f348ac
  1. 52
      api/controllers/actions.ts
  2. 3
      api/controllers/index.ts
  3. 68
      dist/api/controllers/actions.js
  4. 1
      dist/api/controllers/actions.js.map
  5. 2
      dist/api/controllers/index.js
  6. 2
      dist/api/controllers/index.js.map

52
api/controllers/actions.ts

@ -0,0 +1,52 @@
import { success, failure } from '../utils/res'
import * as path from 'path'
import * as fs from 'fs'
import * as network from '../network'
export async function doAction(req, res) {
const thePath = path.join(__dirname,'../../actions.json')
try {
if (fs.existsSync(thePath)) {
processExtra(req, res)
}
} catch(err) {
console.error(err)
}
}
async function processExtra(req, res) {
const actions = require(path.join(__dirname,'../../actions.json'))
if(!(actions&&actions.length)) {
return failure(res, 'no actions defined')
}
const {action,app,secret,pubkey,amount} = req.body
const theApp = actions.find(a=>a.app===app)
if(!theApp) {
return failure(res, 'app not found')
}
if(!(theApp.secret&&theApp.secret===secret)) {
return failure(res, 'wrong secret')
}
if(!(pubkey&&pubkey.length===66&&amount&&action)) {
return failure(res, 'wrong params')
}
if(action==='keysend') {
const MIN_SATS = 3
const destkey = pubkey
const opts = {
dest: destkey,
data: {},
amt: Math.max((amount||0), MIN_SATS)
}
try {
await network.signAndSend(opts)
return success(res, {success:true})
} catch(e) {
return failure(res, e)
}
} else {
return failure(res, 'no action')
}
}

3
api/controllers/index.ts

@ -11,6 +11,7 @@ import * as payments from './payment'
import * as subcriptions from './subscriptions'
import * as uploads from './uploads'
import * as confirmations from './confirmations'
import * as actions from './actions'
import {checkTag} from '../utils/gitinfo'
import * as path from 'path'
import * as timers from '../utils/timers'
@ -92,6 +93,8 @@ export async function set(app) {
app.get('/logs', details.getLogsSince)
app.get('/info', details.getNodeInfo)
app.post('/action', actions.doAction)
app.get('/version', async function(req,res) {
const version = await checkTag()
res.send({version})

68
dist/api/controllers/actions.js

@ -0,0 +1,68 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const res_1 = require("../utils/res");
const path = require("path");
const fs = require("fs");
const network = require("../network");
function doAction(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const thePath = path.join(__dirname, '../../actions.json');
try {
if (fs.existsSync(thePath)) {
processExtra(req, res);
}
}
catch (err) {
console.error(err);
}
});
}
exports.doAction = doAction;
function processExtra(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const actions = require(path.join(__dirname, '../../actions.json'));
if (!(actions && actions.length)) {
return res_1.failure(res, 'no actions defined');
}
const { action, app, secret, pubkey, amount } = req.body;
const theApp = actions.find(a => a.app === app);
if (!theApp) {
return res_1.failure(res, 'app not found');
}
if (!(theApp.secret && theApp.secret === secret)) {
return res_1.failure(res, 'wrong secret');
}
if (!(pubkey && pubkey.length === 66 && amount && action)) {
return res_1.failure(res, 'wrong params');
}
if (action === 'keysend') {
const MIN_SATS = 3;
const destkey = pubkey;
const opts = {
dest: destkey,
data: {},
amt: Math.max((amount || 0), MIN_SATS)
};
try {
yield network.signAndSend(opts);
return res_1.success(res, { success: true });
}
catch (e) {
return res_1.failure(res, e);
}
}
else {
return res_1.failure(res, 'no action');
}
});
}
//# sourceMappingURL=actions.js.map

1
dist/api/controllers/actions.js.map

@ -0,0 +1 @@
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../api/controllers/actions.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAA+C;AAC/C,6BAA4B;AAC5B,yBAAwB;AACxB,sCAAqC;AAErC,SAAsB,QAAQ,CAAC,GAAG,EAAE,G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AG,SAAS,EAAE;YACnB,MAAM,QAAQ,GAAG,CAAC,CAAA;YAClB,MAAM,OAAO,GAAG,MAAM,CAAA;YACtB,MAAM,IAAI,GAAG;gBACT,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,EAAE;gBACR,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,IAAE,CAAC,CAAC,EAAE,QAAQ,CAAC;aACvC,CAAA;YACD,IAAI;gBACA,MAAM,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;gBAC/B,OAAO,aAAO,CAAC,GAAG,EAAE,EAAC,OAAO,EAAC,IAAI,EAAC,CAAC,CAAA;aACtC;YAAC,OAAM,CAAC,EAAE;gBACP,OAAO,aAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;aACzB;SACJ;aAAM;YACH,OAAO,aAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;SACnC;IACL,CAAC;CAAA"}

2
dist/api/controllers/index.js

@ -22,6 +22,7 @@ const payments = require("./payment");
const subcriptions = require("./subscriptions");
const uploads = require("./uploads");
const confirmations = require("./confirmations");
const actions = require("./actions");
const gitinfo_1 = require("../utils/gitinfo");
const path = require("path");
const timers = require("../utils/timers");
@ -89,6 +90,7 @@ function set(app) {
app.get('/getinfo', details.getInfo);
app.get('/logs', details.getLogsSince);
app.get('/info', details.getNodeInfo);
app.post('/action', actions.doAction);
app.get('/version', function (req, res) {
return __awaiter(this, void 0, void 0, function* () {
const version = yield gitinfo_1.checkTag();

2
dist/api/controllers/index.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save