Commit 12b370f2 authored by yann300's avatar yann300

fix deploy and link libraries

parent 084e7907
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
], ],
"main": "./index.js", "main": "./index.js",
"dependencies": { "dependencies": {
"async": "^2.1.2",
"babel-preset-es2015": "^6.24.0", "babel-preset-es2015": "^6.24.0",
"babel-plugin-transform-object-assign": "^6.22.0", "babel-plugin-transform-object-assign": "^6.22.0",
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
var ethJSABI = require('ethereumjs-abi') var ethJSABI = require('ethereumjs-abi')
var helper = require('./txHelper') var helper = require('./txHelper')
var executionContext = require('./execution-context') var executionContext = require('./execution-context')
var asyncJS = require('async')
module.exports = { module.exports = {
...@@ -99,10 +100,37 @@ module.exports = { ...@@ -99,10 +100,37 @@ module.exports = {
atAddress: function () {}, atAddress: function () {},
linkBytecode: function (contract, contracts, udapp, callback, callbackStep) { linkBytecodeStandard: function (contract, contracts, udapp, callback, callbackStep) {
if (contract.evm.bytecode.object.indexOf('_') < 0) { asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences, (libs, file, cbFile) => {
return callback(null, contract.evm.bytecode.object) 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})__/) var libraryRefMatch = contract.evm.bytecode.object.match(/__([^_]{1,36})__/)
if (!libraryRefMatch) { if (!libraryRefMatch) {
return callback('Invalid bytecode format.') return callback('Invalid bytecode format.')
...@@ -129,12 +157,22 @@ module.exports = { ...@@ -129,12 +157,22 @@ module.exports = {
if (hexAddress.slice(0, 2) === '0x') { if (hexAddress.slice(0, 2) === '0x') {
hexAddress = hexAddress.slice(2) 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) contract.evm.bytecode.object = this.linkLibrary(libraryName, hexAddress, contract.evm.bytecode.object)
this.linkBytecode(contract, contracts, udapp, callback, callbackStep) this.linkBytecode(contract, contracts, udapp, callback, callbackStep)
}, 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) { deployLibrary: function (libraryName, libraryShortName, library, contracts, udapp, callback, callbackStep) {
var address = library.address var address = library.address
if (address) { if (address) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment