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
d20d81dd
Commit
d20d81dd
authored
Apr 16, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement eth_getTransactionByHash, eth_getBlockByHash, eth_getTransactionByHash. fix accounts
parent
3010dc0b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
11 deletions
+68
-11
README.md
remix-simulator/README.md
+2
-2
accounts.js
remix-simulator/src/methods/accounts.js
+5
-3
blocks.js
remix-simulator/src/methods/blocks.js
+29
-2
transactions.js
remix-simulator/src/methods/transactions.js
+32
-4
No files found.
remix-simulator/README.md
View file @
d20d81dd
...
...
@@ -28,9 +28,9 @@ Implemented:
*
[
_
]
eth_sendRawTransaction
*
[
X
]
eth_call
*
[
~
]
eth_estimateGas
*
[
_
]
eth_getBlockByHash
*
[
~
]
eth_getBlockByHash
*
[
~
]
eth_getBlockByNumber
*
[
_
]
eth_getTransactionByHash
*
[
~
]
eth_getTransactionByHash
*
[
_
]
eth_getTransactionByBlockHashAndIndex
*
[
_
]
eth_getTransactionByBlockNumberAndIndex
*
[
~
]
eth_getTransactionReceipt
...
...
remix-simulator/src/methods/accounts.js
View file @
d20d81dd
...
...
@@ -7,13 +7,15 @@ var Web3 = require('web3')
var
Accounts
=
function
()
{
this
.
web3
=
new
Web3
()
// 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
.
accountsList
=
[
this
.
web3
.
eth
.
accounts
.
create
([
'abcd'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ef12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ef34'
])]
this
.
accounts
=
{}
this
.
accountsKeys
=
{}
executionContext
.
init
({
get
:
()
=>
{
return
true
}})
for
(
let
_account
of
this
.
accounts
)
{
for
(
let
_account
of
this
.
accounts
List
)
{
this
.
accountsKeys
[
_account
.
address
.
toLowerCase
()]
=
_account
.
privateKey
this
.
accounts
[
_account
.
address
.
toLowerCase
()]
=
{
privateKey
:
Buffer
.
from
(
_account
.
privateKey
.
replace
(
"0x"
,
""
),
'hex'
),
nonce
:
0
}
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
_account
.
address
.
toLowerCase
().
replace
(
"0x"
,
""
),
'hex'
),
(
err
,
account
)
=>
{
var
balance
=
'0x56BC75E2D63100000'
...
...
@@ -31,7 +33,7 @@ Accounts.prototype.methods = function () {
}
Accounts
.
prototype
.
eth_accounts
=
function
(
payload
,
cb
)
{
return
cb
(
null
,
this
.
accounts
.
map
((
x
)
=>
x
.
address
))
return
cb
(
null
,
this
.
accounts
List
.
map
((
x
)
=>
x
.
address
))
}
Accounts
.
prototype
.
eth_getBalance
=
function
(
payload
,
cb
)
{
...
...
remix-simulator/src/methods/blocks.js
View file @
d20d81dd
...
...
@@ -11,7 +11,8 @@ Blocks.prototype.methods = function () {
eth_getBlockByNumber
:
this
.
eth_getBlockByNumber
.
bind
(
this
),
eth_gasPrice
:
this
.
eth_gasPrice
.
bind
(
this
),
eth_coinbase
:
this
.
eth_coinbase
.
bind
(
this
),
eth_blockNumber
:
this
.
eth_blockNumber
.
bind
(
this
)
eth_blockNumber
:
this
.
eth_blockNumber
.
bind
(
this
),
eth_getBlockByHash
:
this
.
eth_getBlockByHash
.
bind
(
this
)
}
}
...
...
@@ -26,7 +27,33 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
'miner'
:
this
.
coinbase
,
'mixHash'
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
'nonce'
:
'0x0000000000000042'
,
'number'
:
Web3
.
utils
.
tohex
(
this
.
blockNumber
),
'number'
:
Web3
.
utils
.
toHex
(
this
.
blockNumber
),
'parentHash'
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
'receiptsRoot'
:
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
,
'sha3Uncles'
:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
,
'size'
:
'0x1f8'
,
'stateRoot'
:
'0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff'
,
'timestamp'
:
'0x0'
,
'totalDifficulty'
:
'0x0'
,
'transactions'
:
[],
'transactionsRoot'
:
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
,
'uncles'
:
[]
}
cb
(
null
,
b
)
}
Blocks
.
prototype
.
eth_getBlockByHash
=
function
(
payload
,
cb
)
{
let
b
=
{
'difficulty'
:
'0x0'
,
'extraData'
:
'0x'
,
'gasLimit'
:
'0x7a1200'
,
'gasUsed'
:
'0x0'
,
'hash'
:
'0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f'
,
'logsBloom'
:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
,
'miner'
:
this
.
coinbase
,
'mixHash'
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
'nonce'
:
'0x0000000000000042'
,
'number'
:
Web3
.
utils
.
toHex
(
this
.
blockNumber
),
'parentHash'
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
'receiptsRoot'
:
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
,
'sha3Uncles'
:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
,
...
...
remix-simulator/src/methods/transactions.js
View file @
d20d81dd
var
RemixLib
=
require
(
'remix-lib'
)
var
executionContext
=
RemixLib
.
execution
.
executionContext
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
processTx
=
require
(
'./txProcess.js'
)
function
hexConvert
(
ints
)
{
...
...
@@ -17,8 +18,6 @@ function hexConvert(ints) {
var
Transactions
=
function
(
accounts
)
{
this
.
accounts
=
accounts
// TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now
//this.deployedContracts = {}
}
Transactions
.
prototype
.
methods
=
function
()
{
...
...
@@ -28,7 +27,8 @@ Transactions.prototype.methods = function () {
eth_getCode
:
this
.
eth_getCode
.
bind
(
this
),
eth_call
:
this
.
eth_call
.
bind
(
this
),
eth_estimateGas
:
this
.
eth_estimateGas
.
bind
(
this
),
eth_getTransactionCount
:
this
.
eth_getTransactionCount
.
bind
(
this
)
eth_getTransactionCount
:
this
.
eth_getTransactionCount
.
bind
(
this
),
eth_getTransactionByHash
:
this
.
eth_getTransactionByHash
.
bind
(
this
)
}
}
...
...
@@ -68,10 +68,10 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
let
address
=
payload
.
params
[
0
]
const
account
=
ethJSUtil
.
toBuffer
(
address
)
executionContext
.
vm
().
stateManager
.
getContractCode
(
account
,
(
error
,
result
)
=>
{
cb
(
error
,
hexConvert
(
result
))
})
//cb(null, this.deployedContracts[address] || '0x')
}
Transactions
.
prototype
.
eth_call
=
function
(
payload
,
cb
)
{
...
...
@@ -87,4 +87,32 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
})
}
Transactions
.
prototype
.
eth_getTransactionByHash
=
function
(
payload
,
cb
)
{
const
address
=
payload
.
params
[
0
]
executionContext
.
web3
().
eth
.
getTransactionReceipt
(
address
,
(
error
,
receipt
)
=>
{
if
(
error
)
{
return
cb
(
error
)
}
web3
.
eth
.
getBlock
(
receipt
.
hash
).
then
((
block
)
=>
{
const
r
=
{
"hash"
:
receipt
.
transactionHash
,
//"nonce": 2,
"blockHash"
:
receipt
.
hash
,
"blockNumber"
:
block
.
number
,
//"transactionIndex": 0,
"from"
:
receipt
.
from
,
"to"
:
receipt
.
to
,
"value"
:
receipt
.
value
,
"gas"
:
receipt
.
gas
,
"gasPrice"
:
'2000000000000'
,
"input"
:
receipt
.
input
}
cb
(
null
,
r
)
})
})
}
module
.
exports
=
Transactions
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