All files / lib WireError.ts

100% Statements 17/17
100% Branches 2/2
100% Functions 2/2
100% Lines 17/17

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 431x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x                               1x           11x 11x   11x 11x 11x      
export enum WireErrorCode {
  nodeAnnSigFailed = 1,
  chanAnnSigFailed = 2,
  chanUpdSigFailed = 3,
  chanBadBlockHash = 4,
  chanBadBlock = 5,
  chanAnnBadTx = 6,
  chanUtxoSpent = 7,
  chanBadScript = 8,
  gossipManagerNotStarted = 101,
}
 
const errorCodeStrings = {
  1: 'node_ann_sig_failed',
  2: 'chan_ann_sig_failed',
  3: 'chan_upd_sig_failed',
  4: 'chan_bad_block_hash',
  5: 'chan_bad_block',
  6: 'chan_bad_tx',
  7: 'chan_utxo_spent',
  8: 'chan_bad_script',
  101: 'gossip_manager_not_started',
};
 
/**
 * Creates an error for a wire operation and captures relevant that
 * caused the error to be emitted or thrown.
 */
export class WireError extends Error {
  public area: string;
  public code: WireErrorCode;
  public data: any;
 
  constructor(code: WireErrorCode, data?: any) {
    const msg = `${errorCodeStrings[code]}`;
    super(msg);
 
    this.area = 'wire';
    this.code = code;
    this.data = data;
  }
}