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
b108fbbd
Commit
b108fbbd
authored
Sep 07, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
txlistener use the transactionExecuted event in case if : using web3 provider…
txlistener use the transactionExecuted event in case if : using web3 provider but not lsitening on network
parent
6bbdb4ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
50 deletions
+72
-50
txListener.js
src/app/execution/txListener.js
+72
-50
No files found.
src/app/execution/txListener.js
View file @
b108fbbd
...
@@ -20,28 +20,47 @@ class TxListener {
...
@@ -20,28 +20,47 @@ class TxListener {
this
.
_api
=
opt
.
api
this
.
_api
=
opt
.
api
this
.
_resolvedTransactions
=
{}
this
.
_resolvedTransactions
=
{}
this
.
_resolvedContracts
=
{}
this
.
_resolvedContracts
=
{}
this
.
_isListening
=
false
this
.
_listenOnNetwork
=
false
this
.
_loopId
=
null
this
.
init
()
this
.
init
()
executionContext
.
event
.
register
(
'contextChanged'
,
(
context
)
=>
{
executionContext
.
event
.
register
(
'contextChanged'
,
(
context
)
=>
{
if
(
this
.
loopId
)
{
if
(
this
.
_isListening
)
{
this
.
startListening
(
context
)
this
.
stopListening
()
this
.
startListening
()
}
}
})
})
opt
.
event
.
udapp
.
register
(
'transactionExecuted'
,
(
error
,
to
,
data
,
lookupOnly
,
txResult
)
=>
{
opt
.
event
.
udapp
.
register
(
'transactionExecuted'
,
(
error
,
to
,
data
,
lookupOnly
,
txResult
)
=>
{
if
(
error
)
return
if
(
error
)
return
if
(
this
.
loopId
&&
executionContext
.
isVM
())
{
// we go for that case if
executionContext
.
web3
().
eth
.
getTransaction
(
txResult
.
transactionHash
,
(
error
,
tx
)
=>
{
// in VM mode
if
(
error
)
return
console
.
log
(
error
)
// in web3 mode && listen remix txs only
this
.
_newBlock
({
if
(
!
this
.
_isListening
)
return
// we don't listen
type
:
'VM'
,
if
(
this
.
_loopId
)
return
// we seems to already listen on the network
number
:
-
1
,
executionContext
.
web3
().
eth
.
getTransaction
(
txResult
.
transactionHash
,
(
error
,
tx
)
=>
{
transactions
:
[
tx
]
if
(
error
)
return
console
.
log
(
error
)
})
this
.
_resolve
([
tx
],
()
=>
{
})
})
}
}
)
})
})
}
}
/**
/**
* define if txlistener should listen on the network or if only tx created from remix are managed
*
* @param {Bool} type - true if listen on the network
*/
setListenOnNetwork
(
listenOnNetwork
)
{
this
.
_listenOnNetwork
=
listenOnNetwork
if
(
this
.
_loopId
)
{
clearInterval
(
this
.
_loopId
)
}
if
(
this
.
_listenOnNetwork
)
{
this
.
_startListenOnNetwork
()
}
}
/**
* reset recorded transactions
* reset recorded transactions
*/
*/
init
()
{
init
()
{
...
@@ -56,53 +75,56 @@ class TxListener {
...
@@ -56,53 +75,56 @@ class TxListener {
* @param {Object} obj - provider
* @param {Object} obj - provider
*/
*/
startListening
()
{
startListening
()
{
this
.
stopListening
()
this
.
init
()
this
.
init
()
if
(
executionContext
.
getProvider
()
===
'vm'
)
{
this
.
_isListening
=
true
this
.
loopId
=
'vm-listener'
if
(
this
.
_listenOnNetwork
)
{
}
else
{
this
.
_startListenOnNetwork
()
this
.
loopId
=
setInterval
(()
=>
{
var
currentLoopId
=
this
.
loopId
executionContext
.
web3
().
eth
.
getBlockNumber
((
error
,
blockNumber
)
=>
{
if
(
this
.
loopId
===
null
||
this
.
loopId
===
'vm-listener'
)
return
if
(
error
)
return
console
.
log
(
error
)
if
(
currentLoopId
===
this
.
loopId
&&
(
!
this
.
lastBlock
||
blockNumber
>
this
.
lastBlock
))
{
if
(
!
this
.
lastBlock
)
this
.
lastBlock
=
blockNumber
-
1
var
current
=
this
.
lastBlock
+
1
this
.
lastBlock
=
blockNumber
while
(
blockNumber
>=
current
)
{
try
{
this
.
_manageBlock
(
current
)
}
catch
(
e
)
{
console
.
log
(
e
)
}
current
++
}
}
})
},
2000
)
}
}
}
}
_manageBlock
(
blockNumber
)
{
/**
executionContext
.
web3
().
eth
.
getBlock
(
blockNumber
,
true
,
(
error
,
result
)
=>
{
if
(
!
error
)
{
this
.
_newBlock
(
Object
.
assign
({
type
:
'web3'
},
result
))
}
})
}
/**
* stop listening for incoming transactions. do not reset the recorded pool.
* stop listening for incoming transactions. do not reset the recorded pool.
*
*
* @param {String} type - type/name of the provider to add
* @param {String} type - type/name of the provider to add
* @param {Object} obj - provider
* @param {Object} obj - provider
*/
*/
stopListening
()
{
stopListening
()
{
if
(
this
.
loopId
)
{
if
(
this
.
_
loopId
)
{
clearInterval
(
this
.
loopId
)
clearInterval
(
this
.
_
loopId
)
}
}
this
.
loopId
=
null
this
.
_loopId
=
null
this
.
_isListening
=
false
}
_startListenOnNetwork
()
{
this
.
_loopId
=
setInterval
(()
=>
{
var
currentLoopId
=
this
.
_loopId
executionContext
.
web3
().
eth
.
getBlockNumber
((
error
,
blockNumber
)
=>
{
if
(
this
.
_loopId
===
null
)
return
if
(
error
)
return
console
.
log
(
error
)
if
(
currentLoopId
===
this
.
_loopId
&&
(
!
this
.
lastBlock
||
blockNumber
>
this
.
lastBlock
))
{
if
(
!
this
.
lastBlock
)
this
.
lastBlock
=
blockNumber
-
1
var
current
=
this
.
lastBlock
+
1
this
.
lastBlock
=
blockNumber
while
(
blockNumber
>=
current
)
{
try
{
this
.
_manageBlock
(
current
)
}
catch
(
e
)
{
console
.
log
(
e
)
}
current
++
}
}
})
},
2000
)
}
_manageBlock
(
blockNumber
)
{
executionContext
.
web3
().
eth
.
getBlock
(
blockNumber
,
true
,
(
error
,
result
)
=>
{
if
(
!
error
)
{
this
.
_newBlock
(
Object
.
assign
({
type
:
'web3'
},
result
))
}
})
}
}
/**
/**
...
@@ -127,13 +149,13 @@ class TxListener {
...
@@ -127,13 +149,13 @@ class TxListener {
_newBlock
(
block
)
{
_newBlock
(
block
)
{
this
.
blocks
.
push
(
block
)
this
.
blocks
.
push
(
block
)
this
.
_resolve
(
block
,
()
=>
{
this
.
_resolve
(
block
.
transactions
,
()
=>
{
this
.
event
.
trigger
(
'newBlock'
,
[
block
])
this
.
event
.
trigger
(
'newBlock'
,
[
block
])
})
})
}
}
_resolve
(
block
,
callback
)
{
_resolve
(
transactions
,
callback
)
{
async
.
each
(
block
.
transactions
,
(
tx
,
cb
)
=>
{
async
.
each
(
transactions
,
(
tx
,
cb
)
=>
{
this
.
_resolveTx
(
tx
,
(
error
,
resolvedData
)
=>
{
this
.
_resolveTx
(
tx
,
(
error
,
resolvedData
)
=>
{
if
(
error
)
cb
(
error
)
if
(
error
)
cb
(
error
)
if
(
resolvedData
)
this
.
event
.
trigger
(
'txResolved'
,
[
tx
,
resolvedData
])
if
(
resolvedData
)
this
.
event
.
trigger
(
'txResolved'
,
[
tx
,
resolvedData
])
...
...
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