src/blockchain/chain.js
function Chain(options) {
  if (!(this instanceof Chain))
    return new Chain(options);

  AsyncObject.call(this);

  this.options = new ChainOptions(options);

  this.network = this.options.network;
  this.logger = this.options.logger.context('chain');
  this.workers = this.options.workers;

  this.db = new ChainDB(this.options);

  this.locker = new Lock(true);
  this.invalid = new LRU(100);
  this.state = new DeploymentState();

  this.tip = new ChainEntry();
  this.height = -1;
  this.synced = false;

  this.orphanMap = new Map();
  this.orphanPrev = new Map();

  this.subscribers = {};
  this.subscribeJobs = {};
  this._subscribes = {
    cmds: [],
    cp: null
  };
  this._notifies = {
    cmds: [],
    cp: null
  };
}
function Chain(options) {
  if (!(this instanceof Chain))
    return new Chain(options);

  AsyncObject.call(this);

  this.options = new ChainOptions(options);

  this.network = this.options.network;
  this.logger = this.options.logger.context('chain');
  this.workers = this.options.workers;

  this.db = new ChainDB(this.options);

  this.locker = new Lock(true);
  this.invalid = new LRU(100);
  this.state = new DeploymentState();

  this.tip = new ChainEntry();
  this.height = -1;
  this.synced = false;

  this.orphanMap = new Map();
  this.orphanPrev = new Map();

  this.subscribers = {};
  this.subscribeJobs = {};
  this._subscribes = {
    cmds: [],
    cp: null
  };
  this._notifies = {
    cmds: [],
    cp: null
  };
}
function Chain ( options ) { if ( ! ( this instanceof Chain ) ) return new Chain ( options ) ; AsyncObject . call ( this ) ; this . options = new ChainOptions ( options ) ; this . network = this . options . network ; this . logger = this . options . logger . context ( 'chain' ) ; this . workers = this . options . workers ; this . db = new ChainDB ( this . options ) ; this . locker = new Lock ( true ) ; this . invalid = new LRU ( 100 ) ; this . state = new DeploymentState ( ) ; this . tip = new ChainEntry ( ) ; this . height = - 1 ; this . synced = false ; this . orphanMap = new Map ( ) ; this . orphanPrev = new Map ( ) ; this . subscribers = { } ; this . subscribeJobs = { } ; this . _subscribes = { cmds : [ ] , cp : null } ; this . _notifies = { cmds : [ ] , cp : null } ; }
Represents a blockchain.
@alias module:blockchain.Chain
@constructor
@param {Object} options
@param {String?} options.name - Database name.
@param {String?} options.location - Database file location.
@param {String?} options.db - Database backend (`"leveldb"` by default).
@param {Number?} options.maxOrphans
@param {Boolean?} options.spv
@property {Boolean} loaded
@property {ChainDB} db - Note that Chain `options` will be passed
to the instantiated ChainDB.
@property {Lock} locker
@property {Object} invalid
@property {ChainEntry?} tip
@property {Number} height
@property {DeploymentState} state
@property {Object} orphan - Orphan map.
@emits Chain#open
@emits Chain#error
@emits Chain#block
@emits Chain#competitor
@emits Chain#resolved
@emits Chain#checkpoint
@emits Chain#fork
@emits Chain#reorganize
@emits Chain#invalid
@emits Chain#exists
@emits Chain#purge
@emits Chain#connect
@emits Chain#reconnect
@emits Chain#disconnect
Represents a blockchain .