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
572dbb0e
Commit
572dbb0e
authored
Aug 22, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix subscription data/topics; get old logs
parent
517f6db8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
32 deletions
+61
-32
logsManager.js
remix-lib/src/execution/logsManager.js
+51
-25
filters.js
remix-simulator/src/methods/filters.js
+5
-4
provider.js
remix-simulator/src/provider.js
+5
-3
No files found.
remix-lib/src/execution/logsManager.js
View file @
572dbb0e
...
@@ -6,6 +6,7 @@ class LogsManager {
...
@@ -6,6 +6,7 @@ class LogsManager {
constructor
()
{
constructor
()
{
this
.
notificationCallbacks
=
[]
this
.
notificationCallbacks
=
[]
this
.
subscriptions
=
{}
this
.
subscriptions
=
{}
this
.
oldLogs
=
[]
}
}
checkBlock
(
blockNumber
,
block
,
web3
)
{
checkBlock
(
blockNumber
,
block
,
web3
)
{
...
@@ -14,6 +15,7 @@ class LogsManager {
...
@@ -14,6 +15,7 @@ class LogsManager {
web3
.
eth
.
getTransactionReceipt
(
txHash
,
(
_error
,
receipt
)
=>
{
web3
.
eth
.
getTransactionReceipt
(
txHash
,
(
_error
,
receipt
)
=>
{
for
(
let
log
of
receipt
.
logs
)
{
for
(
let
log
of
receipt
.
logs
)
{
this
.
oldLogs
.
push
({
type
:
'block'
,
blockNumber
,
block
,
tx
,
log
,
txNumber
:
i
})
let
subscriptions
=
this
.
getSubscriptionsFor
({
type
:
'block'
,
blockNumber
,
block
,
tx
,
log
})
let
subscriptions
=
this
.
getSubscriptionsFor
({
type
:
'block'
,
blockNumber
,
block
,
tx
,
log
})
for
(
let
subscriptionId
of
subscriptions
)
{
for
(
let
subscriptionId
of
subscriptions
)
{
...
@@ -42,6 +44,25 @@ class LogsManager {
...
@@ -42,6 +44,25 @@ class LogsManager {
});
});
}
}
eventMatchesFilter
(
changeEvent
,
queryType
,
queryFilter
)
{
console
.
dir
(
"--> matching topics"
)
if
(
queryFilter
.
topics
.
filter
((
logTopic
)
=>
changeEvent
.
log
.
topics
.
indexOf
(
logTopic
)
>=
0
).
length
===
0
)
return
false
console
.
dir
(
"topic matched"
)
if
(
queryType
===
'logs'
)
{
if
((
queryFilter
.
address
===
(
"0x"
+
changeEvent
.
tx
.
to
.
toString
(
'hex'
)))
&&
(
queryFilter
.
address
===
(
'0x'
+
changeEvent
.
tx
.
from
.
toString
(
'hex'
))))
{
if
(
!
queryFilter
.
toBlock
)
{
return
true
;
}
else
if
(
parseInt
(
queryFilter
.
toBlock
)
>
parseInt
(
changeEvent
.
blockNumber
))
{
return
true
;
}
}
}
return
false
;
}
// TODO:
// TODO:
// * need to get address of deployed contract if it's a tx that create a contract
// * need to get address of deployed contract if it's a tx that create a contract
getSubscriptionsFor
(
changeEvent
)
{
getSubscriptionsFor
(
changeEvent
)
{
...
@@ -49,21 +70,9 @@ class LogsManager {
...
@@ -49,21 +70,9 @@ class LogsManager {
for
(
let
subscriptionId
of
Object
.
keys
(
this
.
subscriptions
))
{
for
(
let
subscriptionId
of
Object
.
keys
(
this
.
subscriptions
))
{
const
subscriptionParams
=
this
.
subscriptions
[
subscriptionId
]
const
subscriptionParams
=
this
.
subscriptions
[
subscriptionId
]
const
[
queryType
,
queryFilter
]
=
subscriptionParams
const
[
queryType
,
queryFilter
]
=
subscriptionParams
if
(
queryType
===
'logs'
)
{
if
(
queryFilter
.
address
===
(
"0x"
+
changeEvent
.
tx
.
to
.
toString
(
'hex'
)))
{
if
(
this
.
eventMatchesFilter
(
changeEvent
,
queryType
,
queryFilter
))
{
if
(
!
queryFilter
.
toBlock
)
{
matchedSubscriptions
.
push
(
subscriptionId
)
matchedSubscriptions
.
push
(
subscriptionId
)
}
else
if
(
parseInt
(
queryFilter
.
toBlock
)
>
parseInt
(
changeEvent
.
blockNumber
))
{
matchedSubscriptions
.
push
(
subscriptionId
)
}
}
if
(
queryFilter
.
address
===
(
'0x'
+
changeEvent
.
tx
.
from
.
toString
(
'hex'
)))
{
if
(
!
queryFilter
.
toBlock
)
{
matchedSubscriptions
.
push
(
subscriptionId
)
}
else
if
(
parseInt
(
queryFilter
.
toBlock
)
>
parseInt
(
changeEvent
.
blockNumber
))
{
matchedSubscriptions
.
push
(
subscriptionId
)
}
}
}
}
}
}
return
matchedSubscriptions
;
return
matchedSubscriptions
;
...
@@ -76,13 +85,24 @@ class LogsManager {
...
@@ -76,13 +85,24 @@ class LogsManager {
console
.
dir
(
result
)
console
.
dir
(
result
)
// TODO: manage subscriptions
// TODO: manage subscriptions
// need to associate subscriptions to notificationCallbacks
this
.
notificationCallbacks
.
forEach
((
callback
)
=>
{
this
.
notificationCallbacks
.
forEach
((
callback
)
=>
{
if
(
result
.
params
.
result
.
raw
)
{
result
.
params
.
result
.
data
=
result
.
params
.
result
.
raw
.
data
result
.
params
.
result
.
topics
=
result
.
params
.
result
.
raw
.
topics
}
console
.
dir
(
"transmitting back"
)
console
.
dir
(
result
)
// console.dir(result.params.result.returnValues)
// console.dir(result.params.result.raw)
callback
(
result
)
callback
(
result
)
});
});
}
}
addListener
(
type
,
cb
)
{
addListener
(
type
,
cb
)
{
console
.
dir
(
"<<<<<<<<<<<------------------------->>>>>>>>>>>>>"
);
console
.
dir
(
"adding listener..."
);
this
.
notificationCallbacks
.
push
(
cb
)
this
.
notificationCallbacks
.
push
(
cb
)
console
.
dir
(
"--------------------------------------------------------->"
)
console
.
dir
(
"--------------------------------------------------------->"
)
console
.
dir
(
"=========================="
)
console
.
dir
(
"=========================="
)
...
@@ -103,16 +123,22 @@ class LogsManager {
...
@@ -103,16 +123,22 @@ class LogsManager {
}
}
getLogsFor
(
params
)
{
getLogsFor
(
params
)
{
let
results
=
[{
let
results
=
[]
"logIndex"
:
"0x1"
,
// 1
for
(
let
log
of
this
.
oldLogs
)
{
"blockNumber"
:
"0x1b4"
,
// 436
if
(
this
.
eventMatchesFilter
(
log
,
'logs'
,
params
))
{
"blockHash"
:
"0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d"
,
results
.
push
({
"transactionHash"
:
"0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf"
,
"logIndex"
:
"0x1"
,
// 1
"transactionIndex"
:
"0x0"
,
// 0
"blockNumber"
:
log
.
blockNumber
,
"address"
:
"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d"
,
"blockHash"
:
(
'0x'
+
log
.
block
.
hash
().
toString
(
'hex'
)),
"data"
:
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"transactionHash"
:
(
'0x'
+
log
.
tx
.
hash
().
toString
(
'hex'
)),
"topics"
:
[
"0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"
]
"transactionIndex"
:
"0x"
+
logs
.
txNumber
.
toString
(
16
),
}]
// TODO: if it's a contract deploy, it should be that address instead
"address"
:
log
.
log
.
address
,
"data"
:
log
.
log
.
data
,
"topics"
:
log
.
log
.
topics
,
})
}
}
return
results
return
results
}
}
...
...
remix-simulator/src/methods/filters.js
View file @
572dbb0e
...
@@ -18,12 +18,13 @@ Filters.prototype.eth_getLogs = function (payload, cb) {
...
@@ -18,12 +18,13 @@ Filters.prototype.eth_getLogs = function (payload, cb) {
console
.
dir
(
"==============================="
)
console
.
dir
(
"==============================="
)
console
.
dir
(
"==============================="
)
console
.
dir
(
"==============================="
)
console
.
dir
(
"=== eth_getLogs"
)
console
.
dir
(
"=== eth_getLogs"
)
// payload.params[0].topics = payload.params[0].topics.filter((x) => x)
console
.
dir
(
payload
.
params
)
console
.
dir
(
payload
.
params
)
// [ { fromBlock: '0x0',
// address: '0xdb2eb1480cb3ac3a5c0ee957045d1ad9dcd34f01',
// topics: [] } ]
let
results
=
executionContext
.
logsManager
.
getLogsFor
(
payload
.
params
);
let
results
=
executionContext
.
logsManager
.
getLogsFor
(
payload
.
params
[
0
]);
console
.
dir
(
"results are ---"
)
console
.
dir
(
results
)
cb
(
null
,
results
)
cb
(
null
,
results
)
}
}
...
...
remix-simulator/src/provider.js
View file @
572dbb0e
...
@@ -29,9 +29,9 @@ var Provider = function (options) {
...
@@ -29,9 +29,9 @@ var Provider = function (options) {
generateBlock
()
generateBlock
()
setTimeout
(()
=>
{
//
setTimeout(() => {
console
.
dir
(
"hello!"
)
//
console.dir("hello!")
},
10
*
1000
)
//
}, 10 * 1000)
}
}
Provider
.
prototype
.
init
=
async
function
()
{
Provider
.
prototype
.
init
=
async
function
()
{
...
@@ -69,6 +69,8 @@ Provider.prototype.isConnected = function () {
...
@@ -69,6 +69,8 @@ Provider.prototype.isConnected = function () {
}
}
Provider
.
prototype
.
on
=
function
(
type
,
cb
)
{
Provider
.
prototype
.
on
=
function
(
type
,
cb
)
{
console
.
dir
(
"on"
)
console
.
dir
(
arguments
)
executionContext
.
logsManager
.
addListener
(
type
,
cb
)
executionContext
.
logsManager
.
addListener
(
type
,
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