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
8daf16f0
Commit
8daf16f0
authored
Jan 02, 2020
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update blockchain module syntax
parent
42b8a5be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
blockchain.js
src/blockchain/blockchain.js
+18
-18
No files found.
src/blockchain/blockchain.js
View file @
8daf16f0
...
@@ -60,7 +60,7 @@ class Blockchain {
...
@@ -60,7 +60,7 @@ class Blockchain {
async
deployContract
(
selectedContract
,
args
,
contractMetadata
,
compilerContracts
,
callbacks
,
confirmationCb
)
{
async
deployContract
(
selectedContract
,
args
,
contractMetadata
,
compilerContracts
,
callbacks
,
confirmationCb
)
{
const
{
continueCb
,
promptCb
,
statusCb
,
finalCb
}
=
callbacks
const
{
continueCb
,
promptCb
,
statusCb
,
finalCb
}
=
callbacks
var
constructor
=
selectedContract
.
getConstructorInterface
()
const
constructor
=
selectedContract
.
getConstructorInterface
()
if
(
!
contractMetadata
||
(
contractMetadata
&&
contractMetadata
.
autoDeployLib
))
{
if
(
!
contractMetadata
||
(
contractMetadata
&&
contractMetadata
.
autoDeployLib
))
{
return
txFormat
.
buildData
(
selectedContract
.
name
,
selectedContract
.
object
,
compilerContracts
,
true
,
constructor
,
args
,
(
error
,
data
)
=>
{
return
txFormat
.
buildData
(
selectedContract
.
name
,
selectedContract
.
object
,
compilerContracts
,
true
,
constructor
,
args
,
(
error
,
data
)
=>
{
if
(
error
)
return
statusCb
(
`creation of
${
selectedContract
.
name
}
errored: `
+
error
)
if
(
error
)
return
statusCb
(
`creation of
${
selectedContract
.
name
}
errored: `
+
error
)
...
@@ -97,9 +97,9 @@ class Blockchain {
...
@@ -97,9 +97,9 @@ class Blockchain {
if
(
error
)
{
if
(
error
)
{
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored:
${
error
}
`
)
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored:
${
error
}
`
)
}
}
var
isVM
=
this
.
executionContext
.
isVM
()
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
if
(
isVM
)
{
var
vmError
=
txExecution
.
checkVMError
(
txResult
)
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
if
(
vmError
.
error
)
{
return
finalCb
(
vmError
.
message
)
return
finalCb
(
vmError
.
message
)
}
}
...
@@ -107,7 +107,7 @@ class Blockchain {
...
@@ -107,7 +107,7 @@ class Blockchain {
if
(
txResult
.
result
.
status
&&
txResult
.
result
.
status
===
'0x0'
)
{
if
(
txResult
.
result
.
status
&&
txResult
.
result
.
status
===
'0x0'
)
{
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored: transaction execution failed`
)
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored: transaction execution failed`
)
}
}
var
address
=
isVM
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
const
address
=
isVM
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
finalCb
(
null
,
selectedContract
,
address
)
finalCb
(
null
,
selectedContract
,
address
)
}
}
)
)
...
@@ -115,12 +115,12 @@ class Blockchain {
...
@@ -115,12 +115,12 @@ class Blockchain {
determineGasPrice
(
cb
)
{
determineGasPrice
(
cb
)
{
this
.
getGasPrice
((
error
,
gasPrice
)
=>
{
this
.
getGasPrice
((
error
,
gasPrice
)
=>
{
var
warnMessage
=
' Please fix this issue before sending any transaction. '
const
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
if
(
error
)
{
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
}
}
try
{
try
{
var
gasPriceValue
=
this
.
fromWei
(
gasPrice
,
false
,
'gwei'
)
const
gasPriceValue
=
this
.
fromWei
(
gasPrice
,
false
,
'gwei'
)
cb
(
null
,
gasPriceValue
)
cb
(
null
,
gasPriceValue
)
}
catch
(
e
)
{
}
catch
(
e
)
{
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
...
@@ -153,7 +153,7 @@ class Blockchain {
...
@@ -153,7 +153,7 @@ class Blockchain {
// TODO: this try catch feels like an anti pattern, can/should be
// TODO: this try catch feels like an anti pattern, can/should be
// removed, but for now keeping the original logic
// removed, but for now keeping the original logic
try
{
try
{
var
fee
=
this
.
calculateFee
(
tx
.
gas
,
gasPrice
)
const
fee
=
this
.
calculateFee
(
tx
.
gas
,
gasPrice
)
txFeeText
=
' '
+
this
.
fromWei
(
fee
,
false
,
'ether'
)
+
' Ether'
txFeeText
=
' '
+
this
.
fromWei
(
fee
,
false
,
'ether'
)
+
' Ether'
priceStatus
=
true
priceStatus
=
true
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -205,8 +205,8 @@ class Blockchain {
...
@@ -205,8 +205,8 @@ class Blockchain {
}
}
isWeb3Provider
()
{
isWeb3Provider
()
{
var
isVM
=
this
.
executionContext
.
isVM
()
const
isVM
=
this
.
executionContext
.
isVM
()
var
isInjected
=
this
.
executionContext
.
getProvider
()
===
'injected'
const
isInjected
=
this
.
executionContext
.
getProvider
()
===
'injected'
return
(
!
isVM
&&
!
isInjected
)
return
(
!
isVM
&&
!
isInjected
)
}
}
...
@@ -215,15 +215,15 @@ class Blockchain {
...
@@ -215,15 +215,15 @@ class Blockchain {
}
}
signMessage
(
message
,
account
,
passphrase
,
cb
)
{
signMessage
(
message
,
account
,
passphrase
,
cb
)
{
var
isVM
=
this
.
executionContext
.
isVM
()
const
isVM
=
this
.
executionContext
.
isVM
()
var
isInjected
=
this
.
executionContext
.
getProvider
()
===
'injected'
const
isInjected
=
this
.
executionContext
.
getProvider
()
===
'injected'
if
(
isVM
)
{
if
(
isVM
)
{
const
personalMsg
=
ethJSUtil
.
hashPersonalMessage
(
Buffer
.
from
(
message
))
const
personalMsg
=
ethJSUtil
.
hashPersonalMessage
(
Buffer
.
from
(
message
))
var
privKey
=
this
.
accounts
[
account
].
privateKey
const
privKey
=
this
.
accounts
[
account
].
privateKey
try
{
try
{
var
rsv
=
ethJSUtil
.
ecsign
(
personalMsg
,
privKey
)
const
rsv
=
ethJSUtil
.
ecsign
(
personalMsg
,
privKey
)
var
signedData
=
ethJSUtil
.
toRpcSig
(
rsv
.
v
,
rsv
.
r
,
rsv
.
s
)
const
signedData
=
ethJSUtil
.
toRpcSig
(
rsv
.
v
,
rsv
.
r
,
rsv
.
s
)
cb
(
null
,
'0x'
+
personalMsg
.
toString
(
'hex'
),
signedData
)
cb
(
null
,
'0x'
+
personalMsg
.
toString
(
'hex'
),
signedData
)
}
catch
(
e
)
{
}
catch
(
e
)
{
cb
(
e
.
message
)
cb
(
e
.
message
)
...
@@ -244,7 +244,7 @@ class Blockchain {
...
@@ -244,7 +244,7 @@ class Blockchain {
const
hashedMsg
=
Web3
.
utils
.
sha3
(
message
)
const
hashedMsg
=
Web3
.
utils
.
sha3
(
message
)
try
{
try
{
var
personal
=
new
Personal
(
this
.
executionContext
.
web3
().
currentProvider
)
const
personal
=
new
Personal
(
this
.
executionContext
.
web3
().
currentProvider
)
personal
.
sign
(
hashedMsg
,
account
,
passphrase
,
(
error
,
signedData
)
=>
{
personal
.
sign
(
hashedMsg
,
account
,
passphrase
,
(
error
,
signedData
)
=>
{
cb
(
error
.
message
,
hashedMsg
,
signedData
)
cb
(
error
.
message
,
hashedMsg
,
signedData
)
})
})
...
@@ -277,9 +277,9 @@ class Blockchain {
...
@@ -277,9 +277,9 @@ 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
)
{
var
isVM
=
this
.
executionContext
.
isVM
()
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
if
(
isVM
)
{
var
vmError
=
txExecution
.
checkVMError
(
txResult
)
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
if
(
vmError
.
error
)
{
logCallback
(
`
${
logMsg
}
errored:
${
vmError
.
message
}
`
)
logCallback
(
`
${
logMsg
}
errored:
${
vmError
.
message
}
`
)
return
return
...
@@ -412,7 +412,7 @@ class Blockchain {
...
@@ -412,7 +412,7 @@ class Blockchain {
stateManager
.
getAccount
(
address
,
(
error
,
account
)
=>
{
stateManager
.
getAccount
(
address
,
(
error
,
account
)
=>
{
if
(
error
)
return
console
.
log
(
error
)
if
(
error
)
return
console
.
log
(
error
)
account
.
balance
=
balance
||
'0xf00000000000000001'
account
.
balance
=
balance
||
'0xf00000000000000001'
stateManager
.
putAccount
(
address
,
account
,
function
cb
(
error
)
{
stateManager
.
putAccount
(
address
,
account
,
(
error
)
=>
{
if
(
error
)
console
.
log
(
error
)
if
(
error
)
console
.
log
(
error
)
})
})
})
})
...
...
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