parent
a91c94dc49
commit
06e81ca845
@ -0,0 +1,41 @@ |
||||
plugin api |
||||
|
||||
# current APIs: |
||||
|
||||
## 1) notifications |
||||
|
||||
### app (key: app) |
||||
|
||||
- unfocus `[]` |
||||
- focus `[]` |
||||
|
||||
### compiler (key: compiler) |
||||
|
||||
- compilationFinished `[success (bool), data (obj), source (obj)]` |
||||
- compilationData `[compilationResult]` |
||||
|
||||
### transaction listener (key: txlistener) |
||||
|
||||
- newTransaction `tx (obj)` |
||||
|
||||
## 2) interactions |
||||
|
||||
### app |
||||
|
||||
- getExecutionContextProvider `@return {String} provider (injected | web3 | vm)` |
||||
- updateTitle `@param {String} title` |
||||
|
||||
### config |
||||
|
||||
- setConfig `@param {String} path, @param {String} content` |
||||
- getConfig `@param {String} path` |
||||
- removeConfig `@param {String} path` |
||||
|
||||
### compiler |
||||
- getCompilationResult `@return {Object} compilation result` |
||||
|
||||
### udapp (only VM) |
||||
- runTx `@param {Object} tx` |
||||
- getAccounts `@return {Array} acccounts` |
||||
- createVMAccount `@param {String} privateKey, @param {String} balance (hex)` |
||||
|
@ -1,26 +1,62 @@ |
||||
'use strict' |
||||
var executionContext = require('../../execution-context') |
||||
|
||||
/* |
||||
Defines available API. `key` / `type` |
||||
*/ |
||||
module.exports = (registry) => { |
||||
module.exports = (fileProviders, compiler, udapp, tabbedMenu) => { |
||||
return { |
||||
app: { |
||||
getExecutionContextProvider: (mod, cb) => { |
||||
cb(null, executionContext.getProvider()) |
||||
}, |
||||
updateTitle: (mod, title, cb) => { |
||||
tabbedMenu.updateTabTitle(mod, title) |
||||
} |
||||
}, |
||||
config: { |
||||
setConfig: (mod, path, content, cb) => { |
||||
registry.get('fileproviders/config').api.set(mod + '/' + path, content) |
||||
fileProviders['config'].set(mod + '/' + path, content) |
||||
cb() |
||||
}, |
||||
getConfig: (mod, path, cb) => { |
||||
cb(null, registry.get('fileproviders/config').get(mod + '/' + path)) |
||||
cb(null, fileProviders['config'].get(mod + '/' + path)) |
||||
}, |
||||
removeConfig: (mod, path, cb) => { |
||||
cb(null, registry.get('fileproviders/config').api.remove(mod + '/' + path)) |
||||
cb(null, fileProviders['config'].remove(mod + '/' + path)) |
||||
if (cb) cb() |
||||
} |
||||
}, |
||||
compiler: { |
||||
getCompilationResult: () => { |
||||
return registry.get('compiler').api.lastCompilationResult |
||||
getCompilationResult: (mod, cb) => { |
||||
cb(null, compiler.lastCompilationResult) |
||||
} |
||||
}, |
||||
udapp: { |
||||
runTx: (mod, tx, cb) => { |
||||
if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow sending a transaction through a web3 connection. Only vm mode is allowed') |
||||
udapp.silentRunTx(tx, (error, result) => { |
||||
if (error) return cb(error) |
||||
cb(null, { |
||||
transactionHash: result.transactionHash, |
||||
status: result.result.status, |
||||
gasUsed: '0x' + result.result.gasUsed.toString('hex'), |
||||
error: result.result.vm.exceptionError, |
||||
return: result.result.vm.return ? '0x' + result.result.vm.return.toString('hex') : '0x', |
||||
createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined |
||||
}) |
||||
}) |
||||
}, |
||||
getAccounts: (mod, cb) => { |
||||
if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow retrieving accounts through a web3 connection. Only vm mode is allowed') |
||||
udapp.getAccounts(cb) |
||||
}, |
||||
createVMAccount: (mod, privateKey, balance, cb) => { |
||||
if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') |
||||
udapp.createVMAccount(privateKey, balance, (error, address) => { |
||||
cb(error, address) |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue