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
6be82ac7
Unverified
Commit
6be82ac7
authored
Feb 27, 2018
by
yann300
Committed by
GitHub
Feb 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1105 from ethereum/refactor/txRunner_remove_ui
extract UI code from txRunner
parents
c1a3c52f
49e1ea12
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
72 deletions
+85
-72
confirmDialog.js
src/app/execution/confirmDialog.js
+1
-1
txLogger.js
src/app/execution/txLogger.js
+1
-1
txRunner.js
src/app/execution/txRunner.js
+13
-61
typeConversion.js
src/app/execution/typeConversion.js
+0
-0
universal-dapp.js
src/universal-dapp.js
+70
-9
No files found.
src/app/execution/confirmDialog.js
View file @
6be82ac7
...
@@ -20,7 +20,7 @@ var css = csjs`
...
@@ -20,7 +20,7 @@ var css = csjs`
function
confirmDialog
(
tx
,
amount
,
gasEstimation
,
self
,
newGasPriceCb
,
initialParamsCb
)
{
function
confirmDialog
(
tx
,
amount
,
gasEstimation
,
self
,
newGasPriceCb
,
initialParamsCb
)
{
var
onGasPriceChange
=
function
()
{
var
onGasPriceChange
=
function
()
{
var
gasPrice
=
el
.
querySelector
(
'#gasprice'
).
value
var
gasPrice
=
el
.
querySelector
(
'#gasprice'
).
value
newGasPriceCb
(
gasPrice
,
(
priceStatus
,
txFeeText
)
=>
{
newGasPriceCb
(
gasPrice
,
(
txFeeText
,
priceStatus
)
=>
{
el
.
querySelector
(
'#txfee'
).
innerHTML
=
txFeeText
el
.
querySelector
(
'#txfee'
).
innerHTML
=
txFeeText
el
.
gasPriceStatus
=
priceStatus
el
.
gasPriceStatus
=
priceStatus
})
})
...
...
src/app/execution/txLogger.js
View file @
6be82ac7
...
@@ -12,7 +12,7 @@ var EventManager = remixLib.EventManager
...
@@ -12,7 +12,7 @@ var EventManager = remixLib.EventManager
var
helper
=
require
(
'../../lib/helper'
)
var
helper
=
require
(
'../../lib/helper'
)
var
executionContext
=
require
(
'../../execution-context'
)
var
executionContext
=
require
(
'../../execution-context'
)
var
modalDialog
=
require
(
'../ui/modal-dialog-custom'
)
var
modalDialog
=
require
(
'../ui/modal-dialog-custom'
)
var
typeConversion
=
require
(
'.
./../lib
/typeConversion'
)
var
typeConversion
=
require
(
'./typeConversion'
)
var
css
=
csjs
`
var
css
=
csjs
`
.log {
.log {
...
...
src/app/execution/txRunner.js
View file @
6be82ac7
...
@@ -4,11 +4,7 @@ var EthJSBlock = require('ethereumjs-block')
...
@@ -4,11 +4,7 @@ var EthJSBlock = require('ethereumjs-block')
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
BN
=
ethJSUtil
.
BN
var
BN
=
ethJSUtil
.
BN
var
executionContext
=
require
(
'../../execution-context'
)
var
executionContext
=
require
(
'../../execution-context'
)
var
modalDialog
=
require
(
'../ui/modaldialog'
)
var
modal
=
require
(
'../ui/modal-dialog-custom'
)
var
modal
=
require
(
'../ui/modal-dialog-custom'
)
var
typeConversion
=
require
(
'../../lib/typeConversion'
)
var
confirmDialog
=
require
(
'./confirmDialog'
)
function
TxRunner
(
vmaccounts
,
api
)
{
function
TxRunner
(
vmaccounts
,
api
)
{
this
.
_api
=
api
this
.
_api
=
api
...
@@ -23,8 +19,8 @@ function TxRunner (vmaccounts, api) {
...
@@ -23,8 +19,8 @@ function TxRunner (vmaccounts, api) {
this
.
queusTxs
=
[]
this
.
queusTxs
=
[]
}
}
TxRunner
.
prototype
.
rawRun
=
function
(
args
,
cb
)
{
TxRunner
.
prototype
.
rawRun
=
function
(
args
,
c
onfirmationCb
,
c
b
)
{
run
(
this
,
args
,
Date
.
now
(),
cb
)
run
(
this
,
args
,
Date
.
now
(),
c
onfirmationCb
,
c
b
)
}
}
function
executeTx
(
tx
,
gasPrice
,
api
,
callback
)
{
function
executeTx
(
tx
,
gasPrice
,
api
,
callback
)
{
...
@@ -41,7 +37,7 @@ function executeTx (tx, gasPrice, api, callback) {
...
@@ -41,7 +37,7 @@ function executeTx (tx, gasPrice, api, callback) {
}
}
}
}
TxRunner
.
prototype
.
execute
=
function
(
args
,
callback
)
{
TxRunner
.
prototype
.
execute
=
function
(
args
,
c
onfirmationCb
,
c
allback
)
{
var
self
=
this
var
self
=
this
var
data
=
args
.
data
var
data
=
args
.
data
...
@@ -50,7 +46,7 @@ TxRunner.prototype.execute = function (args, callback) {
...
@@ -50,7 +46,7 @@ TxRunner.prototype.execute = function (args, callback) {
}
}
if
(
!
executionContext
.
isVM
())
{
if
(
!
executionContext
.
isVM
())
{
self
.
runInNode
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
self
.
runInNode
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
c
onfirmationCb
,
c
allback
)
}
else
{
}
else
{
try
{
try
{
self
.
runInVm
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
self
.
runInVm
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
...
@@ -108,7 +104,7 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall,
...
@@ -108,7 +104,7 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall,
})
})
}
}
TxRunner
.
prototype
.
runInNode
=
function
(
from
,
to
,
data
,
value
,
gasLimit
,
useCall
,
callback
)
{
TxRunner
.
prototype
.
runInNode
=
function
(
from
,
to
,
data
,
value
,
gasLimit
,
useCall
,
c
onfirmCb
,
c
allback
)
{
const
self
=
this
const
self
=
this
var
tx
=
{
from
:
from
,
to
:
to
,
data
:
data
,
value
:
value
}
var
tx
=
{
from
:
from
,
to
:
to
,
data
:
data
,
value
:
value
}
...
@@ -142,62 +138,18 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal
...
@@ -142,62 +138,18 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal
if
(
self
.
_api
.
config
.
getUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
))
{
if
(
self
.
_api
.
config
.
getUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
))
{
return
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
return
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
}
}
self
.
_api
.
detectNetwork
((
err
,
network
)
=>
{
self
.
_api
.
detectNetwork
((
err
,
network
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
err
)
console
.
log
(
err
)
return
return
}
}
if
(
network
.
name
!==
'Main'
)
{
return
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
}
var
amount
=
executionContext
.
web3
().
fromWei
(
typeConversion
.
toInt
(
tx
.
value
),
'ether'
)
confirmCb
(
network
,
tx
,
gasEstimation
,
(
gasPrice
)
=>
{
var
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
self
,
return
executeTx
(
tx
,
gasPrice
,
self
.
_api
,
callback
)
(
gasPrice
,
cb
)
=>
{
},
(
error
)
=>
{
let
txFeeText
,
priceStatus
callback
(
error
)
// TODO: this try catch feels like an anti pattern, can/should be
})
// removed, but for now keeping the original logic
try
{
var
fee
=
executionContext
.
web3
().
toBigNumber
(
tx
.
gas
).
mul
(
executionContext
.
web3
().
toBigNumber
(
executionContext
.
web3
().
toWei
(
gasPrice
.
toString
(
10
),
'gwei'
)))
txFeeText
=
' '
+
executionContext
.
web3
().
fromWei
(
fee
.
toString
(
10
),
'ether'
)
+
' Ether'
priceStatus
=
true
}
catch
(
e
)
{
txFeeText
=
' Please fix this issue before sending any transaction. '
+
e
.
message
priceStatus
=
false
}
cb
(
priceStatus
,
txFeeText
)
},
(
cb
)
=>
{
executionContext
.
web3
().
eth
.
getGasPrice
((
error
,
gasPrice
)
=>
{
var
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
}
try
{
var
gasPriceValue
=
executionContext
.
web3
().
fromWei
(
gasPrice
.
toString
(
10
),
'gwei'
)
cb
(
null
,
gasPriceValue
)
}
catch
(
e
)
{
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
}
})
}
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
self
.
_api
.
config
.
setUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
,
content
.
querySelector
(
'input#confirmsetting'
).
checked
)
if
(
!
content
.
gasPriceStatus
)
{
return
callback
(
'Given gas grice is not correct'
)
}
var
gasPrice
=
executionContext
.
web3
().
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
executeTx
(
tx
,
gasPrice
,
self
.
_api
,
callback
)
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
return
callback
(
'Transaction canceled by user.'
)
}
})
})
})
})
})
}
}
...
@@ -231,12 +183,12 @@ function sendTransaction (sendTx, tx, pass, callback) {
...
@@ -231,12 +183,12 @@ function sendTransaction (sendTx, tx, pass, callback) {
}
}
}
}
function
run
(
self
,
tx
,
stamp
,
callback
)
{
function
run
(
self
,
tx
,
stamp
,
c
onfirmationCb
,
c
allback
)
{
if
(
!
self
.
runAsync
&&
Object
.
keys
(
self
.
pendingTxs
).
length
)
{
if
(
!
self
.
runAsync
&&
Object
.
keys
(
self
.
pendingTxs
).
length
)
{
self
.
queusTxs
.
push
({
tx
,
stamp
,
callback
})
self
.
queusTxs
.
push
({
tx
,
stamp
,
callback
})
}
else
{
}
else
{
self
.
pendingTxs
[
stamp
]
=
tx
self
.
pendingTxs
[
stamp
]
=
tx
self
.
execute
(
tx
,
(
error
,
result
)
=>
{
self
.
execute
(
tx
,
confirmationCb
,
(
error
,
result
)
=>
{
delete
self
.
pendingTxs
[
stamp
]
delete
self
.
pendingTxs
[
stamp
]
callback
(
error
,
result
)
callback
(
error
,
result
)
if
(
self
.
queusTxs
.
length
)
{
if
(
self
.
queusTxs
.
length
)
{
...
...
src/
lib
/typeConversion.js
→
src/
app/execution
/typeConversion.js
View file @
6be82ac7
File moved
src/universal-dapp.js
View file @
6be82ac7
...
@@ -15,6 +15,10 @@ var executionContext = require('./execution-context')
...
@@ -15,6 +15,10 @@ var executionContext = require('./execution-context')
var
modalCustom
=
require
(
'./app/ui/modal-dialog-custom'
)
var
modalCustom
=
require
(
'./app/ui/modal-dialog-custom'
)
var
uiUtil
=
require
(
'./app/ui/util'
)
var
uiUtil
=
require
(
'./app/ui/util'
)
var
modalDialog
=
require
(
'./app/ui/modaldialog'
)
var
typeConversion
=
require
(
'./app/execution/typeConversion'
)
var
confirmDialog
=
require
(
'./app/execution/confirmDialog'
)
/*
/*
trigger debugRequested
trigger debugRequested
*/
*/
...
@@ -249,18 +253,75 @@ UniversalDApp.prototype.runTx = function (args, cb) {
...
@@ -249,18 +253,75 @@ UniversalDApp.prototype.runTx = function (args, cb) {
var
timestamp
=
Date
.
now
()
var
timestamp
=
Date
.
now
()
self
.
event
.
trigger
(
'initiatingTransaction'
,
[
timestamp
,
tx
,
payLoad
])
self
.
event
.
trigger
(
'initiatingTransaction'
,
[
timestamp
,
tx
,
payLoad
])
self
.
txRunner
.
rawRun
(
tx
,
function
(
error
,
result
)
{
self
.
txRunner
.
rawRun
(
tx
,
let
eventName
=
(
tx
.
useCall
?
'callExecuted'
:
'transactionExecuted'
)
self
.
event
.
trigger
(
eventName
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
tx
.
useCall
,
result
,
timestamp
,
payLoad
])
if
(
error
&&
(
typeof
(
error
)
!==
'string'
))
{
(
network
,
tx
,
gasEstimation
,
continueTxExecution
,
cancelCb
)
=>
{
if
(
error
.
message
)
error
=
error
.
message
if
(
network
.
name
!==
'Main'
)
{
else
{
return
continueTxExecution
(
null
)
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
}
}
var
amount
=
executionContext
.
web3
().
fromWei
(
typeConversion
.
toInt
(
tx
.
value
),
'ether'
)
var
content
=
confirmDialog
(
tx
,
amount
,
gasEstimation
,
self
,
(
gasPrice
,
cb
)
=>
{
let
txFeeText
,
priceStatus
// TODO: this try catch feels like an anti pattern, can/should be
// removed, but for now keeping the original logic
try
{
var
fee
=
executionContext
.
web3
().
toBigNumber
(
tx
.
gas
).
mul
(
executionContext
.
web3
().
toBigNumber
(
executionContext
.
web3
().
toWei
(
gasPrice
.
toString
(
10
),
'gwei'
)))
txFeeText
=
' '
+
executionContext
.
web3
().
fromWei
(
fee
.
toString
(
10
),
'ether'
)
+
' Ether'
priceStatus
=
true
}
catch
(
e
)
{
txFeeText
=
' Please fix this issue before sending any transaction. '
+
e
.
message
priceStatus
=
false
}
cb
(
txFeeText
,
priceStatus
)
},
(
cb
)
=>
{
executionContext
.
web3
().
eth
.
getGasPrice
((
error
,
gasPrice
)
=>
{
var
warnMessage
=
' Please fix this issue before sending any transaction. '
if
(
error
)
{
return
cb
(
'Unable to retrieve the current network gas price.'
+
warnMessage
+
error
)
}
try
{
var
gasPriceValue
=
executionContext
.
web3
().
fromWei
(
gasPrice
.
toString
(
10
),
'gwei'
)
cb
(
null
,
gasPriceValue
)
}
catch
(
e
)
{
cb
(
warnMessage
+
e
.
message
,
null
,
false
)
}
})
}
)
modalDialog
(
'Confirm transaction'
,
content
,
{
label
:
'Confirm'
,
fn
:
()
=>
{
self
.
_api
.
config
.
setUnpersistedProperty
(
'doNotShowTransactionConfirmationAgain'
,
content
.
querySelector
(
'input#confirmsetting'
).
checked
)
// TODO: check if this is check is still valid given the refactor
if
(
!
content
.
gasPriceStatus
)
{
cancelCb
(
'Given gas price is not correct'
)
}
else
{
var
gasPrice
=
executionContext
.
web3
().
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
continueTxExecution
(
gasPrice
)
}
}},
{
label
:
'Cancel'
,
fn
:
()
=>
{
return
cancelCb
(
'Transaction canceled by user.'
)
}
})
},
function
(
error
,
result
)
{
let
eventName
=
(
tx
.
useCall
?
'callExecuted'
:
'transactionExecuted'
)
self
.
event
.
trigger
(
eventName
,
[
error
,
tx
.
from
,
tx
.
to
,
tx
.
data
,
tx
.
useCall
,
result
,
timestamp
,
payLoad
])
if
(
error
&&
(
typeof
(
error
)
!==
'string'
))
{
if
(
error
.
message
)
error
=
error
.
message
else
{
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
}
}
next
(
error
,
result
)
}
}
next
(
error
,
result
)
)
})
}
}
],
cb
)
],
cb
)
}
}
...
...
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