src/blockchain/merkle.js
function getHash (data, depth, index) {
    let element
    let elementsHash

    if (depth !== 0 && (depth + 1) !== height) {
      throw new Error('Value node is on wrong height in tree.')
    }

    if (start.gt(index) || end.lt(index)) {
      throw new Error('Wrong index of value node.')
    }

    if (start.plus(elements.length).neq(index)) {
      throw new Error('Value node is on wrong position in tree.')
    }

    if (typeof data === 'string') {
      if (!validateHexadecimal(data)) {
        throw new TypeError('Tree element of wrong type is passed. Hexadecimal expected.')
      }
      element = data
      elementsHash = element
    } else {
      if (Array.isArray(data)) {
        if (!validateBytesArray(data)) {
          throw new TypeError('Tree element of wrong type is passed. Bytes array expected.')
        }
        element = data.slice(0) // clone array of 8-bit integers
        elementsHash = hash(element)
      } else {
        if (!isObject(data)) {
          throw new TypeError('Invalid value of data parameter.')
        }
        if (!isType(type)) {
          throw new TypeError('Invalid type of type parameter.')
        }
        element = data
        elementsHash = hash(element, type)
      }
    }

    elements.push(element)
    return elementsHash
  }
function getHash (data, depth, index) {
    let element
    let elementsHash

    if (depth !== 0 && (depth + 1) !== height) {
      throw new Error('Value node is on wrong height in tree.')
    }

    if (start.gt(index) || end.lt(index)) {
      throw new Error('Wrong index of value node.')
    }

    if (start.plus(elements.length).neq(index)) {
      throw new Error('Value node is on wrong position in tree.')
    }

    if (typeof data === 'string') {
      if (!validateHexadecimal(data)) {
        throw new TypeError('Tree element of wrong type is passed. Hexadecimal expected.')
      }
      element = data
      elementsHash = element
    } else {
      if (Array.isArray(data)) {
        if (!validateBytesArray(data)) {
          throw new TypeError('Tree element of wrong type is passed. Bytes array expected.')
        }
        element = data.slice(0) // clone array of 8-bit integers
        elementsHash = hash(element)
      } else {
        if (!isObject(data)) {
          throw new TypeError('Invalid value of data parameter.')
        }
        if (!isType(type)) {
          throw new TypeError('Invalid type of type parameter.')
        }
        element = data
        elementsHash = hash(element, type)
      }
    }

    elements.push(element)
    return elementsHash
  }
function getHash ( data , depth , index ) { let element let elementsHash if ( depth !== 0 && ( depth + 1 ) !== height ) { throw new Error ( 'Value node is on wrong height in tree.' ) } if ( start . gt ( index ) || end . lt ( index ) ) { throw new Error ( 'Wrong index of value node.' ) } if ( start . plus ( elements . length ) . neq ( index ) ) { throw new Error ( 'Value node is on wrong position in tree.' ) } if ( typeof data === 'string' ) { if ( ! validateHexadecimal ( data ) ) { throw new TypeError ( 'Tree element of wrong type is passed. Hexadecimal expected.' ) } element = data elementsHash = element } else { if ( Array . isArray ( data ) ) { if ( ! validateBytesArray ( data ) ) { throw new TypeError ( 'Tree element of wrong type is passed. Bytes array expected.' ) } element = data . slice ( 0 ) // clone array of 8-bit integers elementsHash = hash ( element ) } else { if ( ! isObject ( data ) ) { throw new TypeError ( 'Invalid value of data parameter.' ) } if ( ! isType ( type ) ) { throw new TypeError ( 'Invalid type of type parameter.' ) } element = data elementsHash = hash ( element , type ) } } elements . push ( element ) return elementsHash }
Get value from node, insert into elements array and return its hash
@param data
@param {number} depth
@param {number} index
@returns {string}
Get value from node insert into elements array and return its hash