From 1cb51a1a796690adfb7b75eb9bd2ca2adbc97677 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Sun, 4 Mar 2018 18:47:26 -0500 Subject: [PATCH] feat: /sealpending command for employees --- src/in-house-bot/commands/index.ts | 4 +++- src/in-house-bot/commands/sealpending.ts | 25 ++++++++++++++++++++++++ src/seals.ts | 6 +++--- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/in-house-bot/commands/sealpending.ts diff --git a/src/in-house-bot/commands/index.ts b/src/in-house-bot/commands/index.ts index 8f2beda44..0fe8fcf3d 100644 --- a/src/in-house-bot/commands/index.ts +++ b/src/in-house-bot/commands/index.ts @@ -17,6 +17,7 @@ import { command as updatemycloud } from './updatemycloud' import { command as model } from './model' import { command as push } from './push' import { command as links } from './links' +import { command as sealpending } from './sealpending' export { help, @@ -37,5 +38,6 @@ export { // sudo only // encryptbucket, // enablebinary, - push + push, + sealpending } diff --git a/src/in-house-bot/commands/sealpending.ts b/src/in-house-bot/commands/sealpending.ts new file mode 100644 index 000000000..97b293879 --- /dev/null +++ b/src/in-house-bot/commands/sealpending.ts @@ -0,0 +1,25 @@ +import { ICommand } from '../types' + +export const command:ICommand = { + name: 'sealpending', + description: 'write pending seals', + examples: [ + '/sealpending' + ], + exec: async ({ commander, req, ctx, args }) => { + try { + return await commander.bot.seals.sealPending() + } catch (err) { + commander.logger.error('failed to write pending seals', err) + return [] + } + }, + sendResult: async ({ commander, req, to, result }) => { + // TODO: link to application + await commander.sendSimpleMessage({ + req, + to, + message: `sealed ${result.length} pending seals` + }) + } +} diff --git a/src/seals.ts b/src/seals.ts index 8b7d87fec..78ac84ca9 100644 --- a/src/seals.ts +++ b/src/seals.ts @@ -131,7 +131,7 @@ interface IErrorRecord { export default class Seals { public syncUnconfirmed: (opts?: ILimitOpts) => Promise - public sealPending: (opts?:any) => Promise + public sealPending: (opts?:any) => Promise public table: any public blockchain: Blockchain private provider: Provider @@ -236,7 +236,7 @@ export default class Seals { return this.table.update(params) } - private _sealPending = async (opts: { limit?: number, key?: any } = {}) => { + private _sealPending = async (opts: { limit?: number, key?: any } = {}):Promise => { typeforce({ limit: typeforce.maybe(typeforce.Number), key: typeforce.maybe(types.privateKey) @@ -254,7 +254,7 @@ export default class Seals { const pending = await this.getUnsealed({ limit }) this.logger.info(`found ${pending.length} pending seals`) - if (!pending.length) return + if (!pending.length) return [] let aborted // TODO: update balance after every tx