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
9937c9c4
Commit
9937c9c4
authored
Feb 19, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate runInVm code from runInNode
parent
ef105746
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
65 deletions
+71
-65
txRunner.js
src/app/execution/txRunner.js
+71
-65
No files found.
src/app/execution/txRunner.js
View file @
9937c9c4
...
@@ -43,12 +43,10 @@ TxRunner.prototype.rawRun = function (args, cb) {
...
@@ -43,12 +43,10 @@ TxRunner.prototype.rawRun = function (args, cb) {
run
(
this
,
args
,
Date
.
now
(),
cb
)
run
(
this
,
args
,
Date
.
now
(),
cb
)
}
}
TxRunner
.
prototype
.
execute
=
function
(
args
,
callback
)
{
function
executeTx
(
tx
,
gasPrice
,
api
,
callback
)
{
var
self
=
this
function
execute
(
gasPrice
)
{
if
(
gasPrice
)
tx
.
gasPrice
=
executionContext
.
web3
().
toHex
(
gasPrice
)
if
(
gasPrice
)
tx
.
gasPrice
=
executionContext
.
web3
().
toHex
(
gasPrice
)
if
(
self
.
_
api
.
personalMode
())
{
if
(
api
.
personalMode
())
{
modal
.
promptPassphrase
(
null
,
'Personal mode is enabled. Please provide passphrase of account '
+
tx
.
from
,
''
,
(
value
)
=>
{
modal
.
promptPassphrase
(
null
,
'Personal mode is enabled. Please provide passphrase of account '
+
tx
.
from
,
''
,
(
value
)
=>
{
sendTransaction
(
executionContext
.
web3
().
personal
.
sendTransaction
,
tx
,
value
,
callback
)
sendTransaction
(
executionContext
.
web3
().
personal
.
sendTransaction
,
tx
,
value
,
callback
)
},
()
=>
{
},
()
=>
{
...
@@ -57,27 +55,85 @@ TxRunner.prototype.execute = function (args, callback) {
...
@@ -57,27 +55,85 @@ TxRunner.prototype.execute = function (args, callback) {
}
else
{
}
else
{
sendTransaction
(
executionContext
.
web3
().
eth
.
sendTransaction
,
tx
,
null
,
callback
)
sendTransaction
(
executionContext
.
web3
().
eth
.
sendTransaction
,
tx
,
null
,
callback
)
}
}
}
}
TxRunner
.
prototype
.
execute
=
function
(
args
,
callback
)
{
var
self
=
this
var
from
=
args
.
from
var
to
=
args
.
to
var
data
=
args
.
data
var
data
=
args
.
data
if
(
data
.
slice
(
0
,
2
)
!==
'0x'
)
{
if
(
data
.
slice
(
0
,
2
)
!==
'0x'
)
{
data
=
'0x'
+
data
data
=
'0x'
+
data
}
}
var
value
=
args
.
value
var
gasLimit
=
args
.
gasLimit
var
tx
if
(
!
executionContext
.
isVM
())
{
if
(
!
executionContext
.
isVM
())
{
tx
=
{
self
.
runInNode
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
}
else
{
self
.
runInVm
(
args
.
from
,
args
.
to
,
data
,
args
.
value
,
args
.
gasLimit
,
args
.
useCall
,
callback
)
}
}
TxRunner
.
prototype
.
runInVm
=
function
(
from
,
to
,
data
,
value
,
gasLimit
,
useCall
,
callback
)
{
const
self
=
this
try
{
var
account
=
self
.
vmaccounts
[
from
]
if
(
!
account
)
{
return
callback
(
'Invalid account selected'
)
}
var
tx
=
new
EthJSTX
({
nonce
:
new
BN
(
account
.
nonce
++
),
gasPrice
:
new
BN
(
1
),
gasLimit
:
new
BN
(
gasLimit
,
10
),
to
:
to
,
value
:
new
BN
(
value
,
10
),
data
:
new
Buffer
(
data
.
slice
(
2
),
'hex'
)
})
tx
.
sign
(
account
.
privateKey
)
const
coinbases
=
[
'0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a'
,
'0x8945a1288dc78a6d8952a92c77aee6730b414778'
,
'0x94d76e24f818426ae84aa404140e8d5f60e10e7e'
]
const
difficulties
=
[
new
BN
(
'69762765929000'
,
10
),
new
BN
(
'70762765929000'
,
10
),
new
BN
(
'71762765929000'
,
10
)
]
var
block
=
new
EthJSBlock
({
header
:
{
timestamp
:
new
Date
().
getTime
()
/
1000
|
0
,
number
:
self
.
blockNumber
,
coinbase
:
coinbases
[
self
.
blockNumber
%
coinbases
.
length
],
difficulty
:
difficulties
[
self
.
blockNumber
%
difficulties
.
length
],
gasLimit
:
new
BN
(
gasLimit
,
10
).
imuln
(
2
)
},
transactions
:
[],
uncleHeaders
:
[]
})
if
(
!
useCall
)
{
++
self
.
blockNumber
}
else
{
executionContext
.
vm
().
stateManager
.
checkpoint
()
}
executionContext
.
vm
().
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
},
function
(
err
,
result
)
{
if
(
useCall
)
{
executionContext
.
vm
().
stateManager
.
revert
(
function
()
{})
}
err
=
err
?
err
.
message
:
err
result
.
status
=
'0x'
+
result
.
vm
.
exception
.
toString
(
16
)
callback
(
err
,
{
result
:
result
,
transactionHash
:
ethJSUtil
.
bufferToHex
(
new
Buffer
(
tx
.
hash
()))
})
})
}
catch
(
e
)
{
callback
(
e
,
null
)
}
}
TxRunner
.
prototype
.
runInNode
=
function
(
from
,
to
,
data
,
value
,
gasLimit
,
useCall
,
callback
)
{
const
self
=
this
var
tx
=
{
from
:
from
,
from
:
from
,
to
:
to
,
to
:
to
,
data
:
data
,
data
:
data
,
value
:
value
value
:
value
}
}
if
(
args
.
useCall
)
{
if
(
useCall
)
{
tx
.
gas
=
gasLimit
tx
.
gas
=
gasLimit
executionContext
.
web3
().
eth
.
call
(
tx
,
function
(
error
,
result
)
{
executionContext
.
web3
().
eth
.
call
(
tx
,
function
(
error
,
result
)
{
callback
(
error
,
{
callback
(
error
,
{
...
@@ -119,7 +175,7 @@ TxRunner.prototype.execute = function (args, callback) {
...
@@ -119,7 +175,7 @@ TxRunner.prototype.execute = function (args, callback) {
callback
(
'Given gas grice is not correct'
)
callback
(
'Given gas grice is not correct'
)
}
else
{
}
else
{
var
gasPrice
=
executionContext
.
web3
().
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
var
gasPrice
=
executionContext
.
web3
().
toWei
(
content
.
querySelector
(
'#gasprice'
).
value
,
'gwei'
)
execute
(
gasPrice
)
executeTx
(
tx
,
gasPrice
,
self
.
_api
,
callback
)
}
}
}},
{
}},
{
label
:
'Cancel'
,
label
:
'Cancel'
,
...
@@ -128,64 +184,14 @@ TxRunner.prototype.execute = function (args, callback) {
...
@@ -128,64 +184,14 @@ TxRunner.prototype.execute = function (args, callback) {
}
}
})
})
}
else
{
}
else
{
execute
()
executeTx
(
tx
,
null
,
self
.
_api
,
callback
)
}
}
}
})
}
else
{
execute
()
}
})
}
}
else
{
try
{
var
account
=
self
.
vmaccounts
[
from
]
if
(
!
account
)
{
return
callback
(
'Invalid account selected'
)
}
}
tx
=
new
EthJSTX
({
nonce
:
new
BN
(
account
.
nonce
++
),
gasPrice
:
new
BN
(
1
),
gasLimit
:
new
BN
(
gasLimit
,
10
),
to
:
to
,
value
:
new
BN
(
value
,
10
),
data
:
new
Buffer
(
data
.
slice
(
2
),
'hex'
)
})
tx
.
sign
(
account
.
privateKey
)
const
coinbases
=
[
'0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a'
,
'0x8945a1288dc78a6d8952a92c77aee6730b414778'
,
'0x94d76e24f818426ae84aa404140e8d5f60e10e7e'
]
const
difficulties
=
[
new
BN
(
'69762765929000'
,
10
),
new
BN
(
'70762765929000'
,
10
),
new
BN
(
'71762765929000'
,
10
)
]
var
block
=
new
EthJSBlock
({
header
:
{
timestamp
:
new
Date
().
getTime
()
/
1000
|
0
,
number
:
self
.
blockNumber
,
coinbase
:
coinbases
[
self
.
blockNumber
%
coinbases
.
length
],
difficulty
:
difficulties
[
self
.
blockNumber
%
difficulties
.
length
],
gasLimit
:
new
BN
(
gasLimit
,
10
).
imuln
(
2
)
},
transactions
:
[],
uncleHeaders
:
[]
})
})
if
(
!
args
.
useCall
)
{
++
self
.
blockNumber
}
else
{
}
else
{
execut
ionContext
.
vm
().
stateManager
.
checkpoint
(
)
execut
eTx
(
tx
,
null
,
self
.
_api
,
callback
)
}
}
executionContext
.
vm
().
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
},
function
(
err
,
result
)
{
if
(
args
.
useCall
)
{
executionContext
.
vm
().
stateManager
.
revert
(
function
()
{})
}
err
=
err
?
err
.
message
:
err
result
.
status
=
'0x'
+
result
.
vm
.
exception
.
toString
(
16
)
callback
(
err
,
{
result
:
result
,
transactionHash
:
ethJSUtil
.
bufferToHex
(
new
Buffer
(
tx
.
hash
()))
})
})
})
}
catch
(
e
)
{
callback
(
e
,
null
)
}
}
}
}
}
...
...
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