const _ = require('lodash')
const colors = require('colors');
const { ChainRpcProvider } = require('@asimovdev/asimovjs')
const storage = require('./storage')
let rpcConfig = storage.getRpcConfig()
let rpc = new ChainRpcProvider({
  baseURL: rpcConfig.url || 'http://127.0.0.1:8545/'
});


function request(method, args) {
  console.log(args)

  if (method.indexOf('asimov_') == -1) {

    method = 'asimov_' + _.lowerFirst(method)
  }

  return rpc.request(method, args).then(res => {
    return res
  }).catch(err => {
    console.log(colors.red(err.toString()));
  })
}

module.exports = {
  request: request,
  rpc: rpc
}
