# All files / src/api/methods getBalance.js

100% Statements 8/8
100% Branches 7/7
100% Functions 1/1
100% Lines 8/8

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
    173x
    3x

    3x
    4x

    1x

    3x
    3x
    3x

     const { INVALID_PARAMS } = require('./constants');
    const { BigInt } = require('jsbi-utils');

    module.exports = async (bridgeState, address, tag = 'latest') => {
      if (tag !== 'latest') {
        /* eslint-disable no-throw-literal */
        throw {
          code: INVALID_PARAMS,
          message: 'Only balance for latest block is supported',
        };
        /* eslint-enable no-throw-literal */
      }
      const balances = bridgeState.currentState.balances['0'] || {};
      const balance = balances[address] || 0;
      return `0x${BigInt(balance).toString(16)}`;
    };