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
02fbc043
Commit
02fbc043
authored
Jul 12, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add subscription & logs methods; create logmanager to direct subscriptiosn
parent
45e865d5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
0 deletions
+153
-0
execution-context.js
remix-lib/src/execution/execution-context.js
+6
-0
logsManager.js
remix-lib/src/execution/logsManager.js
+75
-0
filters.js
remix-simulator/src/methods/filters.js
+48
-0
provider.js
remix-simulator/src/provider.js
+18
-0
server.js
remix-simulator/src/server.js
+6
-0
No files found.
remix-lib/src/execution/execution-context.js
View file @
02fbc043
...
@@ -7,6 +7,8 @@ var ethUtil = require('ethereumjs-util')
...
@@ -7,6 +7,8 @@ var ethUtil = require('ethereumjs-util')
var
StateManager
=
require
(
'ethereumjs-vm/dist/stateManager'
)
var
StateManager
=
require
(
'ethereumjs-vm/dist/stateManager'
)
var
Web3VMProvider
=
require
(
'../web3Provider/web3VmProvider'
)
var
Web3VMProvider
=
require
(
'../web3Provider/web3VmProvider'
)
var
LogsManager
=
require
(
'./logsManager.js'
);
var
rlp
=
ethUtil
.
rlp
var
rlp
=
ethUtil
.
rlp
var
injectedProvider
var
injectedProvider
...
@@ -105,6 +107,8 @@ function ExecutionContext () {
...
@@ -105,6 +107,8 @@ function ExecutionContext () {
var
self
=
this
var
self
=
this
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
logsManager
=
new
LogsManager
()
var
executionContext
=
null
var
executionContext
=
null
this
.
blockGasLimitDefault
=
4300000
this
.
blockGasLimitDefault
=
4300000
...
@@ -305,6 +309,8 @@ function ExecutionContext () {
...
@@ -305,6 +309,8 @@ function ExecutionContext () {
self
.
blocks
[
'0x'
+
block
.
hash
().
toString
(
'hex'
)]
=
block
self
.
blocks
[
'0x'
+
block
.
hash
().
toString
(
'hex'
)]
=
block
self
.
blocks
[
blockNumber
]
=
block
self
.
blocks
[
blockNumber
]
=
block
this
.
logsManager
.
checkBlock
(
blockNumber
,
block
)
}
}
this
.
trackTx
=
function
(
tx
,
block
)
{
this
.
trackTx
=
function
(
tx
,
block
)
{
...
...
remix-lib/src/execution/logsManager.js
0 → 100644
View file @
02fbc043
var
crypto
=
require
(
'crypto'
)
class
LogsManager
{
constructor
()
{
this
.
notificationCallbacks
=
[]
this
.
subscriptions
=
{}
}
checkBlock
(
blockNumber
,
block
)
{
let
subscriptionId
=
Object
.
keys
(
this
.
subscriptions
)[
0
];
let
result
=
{
"logIndex"
:
"0x1"
,
// 1
"blockNumber"
:
"0x1b4"
,
// 436
"blockHash"
:
"0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d"
,
"transactionHash"
:
"0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf"
,
"transactionIndex"
:
"0x0"
,
// 0
"address"
:
"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d"
,
"data"
:
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"topics"
:
[
"0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"
]
}
let
response
=
{
'jsonrpc'
:
'2.0'
,
"method"
:
"eth_subscription"
,
params
:
{
'result'
:
result
,
'subscription'
:
subscriptionId
}
};
this
.
transmit
(
response
);
}
transmit
(
result
)
{
console
.
dir
(
"-----------------"
)
console
.
dir
(
"---- transmit"
)
console
.
dir
(
this
.
notificationCallbacks
)
console
.
dir
(
result
)
// TODO: manage subscriptions
this
.
notificationCallbacks
.
forEach
((
callback
)
=>
{
callback
(
result
)
});
}
addListener
(
type
,
cb
)
{
this
.
notificationCallbacks
.
push
(
cb
)
console
.
dir
(
"--------------------------------------------------------->"
)
console
.
dir
(
"=========================="
)
console
.
dir
(
"=========================="
)
console
.
dir
(
this
.
notificationCallbacks
)
console
.
dir
(
"=========================="
)
console
.
dir
(
"=========================="
)
}
subscribe
(
params
)
{
let
subscriptionId
=
"0x"
+
crypto
.
randomBytes
(
16
).
toString
(
'hex'
)
this
.
subscriptions
[
subscriptionId
]
=
params
return
subscriptionId
}
getLogsFor
(
params
)
{
let
results
=
[{
"logIndex"
:
"0x1"
,
// 1
"blockNumber"
:
"0x1b4"
,
// 436
"blockHash"
:
"0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d"
,
"transactionHash"
:
"0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf"
,
"transactionIndex"
:
"0x0"
,
// 0
"address"
:
"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d"
,
"data"
:
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"topics"
:
[
"0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"
]
}]
return
results
}
}
module
.
exports
=
LogsManager
;
\ No newline at end of file
remix-simulator/src/methods/filters.js
0 → 100644
View file @
02fbc043
var
RemixLib
=
require
(
'remix-lib'
)
var
executionContext
=
RemixLib
.
execution
.
executionContext
var
Filters
=
function
(
_options
)
{
const
options
=
_options
||
{}
}
Filters
.
prototype
.
methods
=
function
()
{
return
{
eth_getLogs
:
this
.
eth_getLogs
.
bind
(
this
),
eth_subscribe
:
this
.
eth_subscribe
.
bind
(
this
)
}
}
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
Filters
.
prototype
.
eth_getLogs
=
function
(
payload
,
cb
)
{
console
.
dir
(
"==============================="
)
console
.
dir
(
"==============================="
)
console
.
dir
(
"=== eth_getLogs"
)
console
.
dir
(
payload
.
params
)
// [ { fromBlock: '0x0',
// address: '0xdb2eb1480cb3ac3a5c0ee957045d1ad9dcd34f01',
// topics: [] } ]
// console.dir(executionContext.vm().stateManager)
// console.dir(executionContext.vm().blockchain)
// var block = executionContext.blocks[payload.params[0]]
// executionContext.vm().stateManager.getLogs(address, (err, account) => {
let
results
=
executionContext
.
logsManager
.
getLogsFor
(
payload
.
params
);
cb
(
null
,
results
)
}
Filters
.
prototype
.
eth_subscribe
=
function
(
payload
,
cb
)
{
console
.
dir
(
"==============================="
)
console
.
dir
(
"==============================="
)
console
.
dir
(
"=== eth_subscribe"
)
console
.
dir
(
payload
.
params
)
let
subscriptionId
=
executionContext
.
logsManager
.
subscribe
(
payload
.
params
);
cb
(
null
,
subscriptionId
)
}
module
.
exports
=
Filters
remix-simulator/src/provider.js
View file @
02fbc043
var
RemixLib
=
require
(
'remix-lib'
)
var
executionContext
=
RemixLib
.
execution
.
executionContext
const
log
=
require
(
'./utils/logs.js'
)
const
log
=
require
(
'./utils/logs.js'
)
const
merge
=
require
(
'merge'
)
const
merge
=
require
(
'merge'
)
const
Accounts
=
require
(
'./methods/accounts.js'
)
const
Accounts
=
require
(
'./methods/accounts.js'
)
const
Blocks
=
require
(
'./methods/blocks.js'
)
const
Blocks
=
require
(
'./methods/blocks.js'
)
const
Filters
=
require
(
'./methods/filters.js'
)
const
Misc
=
require
(
'./methods/misc.js'
)
const
Misc
=
require
(
'./methods/misc.js'
)
const
Net
=
require
(
'./methods/net.js'
)
const
Net
=
require
(
'./methods/net.js'
)
const
Transactions
=
require
(
'./methods/transactions.js'
)
const
Transactions
=
require
(
'./methods/transactions.js'
)
...
@@ -18,11 +22,16 @@ var Provider = function (options) {
...
@@ -18,11 +22,16 @@ var Provider = function (options) {
this
.
methods
=
merge
(
this
.
methods
,
this
.
Accounts
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
this
.
Accounts
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Blocks
(
options
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Blocks
(
options
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Filters
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
this
.
Transactions
.
methods
()))
this
.
methods
=
merge
(
this
.
methods
,
(
this
.
Transactions
.
methods
()))
this
.
methods
=
merge
(
this
.
methods
,
(
new
Whisper
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Whisper
()).
methods
())
generateBlock
()
generateBlock
()
setTimeout
(()
=>
{
console
.
dir
(
"hello!"
)
},
10
*
1000
)
}
}
Provider
.
prototype
.
init
=
async
function
()
{
Provider
.
prototype
.
init
=
async
function
()
{
...
@@ -32,14 +41,19 @@ Provider.prototype.init = async function () {
...
@@ -32,14 +41,19 @@ Provider.prototype.init = async function () {
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
log
.
info
(
'payload method is '
,
payload
.
method
)
log
.
info
(
'payload method is '
,
payload
.
method
)
console
.
dir
(
payload
)
let
method
=
this
.
methods
[
payload
.
method
]
let
method
=
this
.
methods
[
payload
.
method
]
if
(
method
)
{
if
(
method
)
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
dir
(
"====== error"
)
console
.
dir
(
err
)
return
callback
(
err
)
return
callback
(
err
)
}
}
let
response
=
{
'id'
:
payload
.
id
,
'jsonrpc'
:
'2.0'
,
'result'
:
result
}
let
response
=
{
'id'
:
payload
.
id
,
'jsonrpc'
:
'2.0'
,
'result'
:
result
}
console
.
dir
(
"response"
)
console
.
dir
(
response
)
callback
(
null
,
response
)
callback
(
null
,
response
)
})
})
}
}
...
@@ -54,4 +68,8 @@ Provider.prototype.isConnected = function () {
...
@@ -54,4 +68,8 @@ Provider.prototype.isConnected = function () {
return
true
return
true
}
}
Provider
.
prototype
.
on
=
function
(
type
,
cb
)
{
executionContext
.
logsManager
.
addListener
(
type
,
cb
)
}
module
.
exports
=
Provider
module
.
exports
=
Provider
remix-simulator/src/server.js
View file @
02fbc043
...
@@ -48,6 +48,12 @@ class Server {
...
@@ -48,6 +48,12 @@ class Server {
ws
.
send
(
JSON
.
stringify
(
jsonResponse
))
ws
.
send
(
JSON
.
stringify
(
jsonResponse
))
})
})
})
})
this
.
provider
.
on
(
'data'
,
(
result
)
=>
{
console
.
dir
(
"-----> sending"
)
console
.
dir
(
JSON
.
stringify
(
result
))
ws
.
send
(
JSON
.
stringify
(
result
));
})
})
})
}
}
...
...
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