|
|
@ -1,65 +1,83 @@ |
|
|
|
'use strict' |
|
|
|
'use strict' |
|
|
|
|
|
|
|
var executionContext = require('../../execution-context') |
|
|
|
|
|
|
|
|
|
|
|
class CompilerMetadata { |
|
|
|
class CompilerMetadata { |
|
|
|
constructor (events, opts) { |
|
|
|
constructor (events, opts) { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
self._events = events |
|
|
|
self._events = events |
|
|
|
self._opts = opts |
|
|
|
self._opts = opts |
|
|
|
|
|
|
|
self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42'] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
syncContractMetadata () { |
|
|
|
syncContractMetadata () { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
self._events.compiler.register('compilationFinished', (success, data, source) => { |
|
|
|
self._events.compiler.register('compilationFinished', (success, data, source) => { |
|
|
|
if (success) { |
|
|
|
if (!success) return |
|
|
|
var provider = self._opts.fileManager.currentFileProvider() |
|
|
|
var provider = self._opts.fileManager.currentFileProvider() |
|
|
|
var path = self._opts.fileManager.currentPath() |
|
|
|
var path = self._opts.fileManager.currentPath() |
|
|
|
if (provider && path) { |
|
|
|
if (provider && path) { |
|
|
|
self._opts.compiler.visitContracts((contract) => { |
|
|
|
self._opts.compiler.visitContracts((contract) => { |
|
|
|
var fileName = path + '/' + contract.name + '.json' |
|
|
|
var fileName = path + '/' + contract.name + '.json' |
|
|
|
provider.get(fileName, (error, content) => { |
|
|
|
provider.get(fileName, (error, content) => { |
|
|
|
if (!error) { |
|
|
|
if (!error) { |
|
|
|
content = content || '{}' |
|
|
|
content = content || '{}' |
|
|
|
var metadata |
|
|
|
var metadata |
|
|
|
try { |
|
|
|
try { |
|
|
|
metadata = JSON.parse(content) |
|
|
|
metadata = JSON.parse(content) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.log(e) |
|
|
|
console.log(e) |
|
|
|
} |
|
|
|
|
|
|
|
var linkReferences = metadata['linkReferences'] |
|
|
|
|
|
|
|
var autoDeployLib = metadata['autoDeployLib'] |
|
|
|
|
|
|
|
if (!linkReferences) linkReferences = {} |
|
|
|
|
|
|
|
if (autoDeployLib === undefined) autoDeployLib = true |
|
|
|
|
|
|
|
for (var libFile in contract.object.evm.bytecode.linkReferences) { |
|
|
|
|
|
|
|
if (!linkReferences[libFile]) linkReferences[libFile] = {} |
|
|
|
|
|
|
|
for (var lib in contract.object.evm.bytecode.linkReferences[libFile]) { |
|
|
|
|
|
|
|
if (!linkReferences[libFile][lib]) { |
|
|
|
|
|
|
|
linkReferences[libFile][lib] = '<address>' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
metadata['linkReferences'] = linkReferences |
|
|
|
|
|
|
|
metadata['autoDeployLib'] = autoDeployLib |
|
|
|
|
|
|
|
provider.set(fileName, JSON.stringify(metadata, null, '\t')) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
self.networks.forEach((network) => { |
|
|
|
|
|
|
|
metadata[network] = self._syncContext(contract, metadata[network] || {}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
provider.set(fileName, JSON.stringify(metadata, null, '\t')) |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_syncContext (contract, metadata) { |
|
|
|
|
|
|
|
var linkReferences = metadata['linkReferences'] |
|
|
|
|
|
|
|
var autoDeployLib = metadata['autoDeployLib'] |
|
|
|
|
|
|
|
if (!linkReferences) linkReferences = {} |
|
|
|
|
|
|
|
if (autoDeployLib === undefined) autoDeployLib = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var libFile in contract.object.evm.bytecode.linkReferences) { |
|
|
|
|
|
|
|
if (!linkReferences[libFile]) linkReferences[libFile] = {} |
|
|
|
|
|
|
|
for (var lib in contract.object.evm.bytecode.linkReferences[libFile]) { |
|
|
|
|
|
|
|
if (!linkReferences[libFile][lib]) { |
|
|
|
|
|
|
|
linkReferences[libFile][lib] = '<address>' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
metadata['linkReferences'] = linkReferences |
|
|
|
|
|
|
|
metadata['autoDeployLib'] = autoDeployLib |
|
|
|
|
|
|
|
return metadata |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
metadataOf (contractName, callback) { |
|
|
|
metadataOf (contractName, callback) { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
var provider = self._opts.fileManager.currentFileProvider() |
|
|
|
var provider = self._opts.fileManager.currentFileProvider() |
|
|
|
var path = self._opts.fileManager.currentPath() |
|
|
|
var path = self._opts.fileManager.currentPath() |
|
|
|
if (provider && path) { |
|
|
|
if (provider && path) { |
|
|
|
var fileName = path + '/' + contractName + '.json' |
|
|
|
executionContext.detectNetwork((err, { id, name } = {}) => { |
|
|
|
provider.get(fileName, (error, content) => { |
|
|
|
if (err) { |
|
|
|
if (error) return callback(error) |
|
|
|
console.log(err) |
|
|
|
try { |
|
|
|
} else { |
|
|
|
callback(null, JSON.parse(content)) |
|
|
|
var fileName = path + '/' + contractName + '.json' |
|
|
|
} catch (e) { |
|
|
|
provider.get(fileName, (error, content) => { |
|
|
|
callback(e.message) |
|
|
|
if (error) return callback(error) |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var metadata = JSON.parse(content) |
|
|
|
|
|
|
|
return callback(null, metadata[name + ':' + id] || metadata[name] || metadata[id]) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
callback(e.message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|