All files / src index.js

100% Statements 12/12
100% Branches 2/2
100% Functions 3/3
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                      12x 12x 12x     7x   7x                         7x             12x       12x           12x                 1x       1x 1x        
/**
 * @file AElf-sdk index export
 * @author atom-yang
 */
import * as protobuf from '@aelfqueen/protobufjs/light';
import * as bloom from './util/bloom';
import Chain from './chain';
import RequestManager from './util/requestManage';
import HttpProvider from './util/httpProvider';
import wallet from './wallet';
import * as utils from './util/utils';
import * as proto from './util/proto';
import * as transform from './util/transform';
import Settings from './util/settings';
import sha256 from './util/sha256';
 
/* eslint-disable no-underscore-dangle */
export default class AElf {
  constructor(provider) {
    this._requestManager = new RequestManager(provider);
    this.currentProvider = provider;
    this.chain = new Chain(this._requestManager);
  }
 
  static version = process.env.SDK_VERSION;
 
  static providers = {
    HttpProvider
  };
 
  /**
   * @type {protobuf} export protobufjs for developers
   */
  static pbjs = protobuf;
 
  static pbUtils = proto;
 
  static wallet = wallet;
 
  static utils = {
    ...utils,
    ...bloom,
    sha256,
    transform
  };
 
  providers = {
    HttpProvider
  };
 
  settings = new Settings();
 
  /**
   * AElf-sdk version
   * @type {{api: string}}
   */
  version = {
    api: process.env.SDK_VERSION
  };
 
  /**
   * check the rpc node is work or not.
   * @returns {boolean} whether can connect to the rpc.
   */
  isConnected() {
    return this.currentProvider && this.currentProvider.isConnected();
  }
 
  setProvider(provider) {
    this._requestManager.setProvider(provider);
    this.currentProvider = provider;
  }
}
/* eslint-enable */