Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
d7665816
Commit
d7665816
authored
Mar 05, 2019
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
turn API into promise
parent
f09f7616
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
50 deletions
+88
-50
app.js
src/app.js
+28
-17
SourceHighlighters.js
src/app/editor/SourceHighlighters.js
+16
-10
browser-files-tree.js
src/app/files/browser-files-tree.js
+1
-0
compile-tab.js
src/app/tabs/compile-tab.js
+6
-0
universal-dapp.js
src/universal-dapp.js
+37
-23
No files found.
src/app.js
View file @
d7665816
...
...
@@ -253,32 +253,43 @@ class App {
})
}
getExecutionContextProvider
(
cb
)
{
cb
(
null
,
executionContext
.
getProvider
())
getExecutionContextProvider
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
(
executionContext
.
getProvider
())
})
}
getProviderEndpoint
(
cb
)
{
if
(
executionContext
.
getProvider
()
===
'web3'
)
{
cb
(
null
,
executionContext
.
web3
().
currentProvider
.
host
)
}
else
{
cb
(
'no endpoint: current provider is either injected or vm'
)
}
getProviderEndpoint
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
executionContext
.
getProvider
()
===
'web3'
)
{
resolve
(
executionContext
.
web3
().
currentProvider
.
host
)
}
else
{
reject
(
'no endpoint: current provider is either injected or vm'
)
}
})
}
detectNetWork
(
cb
)
{
executionContext
.
detectNetwork
((
error
,
network
)
=>
{
cb
(
error
,
network
)
detectNetWork
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
executionContext
.
detectNetwork
((
error
,
network
)
=>
{
if
(
error
)
return
reject
(
error
)
resolve
(
network
)
})
})
}
addProvider
(
name
,
url
,
cb
)
{
executionContext
.
addProvider
({
name
,
url
})
cb
()
addProvider
(
name
,
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
executionContext
.
addProvider
({
name
,
url
})
resolve
()
})
}
removeProvider
(
name
,
cb
)
{
executionContext
.
removeProvider
(
name
)
cb
()
removeProvider
(
name
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
executionContext
.
removeProvider
(
name
)
resolve
()
})
}
}
...
...
src/app/editor/SourceHighlighters.js
View file @
d7665816
...
...
@@ -18,19 +18,25 @@ class SourceHighlighters {
// TODO what to do with mod?
async
highlight
(
mod
,
lineColumnPos
,
filePath
,
hexColor
)
{
let
position
try
{
position
=
JSON
.
parse
(
lineColumnPos
)
}
catch
(
e
)
{
throw
e
}
if
(
!
this
.
highlighters
[
mod
])
this
.
highlighters
[
mod
]
=
new
SourceHighlighter
()
this
.
highlighters
[
mod
].
currentSourceLocation
(
null
)
this
.
highlighters
[
mod
].
currentSourceLocationFromfileName
(
position
,
filePath
,
hexColor
)
return
new
Promise
((
resolve
,
reject
)
=>
{
let
position
try
{
position
=
JSON
.
parse
(
lineColumnPos
)
}
catch
(
e
)
{
throw
e
}
if
(
!
this
.
highlighters
[
mod
])
this
.
highlighters
[
mod
]
=
new
SourceHighlighter
()
this
.
highlighters
[
mod
].
currentSourceLocation
(
null
)
this
.
highlighters
[
mod
].
currentSourceLocationFromfileName
(
position
,
filePath
,
hexColor
)
resolve
()
})
}
async
discardHighlight
(
mod
)
{
if
(
this
.
highlighters
[
mod
])
this
.
highlighters
[
mod
].
currentSourceLocation
(
null
)
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
highlighters
[
mod
])
this
.
highlighters
[
mod
].
currentSourceLocation
(
null
)
resolve
()
})
}
}
...
...
src/app/files/browser-files-tree.js
View file @
d7665816
...
...
@@ -132,6 +132,7 @@ function FilesTree (name, storage) {
}
this
.
profile
=
function
()
{
// TODO should make them promisable
return
{
name
:
this
.
type
,
methods
:
[
'get'
,
'set'
,
'remove'
],
...
...
src/app/tabs/compile-tab.js
View file @
d7665816
...
...
@@ -143,6 +143,12 @@ class CompileTab {
}
}
getCompilationResult
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
(
this
.
compileTabLogic
.
compiler
.
lastCompilationResult
)
})
}
/*********
* SUB-COMPONENTS
*/
...
...
src/universal-dapp.js
View file @
d7665816
...
...
@@ -33,7 +33,7 @@ UniversalDApp.prototype.profile = function () {
return
{
name
:
'udapp'
,
displayName
:
'universal dapp'
,
methods
:
[
'runTx'
,
'getAccounts'
,
'createVMAccount'
],
methods
:
[
'runT
estT
x'
,
'getAccounts'
,
'createVMAccount'
],
description
:
'service - run transaction and access account'
}
}
...
...
@@ -73,11 +73,13 @@ UniversalDApp.prototype.resetAPI = function (transactionContextAPI) {
}
UniversalDApp
.
prototype
.
createVMAccount
=
function
(
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'
)
this
.
_addAccount
(
privateKey
,
balance
)
executionContext
.
vm
().
stateManager
.
cache
.
flush
(
function
()
{})
privateKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
cb
(
null
,
'0x'
+
ethJSUtil
.
privateToAddress
(
privateKey
).
toString
(
'hex'
))
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
executionContext
.
getProvider
()
!==
'vm'
)
return
reject
(
'plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed'
)
this
.
_addAccount
(
privateKey
,
balance
)
executionContext
.
vm
().
stateManager
.
cache
.
flush
(
function
()
{})
privateKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
resolve
(
'0x'
+
ethJSUtil
.
privateToAddress
(
privateKey
).
toString
(
'hex'
))
})
}
UniversalDApp
.
prototype
.
newAccount
=
function
(
password
,
passwordPromptCb
,
cb
)
{
...
...
@@ -116,24 +118,36 @@ UniversalDApp.prototype._addAccount = function (privateKey, balance) {
}
}
// TODO should remove this cb
UniversalDApp
.
prototype
.
getAccounts
=
function
(
cb
)
{
var
self
=
this
if
(
!
executionContext
.
isVM
())
{
// Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async
// See: https://github.com/ethereum/web3.js/issues/442
if
(
this
.
_deps
.
config
.
get
(
'settings/personal-mode'
))
{
return
executionContext
.
web3
().
personal
.
getListAccounts
(
cb
)
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
executionContext
.
isVM
())
{
// Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async
// See: https://github.com/ethereum/web3.js/issues/442
if
(
this
.
_deps
.
config
.
get
(
'settings/personal-mode'
))
{
return
executionContext
.
web3
().
personal
.
getListAccounts
((
error
,
accounts
)
=>
{
if
(
cb
)
cb
(
error
,
accounts
)
if
(
error
)
return
reject
(
error
)
resolve
(
accounts
)
})
}
else
{
executionContext
.
web3
().
eth
.
getAccounts
((
error
,
accounts
)
=>
{
if
(
cb
)
cb
(
error
,
accounts
)
if
(
error
)
return
reject
(
error
)
resolve
(
accounts
)
})
}
}
else
{
executionContext
.
web3
().
eth
.
getAccounts
(
cb
)
}
}
else
{
if
(
!
self
.
accounts
)
{
return
cb
(
'No accounts?'
)
if
(
!
self
.
accounts
)
{
if
(
cb
)
cb
(
'No accounts?'
)
reject
(
'No accounts?'
)
return
}
if
(
cb
)
cb
(
null
,
Object
.
keys
(
self
.
accounts
))
resolve
(
Object
.
keys
(
self
.
accounts
))
}
cb
(
null
,
Object
.
keys
(
self
.
accounts
))
}
})
}
UniversalDApp
.
prototype
.
getBalance
=
function
(
address
,
cb
)
{
...
...
@@ -235,12 +249,12 @@ UniversalDApp.prototype.getInputs = function (funABI) {
UniversalDApp
.
prototype
.
runTestTx
=
function
(
tx
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
executionContext
.
detectNetwork
((
error
,
network
)
=>
{
if
(
error
)
reject
(
error
)
if
(
error
)
re
turn
re
ject
(
error
)
if
(
network
.
name
===
'Main'
&&
network
.
id
===
'1'
)
{
reject
(
new
Error
(
'It is not allowed to make this action against mainnet'
))
re
turn
re
ject
(
new
Error
(
'It is not allowed to make this action against mainnet'
))
}
this
.
silentRunTx
(
tx
,
(
error
,
result
)
=>
{
if
(
error
)
reject
(
error
)
if
(
error
)
re
turn
re
ject
(
error
)
resolve
({
transactionHash
:
result
.
transactionHash
,
status
:
result
.
result
.
status
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment