packages/core/src/web3-utils.js
// Taken with modifications from solc/linker
Taken with modifications from solc/linker
Taken with modifications from solc / linker
linkBytecode (bytecode, libs) {
    const links = Object.assign({}, libs)
    const keys = Object.keys(links)
    for (let i = 0; i < keys.length; i++) {
      let name = keys[i]
      let addr = links[name]
      name = name.slice(0, 36)
      let label = '__' + name + Array(37 - name.length).join('_') + '__'
      if (addr.slice(0, 2) !== '0x' || addr.length > 42) {
        throw new Error('Invalid address specified for ' + name)
      }
      addr = addr.slice(2)
      addr = Array(40 - addr.length + 1).join('0') + addr
      while (bytecode.indexOf(label) >= 0) {
        bytecode = bytecode.replace(label, addr)
      }
      const regex = new RegExp('__' + name + '_+', 'g')
      bytecode = bytecode.replace(regex, addr.replace('0x', ''))
    }
    return bytecode
  }
linkBytecode ( bytecode , libs ) { const links = Object . assign ( { } , libs ) const keys = Object . keys ( links ) for ( let i = 0 ; i < keys . length ; i ++ ) { let name = keys [ i ] let addr = links [ name ] name = name . slice ( 0 , 36 ) let label = '__' + name + Array ( 37 - name . length ) . join ( '_' ) + '__' if ( addr . slice ( 0 , 2 ) !== '0x' || addr . length > 42 ) { throw new Error ( 'Invalid address specified for ' + name ) } addr = addr . slice ( 2 ) addr = Array ( 40 - addr . length + 1 ) . join ( '0' ) + addr while ( bytecode . indexOf ( label ) >= 0 ) { bytecode = bytecode . replace ( label , addr ) } const regex = new RegExp ( '__' + name + '_+' , 'g' ) bytecode = bytecode . replace ( regex , addr . replace ( '0x' , '' ) ) } return bytecode }
Taken with modifications from solc/linker
Taken with modifications from solc / linker
// Truncate to 37 characters // Prefix and suffix with __ // Remove 0x prefix