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
c3a5040f
Commit
c3a5040f
authored
Apr 09, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add eth_getBalance; use accounts in executionContext vm
parent
912c5c0d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
8 deletions
+28
-8
README.md
remix-simulator/README.md
+1
-1
package.json
remix-simulator/package.json
+2
-0
accounts.js
remix-simulator/src/methods/accounts.js
+25
-7
No files found.
remix-simulator/README.md
View file @
c3a5040f
...
...
@@ -15,7 +15,7 @@ Implemented:
*
[
~
]
eth_gasPrice
*
[
~
]
eth_accounts
*
[
X
]
eth_blockNumber
*
[
_
]
eth_getBalance
*
[
X
]
eth_getBalance
*
[
_
]
eth_getStorageAt
*
[
_
]
eth_getTransactionCount
*
[
_
]
eth_getBlockTransactionCountByHash
...
...
remix-simulator/package.json
View file @
c3a5040f
...
...
@@ -23,6 +23,8 @@
"fast-async"
:
"^6.3.7"
,
"merge"
:
"^1.2.0"
,
"remix-lib"
:
"0.4.5"
,
"ethereumjs-vm"
:
"3.0.0"
,
"ethereumjs-util"
:
"^5.1.2"
,
"standard"
:
"^10.0.3"
,
"time-stamp"
:
"^2.0.0"
,
"web3"
:
"1.0.0-beta.27"
...
...
remix-simulator/src/methods/accounts.js
View file @
c3a5040f
var
RemixLib
=
require
(
'remix-lib'
)
var
executionContext
=
RemixLib
.
execution
.
executionContext
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
BN
=
ethJSUtil
.
BN
var
Web3
=
require
(
'web3'
)
var
Accounts
=
function
()
{
...
...
@@ -5,18 +9,20 @@ var Accounts = function () {
// TODO: make it random and/or use remix-libs
this
.
accounts
=
[
this
.
web3
.
eth
.
accounts
.
create
([
'abcd'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ef12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ef34'
])]
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()]
=
this
.
accounts
[
0
]
this
.
accounts
[
this
.
accounts
[
1
].
address
.
toLowerCase
()]
=
this
.
accounts
[
1
]
this
.
accounts
[
this
.
accounts
[
2
].
address
.
toLowerCase
()]
=
this
.
accounts
[
2
]
executionContext
.
init
({
get
:
()
=>
{
return
true
}})
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()].
privateKey
=
Buffer
.
from
(
this
.
accounts
[
this
.
accounts
[
0
].
address
.
toLowerCase
()].
privateKey
.
slice
(
2
),
'hex'
)
this
.
accounts
[
this
.
accounts
[
1
].
address
.
toLowerCase
()].
privateKey
=
Buffer
.
from
(
this
.
accounts
[
this
.
accounts
[
1
].
address
.
toLowerCase
()].
privateKey
.
slice
(
2
),
'hex'
)
this
.
accounts
[
this
.
accounts
[
2
].
address
.
toLowerCase
()].
privateKey
=
Buffer
.
from
(
this
.
accounts
[
this
.
accounts
[
2
].
address
.
toLowerCase
()].
privateKey
.
slice
(
2
),
'hex'
)
for
(
let
_account
of
this
.
accounts
)
{
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
_account
.
address
.
toLowerCase
().
replace
(
"0x"
,
""
),
'hex'
),
(
err
,
account
)
=>
{
var
balance
=
'0x56BC75E2D63100000'
account
.
balance
=
balance
||
'0xf00000000000000001'
})
}
}
Accounts
.
prototype
.
methods
=
function
()
{
return
{
eth_accounts
:
this
.
eth_accounts
.
bind
(
this
)
eth_accounts
:
this
.
eth_accounts
.
bind
(
this
),
eth_getBalance
:
this
.
eth_getBalance
.
bind
(
this
)
}
}
...
...
@@ -24,4 +30,16 @@ Accounts.prototype.eth_accounts = function (payload, cb) {
return
cb
(
null
,
this
.
accounts
.
map
((
x
)
=>
x
.
address
))
}
Accounts
.
prototype
.
eth_getBalance
=
function
(
payload
,
cb
)
{
let
address
=
payload
.
params
[
0
]
address
=
ethJSUtil
.
stripHexPrefix
(
address
)
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
function
(
err
,
account
)
{
if
(
err
)
{
return
cb
(
'Account not found'
)
}
cb
(
null
,
new
BN
(
account
.
balance
).
toString
(
10
))
})
}
module
.
exports
=
Accounts
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