# All files / src/period index.js

100% Statements 17/17
100% Branches 5/5
100% Functions 4/4
100% Lines 16/16

    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

    1x
    1x

    3x
    3x
    3x

    1x
    1x

    2x

    2x
    2x
    2x

    2x
    1x
    1x

    1x

    2x

     /**
     * Copyright (c) 2018-present, Leap DAO (leapdao.org)
     *
     * This source code is licensed under the Mozilla Public License Version 2.0
     * found in the LICENSE file in the root directory of this source tree.
     */

    const submitPeriod = require('../txHelpers/submitPeriod');
    const { logPeriod } = require('../utils/debug');

    module.exports = (bridgeState, nodeConfig = {}) => async (rsp, chainInfo) => {
      const height = chainInfo.height - 32;
      if (height === 0) {
        // genesis height doesn't need check
        rsp.status = 1;
        return;
      }

      logPeriod('checkBridge');
      // use a timeout to relax race conditions (if period submission is fast)
      await new Promise((resolve) => {
        setTimeout(async () => {
          const contractPeriod = await submitPeriod(
            bridgeState.previousPeriod,
            bridgeState.currentState.slots,
            height + bridgeState.checkCallsCount,
            bridgeState,
            nodeConfig
          );

          if (contractPeriod.timestamp === '0') {
            rsp.status = 0;
            bridgeState.checkCallsCount += 1;
          } else {
            rsp.status = 1;
          }

          resolve();
        }, 300);
      });
    };