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
9cf3f70c
Commit
9cf3f70c
authored
Jan 02, 2020
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor some unnecessary if/else conditions
parent
8daf16f0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
33 deletions
+24
-33
blockchain.js
src/blockchain/blockchain.js
+24
-33
No files found.
src/blockchain/blockchain.js
View file @
9cf3f70c
...
@@ -268,7 +268,9 @@ class Blockchain {
...
@@ -268,7 +268,9 @@ class Blockchain {
runOrCallContractMethod
(
contractName
,
contractAbi
,
funABI
,
value
,
address
,
callType
,
lookupOnly
,
logMsg
,
logCallback
,
outputCb
,
confirmationCb
,
continueCb
,
promptCb
)
{
runOrCallContractMethod
(
contractName
,
contractAbi
,
funABI
,
value
,
address
,
callType
,
lookupOnly
,
logMsg
,
logCallback
,
outputCb
,
confirmationCb
,
continueCb
,
promptCb
)
{
// contractsDetails is used to resolve libraries
// contractsDetails is used to resolve libraries
txFormat
.
buildData
(
contractName
,
contractAbi
,
{},
false
,
funABI
,
callType
,
(
error
,
data
)
=>
{
txFormat
.
buildData
(
contractName
,
contractAbi
,
{},
false
,
funABI
,
callType
,
(
error
,
data
)
=>
{
if
(
!
error
)
{
if
(
error
)
{
return
logCallback
(
`
${
logMsg
}
errored:
${
error
}
`
)
}
if
(
!
lookupOnly
)
{
if
(
!
lookupOnly
)
{
logCallback
(
`
${
logMsg
}
pending ... `
)
logCallback
(
`
${
logMsg
}
pending ... `
)
}
else
{
}
else
{
...
@@ -276,26 +278,21 @@ class Blockchain {
...
@@ -276,26 +278,21 @@ class Blockchain {
}
}
if
(
funABI
.
type
===
'fallback'
)
data
.
dataHex
=
value
if
(
funABI
.
type
===
'fallback'
)
data
.
dataHex
=
value
this
.
callFunction
(
address
,
data
,
funABI
,
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
this
.
callFunction
(
address
,
data
,
funABI
,
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
if
(
!
error
)
{
if
(
error
)
{
return
logCallback
(
`
${
logMsg
}
errored:
${
error
}
`
)
}
const
isVM
=
this
.
executionContext
.
isVM
()
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
if
(
isVM
)
{
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
if
(
vmError
.
error
)
{
logCallback
(
`
${
logMsg
}
errored:
${
vmError
.
message
}
`
)
return
logCallback
(
`
${
logMsg
}
errored:
${
vmError
.
message
}
`
)
return
}
}
}
}
if
(
lookupOnly
)
{
if
(
lookupOnly
)
{
const
returnValue
=
(
this
.
executionContext
.
isVM
()
?
txResult
.
result
.
execResult
.
returnValue
:
ethJSUtil
.
toBuffer
(
txResult
.
result
))
const
returnValue
=
(
this
.
executionContext
.
isVM
()
?
txResult
.
result
.
execResult
.
returnValue
:
ethJSUtil
.
toBuffer
(
txResult
.
result
))
outputCb
(
returnValue
)
outputCb
(
returnValue
)
}
}
}
else
{
logCallback
(
`
${
logMsg
}
errored:
${
error
}
`
)
}
})
})
}
else
{
logCallback
(
`
${
logMsg
}
errored:
${
error
}
`
)
}
},
},
(
msg
)
=>
{
(
msg
)
=>
{
logCallback
(
msg
)
logCallback
(
msg
)
...
@@ -380,21 +377,20 @@ class Blockchain {
...
@@ -380,21 +377,20 @@ class Blockchain {
}
}
newAccount
(
_password
,
passwordPromptCb
,
cb
)
{
newAccount
(
_password
,
passwordPromptCb
,
cb
)
{
if
(
!
this
.
executionContext
.
isVM
())
{
if
(
this
.
executionContext
.
isVM
())
{
if
(
!
this
.
config
.
get
(
'settings/personal-mode'
))
{
return
cb
(
'Not running in personal mode'
)
}
passwordPromptCb
((
passphrase
)
=>
{
this
.
executionContext
.
web3
().
personal
.
newAccount
(
passphrase
,
cb
)
})
}
else
{
let
privateKey
let
privateKey
do
{
do
{
privateKey
=
crypto
.
randomBytes
(
32
)
privateKey
=
crypto
.
randomBytes
(
32
)
}
while
(
!
isValidPrivate
(
privateKey
))
}
while
(
!
isValidPrivate
(
privateKey
))
this
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
return
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
}
if
(
!
this
.
config
.
get
(
'settings/personal-mode'
))
{
return
cb
(
'Not running in personal mode'
)
}
}
passwordPromptCb
((
passphrase
)
=>
{
this
.
executionContext
.
web3
().
personal
.
newAccount
(
passphrase
,
cb
)
})
}
}
/** Add an account to the list of account (only for Javascript VM) */
/** Add an account to the list of account (only for Javascript VM) */
...
@@ -429,8 +425,7 @@ class Blockchain {
...
@@ -429,8 +425,7 @@ class Blockchain {
case
'vm'
:
{
case
'vm'
:
{
if
(
!
this
.
accounts
)
{
if
(
!
this
.
accounts
)
{
if
(
cb
)
cb
(
'No accounts?'
)
if
(
cb
)
cb
(
'No accounts?'
)
reject
(
'No accounts?'
)
return
reject
(
'No accounts?'
)
return
}
}
if
(
cb
)
cb
(
null
,
Object
.
keys
(
this
.
accounts
))
if
(
cb
)
cb
(
null
,
Object
.
keys
(
this
.
accounts
))
resolve
(
Object
.
keys
(
this
.
accounts
))
resolve
(
Object
.
keys
(
this
.
accounts
))
...
@@ -468,37 +463,33 @@ class Blockchain {
...
@@ -468,37 +463,33 @@ class Blockchain {
address
=
stripHexPrefix
(
address
)
address
=
stripHexPrefix
(
address
)
if
(
!
this
.
executionContext
.
isVM
())
{
if
(
!
this
.
executionContext
.
isVM
())
{
this
.
executionContext
.
web3
().
eth
.
getBalance
(
address
,
(
err
,
res
)
=>
{
return
this
.
executionContext
.
web3
().
eth
.
getBalance
(
address
,
(
err
,
res
)
=>
{
if
(
err
)
{
if
(
err
)
{
cb
(
err
)
return
cb
(
err
)
}
else
{
cb
(
null
,
res
.
toString
(
10
))
}
}
cb
(
null
,
res
.
toString
(
10
))
})
})
}
else
{
}
if
(
!
this
.
accounts
)
{
if
(
!
this
.
accounts
)
{
return
cb
(
'No accounts?'
)
return
cb
(
'No accounts?'
)
}
}
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
(
err
,
res
)
=>
{
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
(
err
,
res
)
=>
{
if
(
err
)
{
if
(
err
)
{
cb
(
'Account not found'
)
return
cb
(
'Account not found'
)
}
else
{
cb
(
null
,
new
BN
(
res
.
balance
).
toString
(
10
))
}
}
cb
(
null
,
new
BN
(
res
.
balance
).
toString
(
10
))
})
})
}
}
}
/** Get the balance of an address, and convert wei to ether */
/** Get the balance of an address, and convert wei to ether */
getBalanceInEther
(
address
,
callback
)
{
getBalanceInEther
(
address
,
callback
)
{
this
.
getBalance
(
address
,
(
error
,
balance
)
=>
{
this
.
getBalance
(
address
,
(
error
,
balance
)
=>
{
if
(
error
)
{
if
(
error
)
{
callback
(
error
)
return
callback
(
error
)
}
else
{
}
// callback(null, this.executionContext.web3().fromWei(balance, 'ether'))
// callback(null, this.executionContext.web3().fromWei(balance, 'ether'))
callback
(
null
,
Web3
.
utils
.
fromWei
(
balance
.
toString
(
10
),
'ether'
))
callback
(
null
,
Web3
.
utils
.
fromWei
(
balance
.
toString
(
10
),
'ether'
))
}
})
})
}
}
...
...
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