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
0c4348a6
Commit
0c4348a6
authored
Nov 24, 2020
by
aniket-engg
Committed by
Aniket
Nov 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
class and type updates
parent
febab2ef
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
145 deletions
+133
-145
genesis.ts
libs/remix-simulator/src/genesis.ts
+1
-1
index.ts
libs/remix-simulator/src/index.ts
+0
-2
misc.ts
libs/remix-simulator/src/methods/misc.ts
+47
-49
net.ts
libs/remix-simulator/src/methods/net.ts
+15
-19
provider.ts
libs/remix-simulator/src/provider.ts
+8
-9
logs.ts
libs/remix-simulator/src/utils/logs.ts
+55
-58
accounts.ts
libs/remix-simulator/test/accounts.ts
+7
-7
No files found.
libs/remix-simulator/src/genesis.ts
View file @
0c4348a6
...
@@ -2,7 +2,7 @@ import EthJSBlock from 'ethereumjs-block'
...
@@ -2,7 +2,7 @@ import EthJSBlock from 'ethereumjs-block'
import
{
BN
}
from
'ethereumjs-util'
import
{
BN
}
from
'ethereumjs-util'
export
function
generateBlock
(
executionContext
)
{
export
function
generateBlock
(
executionContext
)
{
const
block
=
new
EthJSBlock
({
const
block
:
EthJSBlock
=
new
EthJSBlock
({
header
:
{
header
:
{
timestamp
:
(
new
Date
().
getTime
()
/
1000
|
0
),
timestamp
:
(
new
Date
().
getTime
()
/
1000
|
0
),
number
:
0
,
number
:
0
,
...
...
libs/remix-simulator/src/index.ts
View file @
0c4348a6
export
{
Provider
}
from
'./provider'
export
{
Provider
}
from
'./provider'
// export { Provider }
libs/remix-simulator/src/methods/misc.ts
View file @
0c4348a6
const
version
=
require
(
'../../package.json'
).
version
const
version
=
require
(
'../../package.json'
).
version
import
web3
from
'web3'
import
Web3
from
'web3'
export
class
Misc
{
export
function
methods
()
{
return
{
methods
()
{
web3_clientVersion
:
this
.
web3_clientVersion
.
bind
(
this
),
return
{
eth_protocolVersion
:
this
.
eth_protocolVersion
.
bind
(
this
),
web3_clientVersion
:
this
.
web3_clientVersion
.
bind
(
this
),
eth_syncing
:
this
.
eth_syncing
.
bind
(
this
),
eth_protocolVersion
:
this
.
eth_protocolVersion
.
bind
(
this
),
eth_mining
:
this
.
eth_mining
.
bind
(
this
),
eth_syncing
:
this
.
eth_syncing
.
bind
(
this
),
eth_hashrate
:
this
.
eth_hashrate
.
bind
(
this
),
eth_mining
:
this
.
eth_mining
.
bind
(
this
),
web3_sha3
:
this
.
web3_sha3
.
bind
(
this
),
eth_hashrate
:
this
.
eth_hashrate
.
bind
(
this
),
eth_getCompilers
:
this
.
eth_getCompilers
.
bind
(
this
),
web3_sha3
:
this
.
web3_sha3
.
bind
(
this
),
eth_compileSolidity
:
this
.
eth_compileSolidity
.
bind
(
this
),
eth_getCompilers
:
this
.
eth_getCompilers
.
bind
(
this
),
eth_compileLLL
:
this
.
eth_compileLLL
.
bind
(
this
),
eth_compileSolidity
:
this
.
eth_compileSolidity
.
bind
(
this
),
eth_compileSerpent
:
this
.
eth_compileSerpent
.
bind
(
this
)
eth_compileLLL
:
this
.
eth_compileLLL
.
bind
(
this
),
eth_compileSerpent
:
this
.
eth_compileSerpent
.
bind
(
this
)
}
}
}
}
web3_clientVersion
(
payload
,
cb
)
{
export
function
web3_clientVersion
(
payload
,
cb
)
{
cb
(
null
,
'Remix Simulator/'
+
version
)
cb
(
null
,
'Remix Simulator/'
+
version
)
}
}
eth_protocolVersion
(
payload
,
cb
)
{
export
function
eth_protocolVersion
(
payload
,
cb
)
{
cb
(
null
,
'0x3f'
)
cb
(
null
,
'0x3f'
)
}
}
eth_syncing
(
payload
,
cb
)
{
export
function
eth_syncing
(
payload
,
cb
)
{
cb
(
null
,
false
)
cb
(
null
,
false
)
}
}
eth_mining
(
payload
,
cb
)
{
export
function
eth_mining
(
payload
,
cb
)
{
// TODO: should depend on the state
// TODO: should depend on the state
cb
(
null
,
false
)
cb
(
null
,
false
)
}
}
eth_hashrate
(
payload
,
cb
)
{
export
function
eth_hashrate
(
payload
,
cb
)
{
cb
(
null
,
'0x0'
)
cb
(
null
,
'0x0'
)
}
}
web3_sha3
(
payload
,
cb
)
{
export
function
web3_sha3
(
payload
,
cb
)
{
const
str
=
payload
.
params
[
0
]
const
str
:
string
=
payload
.
params
[
0
]
cb
(
null
,
w
eb3
.
utils
.
sha3
(
str
))
cb
(
null
,
W
eb3
.
utils
.
sha3
(
str
))
}
}
eth_getCompilers
(
payload
,
cb
)
{
export
function
eth_getCompilers
(
payload
,
cb
)
{
cb
(
null
,
[])
cb
(
null
,
[])
}
}
eth_compileSolidity
(
payload
,
cb
)
{
export
function
eth_compileSolidity
(
payload
,
cb
)
{
cb
(
null
,
'unsupported'
)
cb
(
null
,
'unsupported'
)
}
}
eth_compileLLL
(
payload
,
cb
)
{
export
function
eth_compileLLL
(
payload
,
cb
)
{
cb
(
null
,
'unsupported'
)
cb
(
null
,
'unsupported'
)
}
}
eth_compileSerpent
(
payload
,
cb
)
{
export
function
eth_compileSerpent
(
payload
,
cb
)
{
cb
(
null
,
'unsupported'
)
cb
(
null
,
'unsupported'
)
}
}
}
libs/remix-simulator/src/methods/net.ts
View file @
0c4348a6
export
function
methods
():
Record
<
string
,
unknown
>
{
export
class
Net
{
return
{
net_version
:
this
.
net_version
,
methods
()
{
net_listening
:
this
.
net_listening
,
return
{
net_peerCount
:
this
.
net_peerCount
net_version
:
this
.
net_version
,
net_listening
:
this
.
net_listening
,
net_peerCount
:
this
.
net_peerCount
}
}
}
}
net_version
(
payload
,
cb
)
{
export
function
net_version
(
payload
,
cb
):
void
{
// should be configured networkId
// should be configured networkId
cb
(
null
,
1337
)
cb
(
null
,
1337
)
}
}
net_listening
(
payload
,
cb
)
{
export
function
net_listening
(
payload
,
cb
):
void
{
cb
(
null
,
true
)
cb
(
null
,
true
)
}
}
net_peerCount
(
payload
,
cb
)
{
export
function
net_peerCount
(
payload
,
cb
):
void
{
cb
(
null
,
0
)
cb
(
null
,
0
)
}
}
}
libs/remix-simulator/src/provider.ts
View file @
0c4348a6
...
@@ -2,14 +2,13 @@ import { Blocks } from './methods/blocks'
...
@@ -2,14 +2,13 @@ import { Blocks } from './methods/blocks'
import
{
execution
}
from
'@remix-project/remix-lib'
import
{
execution
}
from
'@remix-project/remix-lib'
const
{
executionContext
}
=
execution
const
{
executionContext
}
=
execution
import
{
Logger
}
from
'./utils/logs'
import
{
info
}
from
'./utils/logs'
const
logger
=
new
Logger
()
import
merge
from
'merge'
import
merge
from
'merge'
import
{
Accounts
}
from
'./methods/accounts'
import
{
Accounts
}
from
'./methods/accounts'
import
{
Filters
}
from
'./methods/filters'
import
{
Filters
}
from
'./methods/filters'
import
{
Misc
}
from
'./methods/misc'
import
{
methods
as
miscMethods
}
from
'./methods/misc'
import
{
Net
}
from
'./methods/net'
import
{
methods
as
netMethods
}
from
'./methods/net'
import
{
Transactions
}
from
'./methods/transactions'
import
{
Transactions
}
from
'./methods/transactions'
import
{
Debug
}
from
'./methods/debug'
import
{
Debug
}
from
'./methods/debug'
import
{
generateBlock
}
from
'./genesis'
import
{
generateBlock
}
from
'./genesis'
...
@@ -31,9 +30,9 @@ export class Provider {
...
@@ -31,9 +30,9 @@ export class Provider {
this
.
methods
=
{}
this
.
methods
=
{}
this
.
methods
=
merge
(
this
.
methods
,
this
.
Accounts
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
this
.
Accounts
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Blocks
(
this
.
executionContext
,
options
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Blocks
(
this
.
executionContext
,
options
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
m
ethods
())
this
.
methods
=
merge
(
this
.
methods
,
miscM
ethods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Filters
(
this
.
executionContext
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Filters
(
this
.
executionContext
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
m
ethods
())
this
.
methods
=
merge
(
this
.
methods
,
netM
ethods
())
this
.
methods
=
merge
(
this
.
methods
,
this
.
Transactions
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
this
.
Transactions
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Debug
(
this
.
executionContext
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Debug
(
this
.
executionContext
)).
methods
())
...
@@ -51,13 +50,13 @@ export class Provider {
...
@@ -51,13 +50,13 @@ export class Provider {
const
method
=
this
.
methods
[
payload
.
method
]
const
method
=
this
.
methods
[
payload
.
method
]
if
(
this
.
options
.
logDetails
)
{
if
(
this
.
options
.
logDetails
)
{
logger
.
info
(
payload
)
info
(
payload
)
}
}
if
(
method
)
{
if
(
method
)
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
if
(
this
.
options
.
logDetails
)
{
if
(
this
.
options
.
logDetails
)
{
logger
.
info
(
err
)
info
(
err
)
logger
.
info
(
result
)
info
(
result
)
}
}
if
(
err
)
{
if
(
err
)
{
return
callback
(
err
)
return
callback
(
err
)
...
...
libs/remix-simulator/src/utils/logs.ts
View file @
0c4348a6
...
@@ -4,75 +4,72 @@ import gray from 'ansi-gray'
...
@@ -4,75 +4,72 @@ import gray from 'ansi-gray'
import
timestamp
from
'time-stamp'
import
timestamp
from
'time-stamp'
import
supportsColor
from
'color-support'
import
supportsColor
from
'color-support'
export
class
Logger
{
function
hasFlag
(
flag
)
{
return
((
typeof
(
process
)
!==
'undefined'
)
&&
(
process
.
argv
.
indexOf
(
'--'
+
flag
)
!==
-
1
))
private
hasFlag
(
flag
)
{
}
return
((
typeof
(
process
)
!==
'undefined'
)
&&
(
process
.
argv
.
indexOf
(
'--'
+
flag
)
!==
-
1
))
}
private
addColor
(
str
)
{
if
(
this
.
hasFlag
(
'no-color'
))
{
return
str
}
if
(
this
.
hasFlag
(
'color'
))
{
return
gray
(
str
)
}
if
(
supportsColor
())
{
return
gray
(
str
)
}
function
addColor
(
str
)
{
if
(
this
.
hasFlag
(
'no-color'
))
{
return
str
return
str
}
}
private
stdout
(
arg
)
{
if
(
this
.
hasFlag
(
'color'
))
{
if
(
typeof
(
process
)
===
'undefined'
||
!
process
.
stdout
)
return
return
gray
(
str
)
process
.
stdout
.
write
(
arg
)
}
}
private
stderr
(
arg
)
{
if
(
supportsColor
())
{
if
(
typeof
(
process
)
===
'undefined'
||
process
.
stderr
)
return
return
gray
(
str
)
process
.
stderr
.
write
(
arg
)
}
}
private
getTimestamp
()
{
return
str
const
coloredTimestamp
=
this
.
addColor
(
timestamp
(
'HH:mm:ss'
))
}
return
'['
+
coloredTimestamp
+
']'
}
log
(...
args
:
any
[])
{
function
stdout
(
arg
)
{
const
time
=
this
.
getTimestamp
()
if
(
typeof
(
process
)
===
'undefined'
||
!
process
.
stdout
)
return
this
.
stdout
(
time
+
' '
)
process
.
stdout
.
write
(
arg
)
console
.
log
(
args
)
}
return
this
}
info
(...
args
:
any
[])
{
function
stderr
(
arg
)
{
const
time
=
this
.
getTimestamp
()
if
(
typeof
(
process
)
===
'undefined'
||
process
.
stderr
)
return
this
.
stdout
(
time
+
' '
)
process
.
stderr
.
write
(
arg
)
console
.
info
(
args
)
}
return
this
}
dir
(...
args
:
any
[])
{
function
getTimestamp
()
{
const
time
=
this
.
getTimestamp
()
const
coloredTimestamp
=
this
.
addColor
(
timestamp
(
'HH:mm:ss'
))
this
.
stdout
(
time
+
' '
)
return
'['
+
coloredTimestamp
+
']'
console
.
dir
(
args
)
}
return
this
}
warn
(...
args
:
any
[])
{
export
function
log
(...
args
:
any
[])
{
const
time
=
this
.
getTimestamp
()
const
time
=
this
.
getTimestamp
()
this
.
stderr
(
time
+
' '
)
this
.
stdout
(
time
+
' '
)
console
.
warn
(
args
)
console
.
log
(
args
)
return
this
return
this
}
}
error
(...
args
:
any
[])
{
export
function
info
(...
args
:
any
[])
{
const
time
=
this
.
getTimestamp
()
const
time
=
this
.
getTimestamp
()
this
.
stderr
(
time
+
' '
)
this
.
stdout
(
time
+
' '
)
console
.
error
(
args
)
console
.
info
(
args
)
return
this
return
this
}
}
export
function
dir
(...
args
:
any
[])
{
const
time
=
this
.
getTimestamp
()
this
.
stdout
(
time
+
' '
)
console
.
dir
(
args
)
return
this
}
export
function
warn
(...
args
:
any
[])
{
const
time
=
this
.
getTimestamp
()
this
.
stderr
(
time
+
' '
)
console
.
warn
(
args
)
return
this
}
export
function
error
(...
args
:
any
[])
{
const
time
=
this
.
getTimestamp
()
this
.
stderr
(
time
+
' '
)
console
.
error
(
args
)
return
this
}
}
libs/remix-simulator/test/accounts.ts
View file @
0c4348a6
...
@@ -12,17 +12,17 @@ describe('Accounts', () => {
...
@@ -12,17 +12,17 @@ describe('Accounts', () => {
describe
(
'eth_getAccounts'
,
()
=>
{
describe
(
'eth_getAccounts'
,
()
=>
{
it
(
'should get a list of accounts'
,
async
function
()
{
it
(
'should get a list of accounts'
,
async
function
()
{
const
accounts
=
await
web3
.
eth
.
getAccounts
()
const
accounts
:
string
[]
=
await
web3
.
eth
.
getAccounts
()
assert
.
notEqual
(
accounts
.
length
,
0
)
assert
.
notEqual
(
accounts
.
length
,
0
)
})
})
})
})
describe
(
'eth_getBalance'
,
()
=>
{
describe
(
'eth_getBalance'
,
()
=>
{
it
(
'should get a account balance'
,
async
()
=>
{
it
(
'should get a account balance'
,
async
()
=>
{
const
accounts
=
await
web3
.
eth
.
getAccounts
()
const
accounts
:
string
[]
=
await
web3
.
eth
.
getAccounts
()
const
balance0
=
await
web3
.
eth
.
getBalance
(
accounts
[
0
])
const
balance0
:
string
=
await
web3
.
eth
.
getBalance
(
accounts
[
0
])
const
balance1
=
await
web3
.
eth
.
getBalance
(
accounts
[
1
])
const
balance1
:
string
=
await
web3
.
eth
.
getBalance
(
accounts
[
1
])
const
balance2
=
await
web3
.
eth
.
getBalance
(
accounts
[
2
])
const
balance2
:
string
=
await
web3
.
eth
.
getBalance
(
accounts
[
2
])
assert
.
deepEqual
(
balance0
,
'100000000000000000000'
)
assert
.
deepEqual
(
balance0
,
'100000000000000000000'
)
assert
.
deepEqual
(
balance1
,
'100000000000000000000'
)
assert
.
deepEqual
(
balance1
,
'100000000000000000000'
)
...
@@ -32,8 +32,8 @@ describe('Accounts', () => {
...
@@ -32,8 +32,8 @@ describe('Accounts', () => {
describe
(
'eth_sign'
,
()
=>
{
describe
(
'eth_sign'
,
()
=>
{
it
(
'should sign payloads'
,
async
()
=>
{
it
(
'should sign payloads'
,
async
()
=>
{
const
accounts
=
await
web3
.
eth
.
getAccounts
()
const
accounts
:
string
[]
=
await
web3
.
eth
.
getAccounts
()
const
signature
=
await
web3
.
eth
.
sign
(
'Hello world'
,
accounts
[
0
])
const
signature
:
string
=
await
web3
.
eth
.
sign
(
'Hello world'
,
accounts
[
0
])
assert
.
deepEqual
(
signature
.
length
,
132
)
assert
.
deepEqual
(
signature
.
length
,
132
)
})
})
...
...
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