ethereumjs-util#isValidAddress TypeScript Examples

The following examples show how to use ethereumjs-util#isValidAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: txFormat.ts    From remix-project with MIT License 6 votes vote down vote up
/**
* link with provided libraries if needed
*
* @param {Object} contract    - input paramater of the function to call
* @param {Object} linkLibraries    - contains {linkReferences} object which list all the addresses to be linked
* @param {Object} linkReferences    - given by the compiler, contains the proper linkReferences
* @param {Function} callback    - callback
*/
export function linkLibraries (contract, linkLibraries, linkReferences, callback) {
  let bytecodeToDeploy = contract.evm.bytecode.object
    if (bytecodeToDeploy.indexOf('_') >= 0) {
      if (linkLibraries && linkReferences) {
        for (const libFile in linkLibraries) {
          for (const lib in linkLibraries[libFile]) {
            const address = linkLibraries[libFile][lib]
            if (!isValidAddress(address)) return callback(address + ' is not a valid address. Please check the provided address is valid.')
            bytecodeToDeploy = linkLibraryStandardFromlinkReferences(lib, address.replace('0x', ''), bytecodeToDeploy, linkReferences)
          }
        }
      }
    }
    if (bytecodeToDeploy.indexOf('_') >= 0) {
      return callback('Failed to link some libraries')
    }
    return callback(null, bytecodeToDeploy)
}