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
3d8dceb6
Commit
3d8dceb6
authored
Jan 08, 2020
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor get provider
parent
d563b17c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
18 deletions
+31
-18
blockchain.js
src/blockchain/blockchain.js
+19
-18
injected.js
src/blockchain/providers/injected.js
+4
-0
node.js
src/blockchain/providers/node.js
+4
-0
vm.js
src/blockchain/providers/vm.js
+4
-0
No files found.
src/blockchain/blockchain.js
View file @
3d8dceb6
...
...
@@ -34,7 +34,7 @@ class Blockchain {
this
.
executionContext
.
detectNetwork
(
cb
)
},
personalMode
:
()
=>
{
return
this
.
executionContext
.
getProvider
()
===
'web3'
?
this
.
config
.
get
(
'settings/personal-mode'
)
:
false
return
this
.
getProvider
()
===
'web3'
?
this
.
config
.
get
(
'settings/personal-mode'
)
:
false
}
},
this
.
executionContext
)
this
.
executionContext
.
event
.
register
(
'contextChanged'
,
this
.
resetEnvironment
.
bind
(
this
))
...
...
@@ -66,7 +66,7 @@ class Blockchain {
}
getCurrentProvider
()
{
const
provider
=
this
.
executionContext
.
getProvider
()
const
provider
=
this
.
getProvider
()
return
this
.
providers
[
provider
]
}
...
...
@@ -199,10 +199,6 @@ class Blockchain {
return
this
.
executionContext
.
setProviderFromEndpoint
(
target
,
context
,
cb
)
}
getProvider
()
{
return
this
.
executionContext
.
getProvider
()
}
updateNetwork
(
cb
)
{
this
.
networkcallid
++
((
callid
)
=>
{
...
...
@@ -221,14 +217,18 @@ class Blockchain {
return
this
.
executionContext
.
detectNetwork
(
cb
)
}
getProvider
()
{
return
this
.
executionContext
.
getProvider
()
}
isWeb3Provider
()
{
const
isVM
=
this
.
executionContext
.
isVM
()
const
isInjected
=
this
.
executionContext
.
getProvider
()
===
'injected'
const
isVM
=
this
.
getProvider
===
'vm'
const
isInjected
=
this
.
getProvider
()
===
'injected'
return
(
!
isVM
&&
!
isInjected
)
}
isInjectedWeb3
()
{
return
this
.
executionContext
.
getProvider
()
===
'injected'
return
this
.
getProvider
()
===
'injected'
}
signMessage
(
message
,
account
,
passphrase
,
cb
)
{
...
...
@@ -263,13 +263,6 @@ class Blockchain {
if
(
error
)
{
return
logCallback
(
`
${
logMsg
}
errored:
${
error
}
`
)
}
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
return
logCallback
(
`
${
logMsg
}
errored:
${
vmError
.
message
}
`
)
}
}
if
(
lookupOnly
)
{
const
returnValue
=
(
this
.
executionContext
.
isVM
()
?
txResult
.
result
.
execResult
.
returnValue
:
ethJSUtil
.
toBuffer
(
txResult
.
result
))
outputCb
(
returnValue
)
...
...
@@ -322,7 +315,7 @@ class Blockchain {
this
.
executionContext
.
detectNetwork
(
cb
)
},
personalMode
:
()
=>
{
return
this
.
executionContext
.
getProvider
()
===
'web3'
?
this
.
config
.
get
(
'settings/personal-mode'
)
:
false
return
this
.
getProvider
()
===
'web3'
?
this
.
config
.
get
(
'settings/personal-mode'
)
:
false
}
},
this
.
executionContext
)
this
.
txRunner
.
event
.
register
(
'transactionBroadcasted'
,
(
txhash
)
=>
{
...
...
@@ -338,7 +331,7 @@ class Blockchain {
* @param {{privateKey: string, balance: string}} newAccount The new account to create
*/
createVMAccount
(
newAccount
)
{
if
(
this
.
executionContext
.
getProvider
()
!==
'vm'
)
{
if
(
this
.
getProvider
()
!==
'vm'
)
{
throw
new
Error
(
'plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed'
)
}
return
this
.
providers
.
vm
.
createVMAccount
(
newAccount
)
...
...
@@ -368,6 +361,14 @@ class Blockchain {
callFunction
(
to
,
data
,
funAbi
,
confirmationCb
,
continueCb
,
promptCb
,
callback
)
{
const
useCall
=
funAbi
.
stateMutability
===
'view'
||
funAbi
.
stateMutability
===
'pure'
this
.
runTx
({
to
,
data
,
useCall
},
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
return
callback
(
vmError
.
message
)
}
}
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback
(
error
,
txResult
)
})
...
...
src/blockchain/providers/injected.js
View file @
3d8dceb6
...
...
@@ -40,6 +40,10 @@ class InjectedProvider {
cb
(
e
.
message
)
}
}
getProvider
()
{
return
'injected'
}
}
module
.
exports
=
InjectedProvider
src/blockchain/providers/node.js
View file @
3d8dceb6
...
...
@@ -49,6 +49,10 @@ class NodeProvider {
cb
(
e
.
message
)
}
}
getProvider
()
{
return
this
.
executionContext
.
getProvider
()
}
}
module
.
exports
=
NodeProvider
src/blockchain/providers/vm.js
View file @
3d8dceb6
...
...
@@ -83,6 +83,10 @@ class VMProvider {
cb
(
e
.
message
)
}
}
getProvider
()
{
return
'vm'
}
}
module
.
exports
=
VMProvider
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