fix deploy and link libraries

pull/7/head
yann300 7 years ago
parent 084e7907c9
commit 12b370f211
  1. 1
      remix-lib/package.json
  2. 46
      remix-lib/src/execution/txFormat.js

@ -14,6 +14,7 @@
],
"main": "./index.js",
"dependencies": {
"async": "^2.1.2",
"babel-preset-es2015": "^6.24.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-eslint": "^7.1.1",

@ -2,6 +2,7 @@
var ethJSABI = require('ethereumjs-abi')
var helper = require('./txHelper')
var executionContext = require('./execution-context')
var asyncJS = require('async')
module.exports = {
@ -99,10 +100,37 @@ module.exports = {
atAddress: function () {},
linkBytecode: function (contract, contracts, udapp, callback, callbackStep) {
if (contract.evm.bytecode.object.indexOf('_') < 0) {
return callback(null, contract.evm.bytecode.object)
linkBytecodeStandard: function (contract, contracts, udapp, callback, callbackStep) {
asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences, (libs, file, cbFile) => {
asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences[file], (libRef, libName, cbLibDeployed) => {
var library = contracts[file][libName]
if (library) {
this.deployLibrary(file + ':' + libName, libName, library, contracts, udapp, (error, address) => {
if (error) {
return cbLibDeployed(error)
}
var hexAddress = address.toString('hex')
if (hexAddress.slice(0, 2) === '0x') {
hexAddress = hexAddress.slice(2)
}
contract.evm.bytecode.object = this.linkLibraryStandard(libName, hexAddress, contract)
cbLibDeployed()
}, callbackStep)
} else {
cbLibDeployed('Cannot find compilation data of library ' + libName)
}
}, (error) => {
cbFile(error)
})
}, (error) => {
if (error) {
callbackStep(error)
}
callback(error, contract.evm.bytecode.object)
})
},
linkBytecodeLegacy: function (contract, contracts, udapp, callback, callbackStep) {
var libraryRefMatch = contract.evm.bytecode.object.match(/__([^_]{1,36})__/)
if (!libraryRefMatch) {
return callback('Invalid bytecode format.')
@ -129,12 +157,22 @@ module.exports = {
if (hexAddress.slice(0, 2) === '0x') {
hexAddress = hexAddress.slice(2)
}
contract.evm.bytecode.object = this.linkLibraryStandard(libraryShortName, hexAddress, contract)
contract.evm.bytecode.object = this.linkLibrary(libraryName, hexAddress, contract.evm.bytecode.object)
this.linkBytecode(contract, contracts, udapp, callback, callbackStep)
}, callbackStep)
},
linkBytecode: function (contract, contracts, udapp, callback, callbackStep) {
if (contract.evm.bytecode.object.indexOf('_') < 0) {
return callback(null, contract.evm.bytecode.object)
}
if (contract.evm.bytecode.linkReferences && Object.keys(contract.evm.bytecode.linkReferences).length) {
this.linkBytecodeStandard(contract, contracts, udapp, callback, callbackStep)
} else {
this.linkBytecodeLegacy(contract, contracts, udapp, callback, callbackStep)
}
},
deployLibrary: function (libraryName, libraryShortName, library, contracts, udapp, callback, callbackStep) {
var address = library.address
if (address) {

Loading…
Cancel
Save