Evan Feenstra
5 years ago
6 changed files with 127 additions and 1 deletions
@ -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') |
|||
} |
|||
} |
@ -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
|
@ -0,0 +1 @@ |
|||
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../api/controllers/actions.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sC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