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
0d5765b4
Commit
0d5765b4
authored
Dec 26, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor out of the recorder executioncontext and udapp
parent
a3946e67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
34 deletions
+52
-34
blockchain.js
src/app/tabs/runTab/model/blockchain.js
+25
-0
recorder.js
src/app/tabs/runTab/model/recorder.js
+26
-33
run-tab.js
src/app/udapp/run-tab.js
+1
-1
No files found.
src/app/tabs/runTab/model/blockchain.js
View file @
0d5765b4
...
@@ -2,13 +2,30 @@ const remixLib = require('remix-lib')
...
@@ -2,13 +2,30 @@ const remixLib = require('remix-lib')
const
txFormat
=
remixLib
.
execution
.
txFormat
const
txFormat
=
remixLib
.
execution
.
txFormat
const
txExecution
=
remixLib
.
execution
.
txExecution
const
txExecution
=
remixLib
.
execution
.
txExecution
const
typeConversion
=
remixLib
.
execution
.
typeConversion
const
typeConversion
=
remixLib
.
execution
.
typeConversion
const
EventManager
=
remixLib
.
EventManager
const
Web3
=
require
(
'web3'
)
const
Web3
=
require
(
'web3'
)
class
Blockchain
{
class
Blockchain
{
constructor
(
executionContext
,
udapp
)
{
constructor
(
executionContext
,
udapp
)
{
this
.
event
=
new
EventManager
()
this
.
executionContext
=
executionContext
this
.
executionContext
=
executionContext
this
.
udapp
=
udapp
this
.
udapp
=
udapp
this
.
setupEvents
()
}
setupEvents
()
{
this
.
executionContext
.
event
.
register
(
'contextChanged'
,
()
=>
{
this
.
event
.
trigger
(
'contextChanged'
,
[])
})
this
.
udapp
.
event
.
register
(
'initiatingTransaction'
,
()
=>
{
this
.
event
.
trigger
(
'initiatingTransaction'
,
[])
})
this
.
udapp
.
event
.
register
(
'transactionExecuted'
,
()
=>
{
this
.
event
.
trigger
(
'transactionExecuted'
,
[])
})
}
}
async
deployContract
(
selectedContract
,
args
,
contractMetadata
,
compilerContracts
,
callbacks
,
confirmationCb
)
{
async
deployContract
(
selectedContract
,
args
,
contractMetadata
,
compilerContracts
,
callbacks
,
confirmationCb
)
{
...
@@ -120,6 +137,14 @@ class Blockchain {
...
@@ -120,6 +137,14 @@ class Blockchain {
return
determineGasFeesCb
return
determineGasFeesCb
}
}
getAddressFromTransactionResult
(
txResult
)
{
return
this
.
executionContext
.
isVM
()
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
}
getAccounts
(
cb
)
{
return
this
.
udapp
.
getAccounts
(
cb
)
}
}
}
module
.
exports
=
Blockchain
module
.
exports
=
Blockchain
src/app/tabs/runTab/model/recorder.js
View file @
0d5765b4
...
@@ -12,16 +12,15 @@ var helper = require('../../../../lib/helper.js')
...
@@ -12,16 +12,15 @@ var helper = require('../../../../lib/helper.js')
*
*
*/
*/
class
Recorder
{
class
Recorder
{
constructor
(
executionContext
,
udapp
,
fileManager
,
config
)
{
constructor
(
blockchain
,
fileManager
,
config
)
{
var
self
=
this
var
self
=
this
self
.
event
=
new
EventManager
()
self
.
event
=
new
EventManager
()
self
.
executionContext
=
executionContext
self
.
blockchain
=
blockchain
self
.
data
=
{
_listen
:
true
,
_replay
:
false
,
journal
:
[],
_createdContracts
:
{},
_createdContractsReverse
:
{},
_usedAccounts
:
{},
_abis
:
{},
_contractABIReferences
:
{},
_linkReferences
:
{}
}
self
.
data
=
{
_listen
:
true
,
_replay
:
false
,
journal
:
[],
_createdContracts
:
{},
_createdContractsReverse
:
{},
_usedAccounts
:
{},
_abis
:
{},
_contractABIReferences
:
{},
_linkReferences
:
{}
}
this
.
udapp
=
udapp
this
.
fileManager
=
fileManager
this
.
fileManager
=
fileManager
this
.
config
=
config
this
.
config
=
config
this
.
udapp
.
event
.
register
(
'initiatingTransaction'
,
(
timestamp
,
tx
,
payLoad
)
=>
{
this
.
blockchain
.
event
.
register
(
'initiatingTransaction'
,
(
timestamp
,
tx
,
payLoad
)
=>
{
if
(
tx
.
useCall
)
return
if
(
tx
.
useCall
)
return
var
{
from
,
to
,
value
}
=
tx
var
{
from
,
to
,
value
}
=
tx
...
@@ -59,7 +58,7 @@ class Recorder {
...
@@ -59,7 +58,7 @@ class Recorder {
if
(
thistimestamp
)
record
.
parameters
[
p
]
=
`created{
${
thistimestamp
}
}`
if
(
thistimestamp
)
record
.
parameters
[
p
]
=
`created{
${
thistimestamp
}
}`
}
}
this
.
udapp
.
getAccounts
((
error
,
accounts
)
=>
{
this
.
blockchain
.
getAccounts
((
error
,
accounts
)
=>
{
if
(
error
)
return
console
.
log
(
error
)
if
(
error
)
return
console
.
log
(
error
)
record
.
from
=
`account{
${
accounts
.
indexOf
(
from
)}
}`
record
.
from
=
`account{
${
accounts
.
indexOf
(
from
)}
}`
self
.
data
.
_usedAccounts
[
record
.
from
]
=
from
self
.
data
.
_usedAccounts
[
record
.
from
]
=
from
...
@@ -68,11 +67,11 @@ class Recorder {
...
@@ -68,11 +67,11 @@ class Recorder {
}
}
})
})
this
.
udapp
.
event
.
register
(
'transactionExecuted'
,
(
error
,
from
,
to
,
data
,
call
,
txResult
,
timestamp
)
=>
{
this
.
blockchain
.
event
.
register
(
'transactionExecuted'
,
(
error
,
from
,
to
,
data
,
call
,
txResult
,
timestamp
)
=>
{
if
(
error
)
return
console
.
log
(
error
)
if
(
error
)
return
console
.
log
(
error
)
if
(
call
)
return
if
(
call
)
return
const
rawAddress
=
this
.
executionContext
.
isVM
()
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
const
rawAddress
=
this
.
blockchain
.
getAddressFromTransactionResult
(
txResult
)
if
(
!
rawAddress
)
return
// not a contract creation
if
(
!
rawAddress
)
return
// not a contract creation
const
stringAddress
=
this
.
addressToString
(
rawAddress
)
const
stringAddress
=
this
.
addressToString
(
rawAddress
)
const
address
=
ethutil
.
toChecksumAddress
(
stringAddress
)
const
address
=
ethutil
.
toChecksumAddress
(
stringAddress
)
...
@@ -80,7 +79,7 @@ class Recorder {
...
@@ -80,7 +79,7 @@ class Recorder {
this
.
data
.
_createdContracts
[
address
]
=
timestamp
this
.
data
.
_createdContracts
[
address
]
=
timestamp
this
.
data
.
_createdContractsReverse
[
timestamp
]
=
address
this
.
data
.
_createdContractsReverse
[
timestamp
]
=
address
})
})
this
.
executionContext
.
event
.
register
(
'contextChanged'
,
this
.
clearAll
.
bind
(
this
))
this
.
blockchain
.
event
.
register
(
'contextChanged'
,
this
.
clearAll
.
bind
(
this
))
this
.
event
.
register
(
'newTxRecorded'
,
(
count
)
=>
{
this
.
event
.
register
(
'newTxRecorded'
,
(
count
)
=>
{
this
.
event
.
trigger
(
'recorderCountChange'
,
[
count
])
this
.
event
.
trigger
(
'recorderCountChange'
,
[
count
])
})
})
...
@@ -183,7 +182,6 @@ class Recorder {
...
@@ -183,7 +182,6 @@ class Recorder {
* @param {Object} accounts
* @param {Object} accounts
* @param {Object} options
* @param {Object} options
* @param {Object} abis
* @param {Object} abis
* @param {Object} udapp
* @param {Function} newContractFn
* @param {Function} newContractFn
*
*
*/
*/
...
@@ -195,8 +193,7 @@ class Recorder {
...
@@ -195,8 +193,7 @@ class Recorder {
var
record
=
self
.
resolveAddress
(
tx
.
record
,
accounts
,
options
)
var
record
=
self
.
resolveAddress
(
tx
.
record
,
accounts
,
options
)
var
abi
=
abis
[
tx
.
record
.
abi
]
var
abi
=
abis
[
tx
.
record
.
abi
]
if
(
!
abi
)
{
if
(
!
abi
)
{
alertCb
(
'cannot find ABI for '
+
tx
.
record
.
abi
+
'. Execution stopped at '
+
index
)
return
alertCb
(
'cannot find ABI for '
+
tx
.
record
.
abi
+
'. Execution stopped at '
+
index
)
return
}
}
/* Resolve Library */
/* Resolve Library */
if
(
record
.
linkReferences
&&
Object
.
keys
(
record
.
linkReferences
).
length
)
{
if
(
record
.
linkReferences
&&
Object
.
keys
(
record
.
linkReferences
).
length
)
{
...
@@ -220,8 +217,7 @@ class Recorder {
...
@@ -220,8 +217,7 @@ class Recorder {
}
}
if
(
!
fnABI
)
{
if
(
!
fnABI
)
{
alertCb
(
'cannot resolve abi of '
+
JSON
.
stringify
(
record
,
null
,
'
\
t'
)
+
'. Execution stopped at '
+
index
)
alertCb
(
'cannot resolve abi of '
+
JSON
.
stringify
(
record
,
null
,
'
\
t'
)
+
'. Execution stopped at '
+
index
)
cb
(
'cannot resolve abi'
)
return
cb
(
'cannot resolve abi'
)
return
}
}
if
(
tx
.
record
.
parameters
)
{
if
(
tx
.
record
.
parameters
)
{
/* check if we have some params to resolve */
/* check if we have some params to resolve */
...
@@ -239,35 +235,32 @@ class Recorder {
...
@@ -239,35 +235,32 @@ class Recorder {
tx
.
record
.
parameters
[
index
]
=
value
tx
.
record
.
parameters
[
index
]
=
value
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
alertCb
(
'cannot resolve input parameters '
+
JSON
.
stringify
(
tx
.
record
.
parameters
)
+
'. Execution stopped at '
+
index
)
return
alertCb
(
'cannot resolve input parameters '
+
JSON
.
stringify
(
tx
.
record
.
parameters
)
+
'. Execution stopped at '
+
index
)
return
}
}
}
}
var
data
=
format
.
encodeData
(
fnABI
,
tx
.
record
.
parameters
,
tx
.
record
.
bytecode
)
var
data
=
format
.
encodeData
(
fnABI
,
tx
.
record
.
parameters
,
tx
.
record
.
bytecode
)
if
(
data
.
error
)
{
if
(
data
.
error
)
{
alertCb
(
data
.
error
+
'. Record:'
+
JSON
.
stringify
(
record
,
null
,
'
\
t'
)
+
'. Execution stopped at '
+
index
)
alertCb
(
data
.
error
+
'. Record:'
+
JSON
.
stringify
(
record
,
null
,
'
\
t'
)
+
'. Execution stopped at '
+
index
)
cb
(
data
.
error
)
return
cb
(
data
.
error
)
return
}
else
{
logCallBack
(
`(
${
index
}
)
${
JSON
.
stringify
(
record
,
null
,
'
\
t'
)}
`
)
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
.
udapp
.
runTx
(
record
,
confirmationCb
,
continueCb
,
promptCb
,
logCallBack
(
`(
${
index
}
)
${
JSON
.
stringify
(
record
,
null
,
'
\
t'
)}
`
)
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
.
runTransaction
(
record
,
continueCb
,
promptCb
,
confirmationCb
,
function
(
err
,
txResult
)
{
function
(
err
,
txResult
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
err
)
console
.
error
(
err
)
logCallBack
(
err
+
'. Execution failed at '
+
index
)
return
logCallBack
(
err
+
'. Execution failed at '
+
index
)
}
else
{
}
const
rawAddress
=
self
.
executionContext
.
isVM
()
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
const
rawAddress
=
self
.
blockchain
.
getAddressFromTransactionResult
(
txResult
)
if
(
rawAddress
)
{
if
(
rawAddress
)
{
const
stringAddress
=
self
.
addressToString
(
rawAddress
)
const
stringAddress
=
self
.
addressToString
(
rawAddress
)
const
address
=
ethutil
.
toChecksumAddress
(
stringAddress
)
const
address
=
ethutil
.
toChecksumAddress
(
stringAddress
)
// save back created addresses for the convertion from tokens to real adresses
// save back created addresses for the convertion from tokens to real adresses
self
.
data
.
_createdContracts
[
address
]
=
tx
.
timestamp
self
.
data
.
_createdContracts
[
address
]
=
tx
.
timestamp
self
.
data
.
_createdContractsReverse
[
tx
.
timestamp
]
=
address
self
.
data
.
_createdContractsReverse
[
tx
.
timestamp
]
=
address
newContractFn
(
abi
,
address
,
record
.
contractName
)
newContractFn
(
abi
,
address
,
record
.
contractName
)
}
}
}
cb
(
err
)
cb
(
err
)
}
}
...
...
src/app/udapp/run-tab.js
View file @
0d5765b4
...
@@ -153,7 +153,7 @@ export class RunTab extends LibraryPlugin {
...
@@ -153,7 +153,7 @@ export class RunTab extends LibraryPlugin {
renderRecorder
(
udapp
,
udappUI
,
fileManager
,
config
,
logCallback
)
{
renderRecorder
(
udapp
,
udappUI
,
fileManager
,
config
,
logCallback
)
{
this
.
recorderCount
=
yo
`<span>0</span>`
this
.
recorderCount
=
yo
`<span>0</span>`
const
recorder
=
new
Recorder
(
this
.
executionContext
,
udapp
,
fileManager
,
config
)
const
recorder
=
new
Recorder
(
this
.
blockchain
,
fileManager
,
config
)
recorder
.
event
.
register
(
'recorderCountChange'
,
(
count
)
=>
{
recorder
.
event
.
register
(
'recorderCountChange'
,
(
count
)
=>
{
this
.
recorderCount
.
innerText
=
count
this
.
recorderCount
.
innerText
=
count
})
})
...
...
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