Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Queue = require('better-queue');
  2. var BtcClient = require('bitcoin-core')
  3.  
  4. class Test {
  5. constructor() {
  6.    this.methods = ['getSomething', 'getBalance', 'batch', 'getAddress', 'getBlock', 'getBlockCount', 'getBestBlockHash', 'getBestBlock', 'getBlockCount', 'getAddresses']
  7.    this.queue = new Queue(this.execute.bind(this), { maxRetries: 10, retryDelay: 1000 })
  8.    //this.tmp = {}
  9.    //this.tmp['btc'] = { 'test': function(){console.log("works") }}
  10.   }
  11.  
  12.   async getSomething (a, b) {
  13. //      this.tmp['btc']['test']()
  14.         console.log("yay ", a, b)
  15.   }
  16.  
  17.   async execute (input) {
  18.     try {
  19.     return await this[input.cmd](...input.args)
  20.     } catch (e) {
  21.         // can't throw errors in here
  22.       console.log(e)
  23.  
  24.    }
  25.   }
  26.  
  27.   handle(msg) {
  28.    if (this.methods.indexOf(msg.cmd) > -1) {
  29.         let id = this.queue.push(msg)
  30.         return id;
  31.   } else {
  32.   }
  33.  }
  34.  
  35. }
  36.  
  37.  
  38. let d = new Test()
  39.  
  40. try {
  41. a = d.handle({id:'idhere', cmd: "getSomething", coin: 'CLAM', args: ['a', 'b']} )
  42. if(a.status == 'created') {
  43.         console.log('jesus chist, superstar', a.status)
  44. }
  45. } catch (e) {
  46.         console.log("a error ", e)
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement