Skip to content

Commit

Permalink
feat: /sealpending command for employees
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Mar 5, 2018
1 parent cf833ad commit 1cb51a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/in-house-bot/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,5 +38,6 @@ export {
// sudo only
// encryptbucket,
// enablebinary,
push
push,
sealpending
}
25 changes: 25 additions & 0 deletions src/in-house-bot/commands/sealpending.ts
Original file line number Diff line number Diff line change
@@ -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`
})
}
}
6 changes: 3 additions & 3 deletions src/seals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ interface IErrorRecord {

export default class Seals {
public syncUnconfirmed: (opts?: ILimitOpts) => Promise<Seal[]>
public sealPending: (opts?:any) => Promise<any>
public sealPending: (opts?:any) => Promise<Seal[]>
public table: any
public blockchain: Blockchain
private provider: Provider
Expand Down Expand Up @@ -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<Seal[]> => {
typeforce({
limit: typeforce.maybe(typeforce.Number),
key: typeforce.maybe(types.privateKey)
Expand All @@ -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
Expand Down

0 comments on commit 1cb51a1

Please sign in to comment.