Commit 375c604e authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #804 from ethereum/fixLib

Fix library
parents 08e13f1f f6fdab08
...@@ -35,8 +35,8 @@ class EventsDecoder { ...@@ -35,8 +35,8 @@ class EventsDecoder {
this._decodeEvents(tx, receipt.logs, contract, contracts, cb) this._decodeEvents(tx, receipt.logs, contract, contracts, cb)
} }
_eventABI (contractName, compiledContracts) { _eventABI (contractabi) {
var contractabi = JSON.parse(compiledContracts[contractName].interface) contractabi = JSON.parse(contractabi.interface)
var eventABI = {} var eventABI = {}
contractabi.forEach(function (funABI, i) { contractabi.forEach(function (funABI, i) {
if (funABI.type !== 'event') { if (funABI.type !== 'event') {
...@@ -48,13 +48,30 @@ class EventsDecoder { ...@@ -48,13 +48,30 @@ class EventsDecoder {
return eventABI return eventABI
} }
_eventsABI (compiledContracts) {
var eventsABI = {}
for (var contract in compiledContracts) {
eventsABI[contract] = this._eventABI(compiledContracts[contract])
}
return eventsABI
}
_event (hash, eventsABI) {
for (var k in eventsABI) {
if (eventsABI[k][hash]) {
return eventsABI[k][hash]
}
}
return null
}
_decodeEvents (tx, logs, contractName, compiledContracts, cb) { _decodeEvents (tx, logs, contractName, compiledContracts, cb) {
var eventABI = this._eventABI(contractName, compiledContracts) var eventsABI = this._eventsABI(compiledContracts)
var events = [] var events = []
for (var i in logs) { for (var i in logs) {
// [address, topics, mem] // [address, topics, mem]
var log = logs[i] var log = logs[i]
var abi = eventABI[log.topics[0].replace('0x', '')] var abi = this._event(log.topics[0].replace('0x', ''), eventsABI)
if (abi) { if (abi) {
var event var event
try { try {
......
...@@ -18,8 +18,9 @@ module.exports = { ...@@ -18,8 +18,9 @@ module.exports = {
* @param {Object} params - input paramater of the function to call * @param {Object} params - input paramater of the function to call
* @param {Object} udapp - udapp * @param {Object} udapp - udapp
* @param {Function} callback - callback * @param {Function} callback - callback
* @param {Function} callbackStep - callbackStep
*/ */
buildData: function (contract, contracts, isConstructor, funAbi, params, udapp, callback) { buildData: function (contract, contracts, isConstructor, funAbi, params, udapp, callback, callbackStep) {
var funArgs = '' var funArgs = ''
try { try {
funArgs = $.parseJSON('[' + params + ']') funArgs = $.parseJSON('[' + params + ']')
...@@ -54,7 +55,7 @@ module.exports = { ...@@ -54,7 +55,7 @@ module.exports = {
bytecodeToDeploy = bytecode + dataHex bytecodeToDeploy = bytecode + dataHex
return callback(null, bytecodeToDeploy) return callback(null, bytecodeToDeploy)
} }
}) }, callbackStep)
return return
} else { } else {
dataHex = bytecodeToDeploy + dataHex dataHex = bytecodeToDeploy + dataHex
...@@ -67,7 +68,7 @@ module.exports = { ...@@ -67,7 +68,7 @@ module.exports = {
atAddress: function () {}, atAddress: function () {},
linkBytecode: function (contract, contracts, udapp, callback) { linkBytecode: function (contract, contracts, udapp, callback, callbackStep) {
var bytecode = contract.bytecode var bytecode = contract.bytecode
if (bytecode.indexOf('_') < 0) { if (bytecode.indexOf('_') < 0) {
return callback(null, bytecode) return callback(null, bytecode)
...@@ -81,7 +82,7 @@ module.exports = { ...@@ -81,7 +82,7 @@ module.exports = {
if (!libraryabi) { if (!libraryabi) {
return callback('Library ' + libraryName + ' not found.') return callback('Library ' + libraryName + ' not found.')
} }
this.deployLibrary(libraryabi, udapp, (err, address) => { this.deployLibrary(libraryName, libraryabi, udapp, (err, address) => {
if (err) { if (err) {
return callback(err) return callback(err)
} }
...@@ -95,22 +96,23 @@ module.exports = { ...@@ -95,22 +96,23 @@ module.exports = {
bytecode = bytecode.replace(libLabel, hexAddress) bytecode = bytecode.replace(libLabel, hexAddress)
} }
contract.bytecode = bytecode contract.bytecode = bytecode
this.linkBytecode(contract, contracts, udapp, callback) this.linkBytecode(contract, contracts, udapp, callback, callbackStep)
}) }, callbackStep)
}, },
deployLibrary: function (libraryName, library, udapp, callback) { deployLibrary: function (libraryName, library, udapp, callback, callbackStep) {
var address = library.address var address = library.address
if (address) { if (address) {
return callback(null, address) return callback(null, address)
} }
var bytecode = library.bytecode var bytecode = library.bytecode
if (bytecode.indexOf('_') >= 0) { if (bytecode.indexOf('_') >= 0) {
this.linkBytecode(libraryName, (err, bytecode) => { this.linkBytecode(libraryName, library, udapp, (err, bytecode) => {
if (err) callback(err) if (err) callback(err)
else this.deployLibrary(libraryName, callback) else this.deployLibrary(libraryName, library, udapp, callback, callbackStep)
}) }, callbackStep)
} else { } else {
callbackStep(`creation of library ${libraryName} pending...`)
udapp.runTx({ data: bytecode, useCall: false }, (err, txResult) => { udapp.runTx({ data: bytecode, useCall: false }, (err, txResult) => {
if (err) { if (err) {
return callback(err) return callback(err)
......
...@@ -91,7 +91,7 @@ module.exports = { ...@@ -91,7 +91,7 @@ module.exports = {
getContractByName: function (contractName, contracts) { getContractByName: function (contractName, contracts) {
for (var c in contracts) { for (var c in contracts) {
if (contracts[c].name === contractName) { if (c === contractName) {
return contracts[c] return contracts[c]
} }
} }
......
...@@ -323,6 +323,8 @@ function contractDropdown (appAPI, appEvents, instanceContainer) { ...@@ -323,6 +323,8 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
} else { } else {
appAPI.logMessage(`creation of ${contractName} errored: ` + error) appAPI.logMessage(`creation of ${contractName} errored: ` + error)
} }
}, (msg) => {
appAPI.logMessage(msg)
}) })
} }
......
...@@ -417,6 +417,8 @@ UniversalDApp.prototype.getCallButton = function (args) { ...@@ -417,6 +417,8 @@ UniversalDApp.prototype.getCallButton = function (args) {
} else { } else {
self._api.logMessage(`${logMsg} errored: ${error} `) self._api.logMessage(`${logMsg} errored: ${error} `)
} }
}, (msg) => {
self._api.logMessage(msg)
}) })
} }
......
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