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
72619b99
Commit
72619b99
authored
Aug 02, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get web3VMProvider out of txlistener
parent
7830b342
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
51 deletions
+63
-51
app.js
src/app.js
+49
-12
eventsDecoder.js
src/app/eventsDecoder.js
+10
-14
txListener.js
src/app/txListener.js
+4
-25
No files found.
src/app.js
View file @
72619b99
...
...
@@ -7,7 +7,8 @@ var base64 = require('js-base64').Base64
var
swarmgw
=
require
(
'swarmgw'
)
var
csjs
=
require
(
'csjs-inject'
)
var
yo
=
require
(
'yo-yo'
)
var
EventManager
=
require
(
'ethereum-remix'
).
lib
.
EventManager
var
remix
=
require
(
'ethereum-remix'
)
var
EventManager
=
remix
.
lib
.
EventManager
var
UniversalDApp
=
require
(
'./universal-dapp.js'
)
var
Remixd
=
require
(
'./lib/remixd'
)
...
...
@@ -30,10 +31,9 @@ var EditorPanel = require('./app/editor-panel')
var
RighthandPanel
=
require
(
'./app/righthand-panel'
)
var
examples
=
require
(
'./app/example-contracts'
)
var
modalDialogCustom
=
require
(
'./app/modal-dialog-custom'
)
/*
var
Txlistener
=
require
(
'./app/txListener'
)
var
EventsDecoder
=
require
(
'./app/eventsDecoder'
)
*/
var
Web3VMProvider
=
remix
.
web3
.
web3VMProvider
var
css
=
csjs
`
html { box-sizing: border-box; }
...
...
@@ -752,7 +752,32 @@ function run () {
// ----------------- Tx listener -----------------
// not used right now
/*
// TODO the following should be put in execution context
var
web3VM
=
new
Web3VMProvider
()
web3VM
.
setVM
(
executionContext
.
vm
())
var
currentWeb3
=
function
()
{
return
executionContext
.
isVM
()
?
web3VM
:
executionContext
.
web3
()
}
var
transactionReceiptResolver
=
{
_transactionReceipts
:
{},
resolve
:
function
(
tx
,
cb
)
{
if
(
this
.
_transactionReceipts
[
tx
.
hash
])
{
return
cb
(
null
,
this
.
_transactionReceipts
[
tx
.
hash
])
}
currentWeb3
().
eth
.
getTransactionReceipt
(
tx
.
hash
,
(
error
,
receipt
)
=>
{
if
(
!
error
)
{
this
.
_transactionReceipts
[
tx
.
hash
]
=
receipt
cb
(
null
,
receipt
)
}
else
{
cb
(
error
)
}
})
}
}
var
compiledContracts
=
function
()
{
if
(
compiler
.
lastCompilationResult
&&
compiler
.
lastCompilationResult
.
data
)
{
return
compiler
.
lastCompilationResult
.
data
.
contracts
...
...
@@ -762,22 +787,29 @@ function run () {
var
txlistener
=
new
Txlistener
({
api
:
{
web3: function () { return
executionContext.w
eb3() },
web3
:
function
()
{
return
currentW
eb3
()
},
isVM
:
function
()
{
return
executionContext
.
isVM
()
},
vm: function () { return executionContext.vm() },
contracts
:
compiledContracts
,
context
:
function
()
{
return
executionContext
.
getProvider
()
},
resolveReceipt
:
function
(
tx
,
cb
)
{
transactionReceiptResolver
.
resolve
(
tx
,
cb
)
}
},
event
:
{
executionContext
:
executionContext
.
event
,
udapp
:
udapp
.
event
}})
var
eventsDecoder
=
new
EventsDecoder
({
api
:
{
resolveReceipt
:
function
(
tx
,
cb
)
{
transactionReceiptResolver
.
resolve
(
tx
,
cb
)
}
}
})
var eventsDecoder = new EventsDecoder({ txListener: txlistener })
txlistener
.
startListening
()
txlistener
.
event
.
register
(
'newTransaction'
,
(
tx
)
=>
{
...
...
@@ -788,22 +820,27 @@ function run () {
address
=
resolvedTransaction
.
contractAddress
?
resolvedTransaction
.
contractAddress
:
tx
.
to
resolvedContract
=
txlistener
.
resolvedContract
(
address
)
if
(
resolvedContract
)
{
eventsDecoder.parseLogs(tx, resolvedContract, compiledContracts(), () => {
eventsDecoder
.
parseLogs
(
tx
,
resolvedContract
,
compiledContracts
(),
(
error
,
log
)
=>
{
console
.
log
({
tx
:
tx
,
resolvedContract: resolvedContract,
resolvedTransaction
:
resolvedTransaction
,
resolvedEvents: eventsDecoder.eventsOf(tx.hash)
resolvedContract
:
resolvedContract
,
resolvedEvents
:
(
!
error
?
log
:
error
)
})
})
}
else
{
console
.
log
({
tx
:
tx
,
resolvedTransaction
:
resolvedTransaction
})
}
}
else
{
// contract unknown - just displaying raw tx.
console
.
log
({
tx
:
tx
})
}
})
*/
// ----------------- autoCompile -----------------
var
autoCompile
=
document
.
querySelector
(
'#autoCompile'
).
checked
...
...
src/app/eventsDecoder.js
View file @
72619b99
...
...
@@ -8,8 +8,7 @@ var ethJSABI = require('ethereumjs-abi')
*/
class
EventsDecoder
{
constructor
(
opt
=
{})
{
this
.
txListener
=
opt
.
txListener
this
.
resolvedEvents
=
{}
this
.
_api
=
opt
.
api
}
/**
...
...
@@ -20,19 +19,18 @@ class EventsDecoder {
* @param {Function} cb - callback
*/
parseLogs
(
tx
,
contractName
,
compiledContracts
,
cb
)
{
this
.
txListener
.
resolveTransaction
Receipt
(
tx
,
(
error
,
receipt
)
=>
{
this
.
_api
.
resolve
Receipt
(
tx
,
(
error
,
receipt
)
=>
{
if
(
error
)
cb
(
error
)
this
.
_decodeLogs
(
tx
,
receipt
,
contractName
,
compiledContracts
,
cb
)
})
}
eventsOf
(
hash
)
{
return
this
.
resolvedEvents
[
hash
]
}
_decodeLogs
(
tx
,
receipt
,
contract
,
contracts
,
cb
)
{
if
(
!
contract
||
!
receipt
.
logs
)
{
return
cb
()
if
(
!
contract
||
!
receipt
)
{
return
cb
(
'cannot decode logs - contract or receipt not resolved '
)
}
if
(
!
receipt
.
logs
)
{
return
cb
(
null
,
[])
}
this
.
_decodeEvents
(
tx
,
receipt
.
logs
,
contract
,
contracts
,
cb
)
}
...
...
@@ -53,6 +51,7 @@ class EventsDecoder {
_decodeEvents
(
tx
,
logs
,
contractName
,
compiledContracts
,
cb
)
{
var
eventABI
=
this
.
_eventABI
(
contractName
,
compiledContracts
)
// FIXME: support indexed events
var
events
=
[]
for
(
var
i
in
logs
)
{
// [address, topics, mem]
var
log
=
logs
[
i
]
...
...
@@ -70,12 +69,9 @@ class EventsDecoder {
}
catch
(
e
)
{
decoded
=
log
.
data
}
if
(
!
this
.
resolvedEvents
[
tx
.
hash
])
{
this
.
resolvedEvents
[
tx
.
hash
]
=
[]
}
this
.
resolvedEvents
[
tx
.
hash
].
push
({
event
:
event
,
args
:
decoded
})
events
.
push
({
event
:
event
,
args
:
decoded
})
}
cb
()
cb
(
null
,
events
)
}
}
...
...
src/app/txListener.js
View file @
72619b99
...
...
@@ -5,7 +5,6 @@ var ethJSUtil = require('ethereumjs-util')
var
EventManager
=
require
(
'ethereum-remix'
).
lib
.
EventManager
var
remix
=
require
(
'ethereum-remix'
)
var
codeUtil
=
remix
.
util
.
code
var
Web3VMProvider
=
remix
.
web3
.
web3VMProvider
/**
* poll web3 each 2s if web3
...
...
@@ -18,11 +17,8 @@ class TxListener {
constructor
(
opt
)
{
this
.
event
=
new
EventManager
()
this
.
_api
=
opt
.
api
this
.
_web3VMProvider
=
new
Web3VMProvider
()
// TODO this should maybe be put in app.js
this
.
_web3VMProvider
.
setVM
(
opt
.
api
.
vm
())
this
.
_resolvedTransactions
=
{}
this
.
_resolvedContracts
=
{}
this
.
_transactionReceipts
=
{}
this
.
init
()
opt
.
event
.
executionContext
.
register
(
'contextChanged'
,
(
context
)
=>
{
if
(
this
.
loopId
)
{
...
...
@@ -31,7 +27,7 @@ class TxListener {
})
opt
.
event
.
udapp
.
register
(
'transactionExecuted'
,
(
to
,
data
,
lookupOnly
,
txResult
)
=>
{
if
(
this
.
loopId
&&
this
.
_api
.
isVM
())
{
this
.
_
web3VMProvider
.
getTransaction
(
txResult
.
transactionHash
,
(
error
,
tx
)
=>
{
this
.
_
api
.
web3
().
eth
.
getTransaction
(
txResult
.
transactionHash
,
(
error
,
tx
)
=>
{
if
(
error
)
return
console
.
log
(
error
)
this
.
_newBlock
({
type
:
'VM'
,
...
...
@@ -65,6 +61,7 @@ class TxListener {
}
else
{
this
.
loopId
=
setInterval
(()
=>
{
this
.
_api
.
web3
().
eth
.
getBlockNumber
((
error
,
blockNumber
)
=>
{
if
(
this
.
loopId
===
null
||
this
.
loopId
===
'vm-listener'
)
return
if
(
error
)
return
console
.
log
(
error
)
if
(
!
this
.
lastBlock
||
blockNumber
>
this
.
lastBlock
)
{
this
.
lastBlock
=
blockNumber
...
...
@@ -79,10 +76,6 @@ class TxListener {
}
}
currentWeb3
()
{
// TODO this should maybe be put in app.js
return
this
.
_api
.
isVM
()
?
this
.
_web3VMProvider
:
this
.
_api
.
web3
()
}
/**
* stop listening for incoming transactions. do not reset the recorded pool.
*
...
...
@@ -147,7 +140,7 @@ class TxListener {
var
code
=
tx
.
input
contractName
=
this
.
_tryResolveContract
(
code
,
contracts
,
'bytecode'
)
if
(
contractName
)
{
this
.
resolveTransaction
Receipt
(
tx
,
(
error
,
receipt
)
=>
{
this
.
_api
.
resolve
Receipt
(
tx
,
(
error
,
receipt
)
=>
{
if
(
error
)
return
cb
(
error
)
var
address
=
receipt
.
contractAddress
this
.
_resolvedContracts
[
address
]
=
contractName
...
...
@@ -164,7 +157,7 @@ class TxListener {
// first check known contract, resolve against the `runtimeBytecode` if not known
contractName
=
this
.
_resolvedContracts
[
tx
.
to
]
if
(
!
contractName
)
{
this
.
currentW
eb3
().
eth
.
getCode
(
tx
.
to
,
(
error
,
code
)
=>
{
this
.
_api
.
w
eb3
().
eth
.
getCode
(
tx
.
to
,
(
error
,
code
)
=>
{
if
(
error
)
return
cb
(
error
)
if
(
code
)
{
var
contractName
=
this
.
_tryResolveContract
(
code
,
contracts
,
'runtimeBytecode'
)
...
...
@@ -186,20 +179,6 @@ class TxListener {
}
}
resolveTransactionReceipt
(
tx
,
cb
)
{
if
(
this
.
_transactionReceipts
[
tx
.
hash
])
{
return
cb
(
null
,
this
.
_transactionReceipts
[
tx
.
hash
])
}
this
.
currentWeb3
().
eth
.
getTransactionReceipt
(
tx
.
hash
,
(
error
,
receipt
)
=>
{
if
(
!
error
)
{
this
.
_transactionReceipts
[
tx
.
hash
]
=
receipt
cb
(
null
,
receipt
)
}
else
{
cb
(
error
)
}
})
}
_resolveFunction
(
contractName
,
compiledContracts
,
tx
,
isCtor
)
{
var
abi
=
JSON
.
parse
(
compiledContracts
[
contractName
].
interface
)
var
inputData
=
tx
.
input
.
replace
(
'0x'
,
''
)
...
...
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