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
b69fbce5
Commit
b69fbce5
authored
Jan 03, 2020
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove duplicated methods
parent
9cf3f70c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
88 deletions
+42
-88
recorder.js
src/app/tabs/runTab/model/recorder.js
+1
-1
settings.js
src/app/tabs/runTab/settings.js
+1
-1
blockchain.js
src/blockchain/blockchain.js
+40
-86
No files found.
src/app/tabs/runTab/model/recorder.js
View file @
b69fbce5
...
...
@@ -247,7 +247,7 @@ class Recorder {
logCallBack
(
`(
${
index
}
) data:
${
data
.
data
}
`
)
record
.
data
=
{
dataHex
:
data
.
data
,
funArgs
:
tx
.
record
.
parameters
,
funAbi
:
fnABI
,
contractBytecode
:
tx
.
record
.
bytecode
,
contractName
:
tx
.
record
.
contractName
,
timestamp
:
tx
.
timestamp
}
self
.
blockchain
.
runT
ransaction
(
record
,
continueCb
,
promptCb
,
confirmation
Cb
,
self
.
blockchain
.
runT
x
(
record
,
confirmationCb
,
continueCb
,
prompt
Cb
,
function
(
err
,
txResult
)
{
if
(
err
)
{
console
.
error
(
err
)
...
...
src/app/tabs/runTab/settings.js
View file @
b69fbce5
...
...
@@ -44,7 +44,7 @@ class SettingsUI {
if
(
!
this
.
el
)
return
var
accounts
=
$
(
this
.
el
.
querySelector
(
'#txorigin'
)).
children
(
'option'
)
accounts
.
each
((
index
,
account
)
=>
{
this
.
blockchain
.
get
AccountBalanceForAddress
(
account
.
value
,
(
err
,
balance
)
=>
{
this
.
blockchain
.
get
BalanceInEther
(
account
.
value
,
(
err
,
balance
)
=>
{
if
(
err
)
return
account
.
innerText
=
helper
.
shortenAddress
(
account
.
value
,
balance
)
})
...
...
src/blockchain/blockchain.js
View file @
b69fbce5
...
...
@@ -68,8 +68,8 @@ class Blockchain {
statusCb
(
`creation of
${
selectedContract
.
name
}
pending...`
)
this
.
createContract
(
selectedContract
,
data
,
continueCb
,
promptCb
,
confirmationCb
,
finalCb
)
},
statusCb
,
(
data
,
runTxCallback
)
=>
{
// called for libraries deployment
this
.
runT
ransaction
(
data
,
continueCb
,
promptCb
,
confirmation
Cb
,
runTxCallback
)
// called for libraries deployment
this
.
runT
x
(
data
,
confirmationCb
,
continueCb
,
prompt
Cb
,
runTxCallback
)
})
}
if
(
Object
.
keys
(
selectedContract
.
bytecodeLinkReferences
).
length
)
statusCb
(
`linking
${
JSON
.
stringify
(
selectedContract
.
bytecodeLinkReferences
,
null
,
'
\
t'
)}
using
${
JSON
.
stringify
(
contractMetadata
.
linkReferences
,
null
,
'
\
t'
)}
`
)
...
...
@@ -81,10 +81,6 @@ class Blockchain {
})
}
runTransaction
(
data
,
continueCb
,
promptCb
,
confirmationCb
,
finalCb
)
{
this
.
runTx
(
data
,
confirmationCb
,
continueCb
,
promptCb
,
finalCb
)
}
createContract
(
selectedContract
,
data
,
continueCb
,
promptCb
,
confirmationCb
,
finalCb
)
{
if
(
data
)
{
data
.
contractName
=
selectedContract
.
name
...
...
@@ -92,29 +88,29 @@ class Blockchain {
data
.
contractABI
=
selectedContract
.
abi
}
this
.
_createContract
(
data
,
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
if
(
error
)
{
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored:
${
error
}
`
)
}
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
return
finalCb
(
vmError
.
message
)
}
}
if
(
txResult
.
result
.
status
&&
txResult
.
result
.
status
===
'0x0'
)
{
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored: transaction execution failed`
)
}
const
address
=
isVM
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
finalCb
(
null
,
selectedContract
,
address
)
}
)
this
.
runTx
({
data
:
data
,
useCall
:
false
}
,
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
if
(
error
)
{
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored:
${
error
}
`
)
}
const
isVM
=
this
.
executionContext
.
isVM
()
if
(
isVM
)
{
const
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
return
finalCb
(
vmError
.
message
)
}
}
if
(
txResult
.
result
.
status
&&
txResult
.
result
.
status
===
'0x0'
)
{
return
finalCb
(
`creation of
${
selectedContract
.
name
}
errored: transaction execution failed`
)
}
const
address
=
isVM
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
finalCb
(
null
,
selectedContract
,
address
)
}
)
}
determineGasPrice
(
cb
)
{
this
.
getGasPrice
((
error
,
gasPrice
)
=>
{
this
.
executionContext
.
web3
().
eth
.
getGasPrice
((
error
,
gasPrice
)
=>
{
const
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
...
...
@@ -128,10 +124,6 @@ class Blockchain {
})
}
getGasPrice
(
cb
)
{
return
this
.
executionContext
.
web3
().
eth
.
getGasPrice
(
cb
)
}
fromWei
(
value
,
doTypeConversion
,
unit
)
{
if
(
doTypeConversion
)
{
return
Web3
.
utils
.
fromWei
(
typeConversion
.
toInt
(
value
),
unit
||
'ether'
)
...
...
@@ -182,10 +174,6 @@ class Blockchain {
return
this
.
executionContext
.
getProvider
()
}
getAccountBalanceForAddress
(
address
,
cb
)
{
return
this
.
getBalanceInEther
(
address
,
cb
)
}
updateNetwork
(
cb
)
{
this
.
networkcallid
++
((
callid
)
=>
{
...
...
@@ -458,8 +446,8 @@ class Blockchain {
})
}
/** Get the balance of an address */
getBalance
(
address
,
cb
)
{
/** Get the balance of an address
, and convert wei to ether
*/
getBalance
InEther
(
address
,
cb
)
{
address
=
stripHexPrefix
(
address
)
if
(
!
this
.
executionContext
.
isVM
())
{
...
...
@@ -467,7 +455,7 @@ class Blockchain {
if
(
err
)
{
return
cb
(
err
)
}
cb
(
null
,
res
.
toString
(
10
))
cb
(
null
,
Web3
.
utils
.
fromWei
(
res
.
toString
(
10
),
'ether'
))
})
}
if
(
!
this
.
accounts
)
{
...
...
@@ -478,18 +466,7 @@ class Blockchain {
if
(
err
)
{
return
cb
(
'Account not found'
)
}
cb
(
null
,
new
BN
(
res
.
balance
).
toString
(
10
))
})
}
/** Get the balance of an address, and convert wei to ether */
getBalanceInEther
(
address
,
callback
)
{
this
.
getBalance
(
address
,
(
error
,
balance
)
=>
{
if
(
error
)
{
return
callback
(
error
)
}
// callback(null, this.executionContext.web3().fromWei(balance, 'ether'))
callback
(
null
,
Web3
.
utils
.
fromWei
(
balance
.
toString
(
10
),
'ether'
))
cb
(
null
,
Web3
.
utils
.
fromWei
(
new
BN
(
res
.
balance
).
toString
(
10
),
'ether'
))
})
}
...
...
@@ -498,19 +475,6 @@ class Blockchain {
}
/**
* deploy the given contract
*
* @param {String} data - data to send with the transaction ( return of txFormat.buildData(...) ).
* @param {Function} callback - callback.
*/
_createContract
(
data
,
confirmationCb
,
continueCb
,
promptCb
,
callback
)
{
this
.
runTx
({
data
:
data
,
useCall
:
false
},
confirmationCb
,
continueCb
,
promptCb
,
(
error
,
txResult
)
=>
{
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback
(
error
,
txResult
)
})
}
/**
* call the current given contract
*
* @param {String} to - address of the contract to call.
...
...
@@ -543,35 +507,25 @@ class Blockchain {
if
(
network
.
name
===
'Main'
&&
network
.
id
===
'1'
)
{
return
reject
(
new
Error
(
'It is not allowed to make this action against mainnet'
))
}
this
.
silentRunTx
(
tx
,
(
error
,
result
)
=>
{
if
(
error
)
return
reject
(
error
)
try
{
resolve
(
resultToRemixTx
(
result
))
}
catch
(
e
)
{
reject
(
e
)
this
.
txRunner
.
rawRun
(
tx
,
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
continueTxExecution
()
},
(
error
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
error
)
{
reject
(
error
)
}
else
{
continueTxExecution
()
}
},
(
okCb
,
cancelCb
)
=>
{
okCb
()
},
(
error
,
result
)
=>
{
if
(
error
)
return
reject
(
error
)
try
{
resolve
(
resultToRemixTx
(
result
))
}
catch
(
e
)
{
reject
(
e
)
}
}
}
)
)
})
})
}
/**
* This function send a tx without alerting the user (if mainnet or if gas estimation too high).
* SHOULD BE TAKEN CAREFULLY!
*
* @param {Object} tx - transaction.
* @param {Function} callback - callback.
*/
silentRunTx
(
tx
,
cb
)
{
this
.
txRunner
.
rawRun
(
tx
,
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
continueTxExecution
()
},
(
error
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
error
)
{
cb
(
error
)
}
else
{
continueTxExecution
()
}
},
(
okCb
,
cancelCb
)
=>
{
okCb
()
},
cb
)
}
runTx
(
args
,
confirmationCb
,
continueCb
,
promptCb
,
cb
)
{
const
self
=
this
async
.
waterfall
([
...
...
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