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
798cac85
Commit
798cac85
authored
Jan 31, 2020
by
Iuri Matias
Committed by
yann300
Mar 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use remix-simulator accounts and addAccount
parent
162bc684
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
19 deletions
+35
-19
blockchain.js
src/blockchain/blockchain.js
+4
-2
vm.js
src/blockchain/providers/vm.js
+31
-17
No files found.
src/blockchain/blockchain.js
View file @
798cac85
...
@@ -321,7 +321,8 @@ class Blockchain {
...
@@ -321,7 +321,8 @@ class Blockchain {
resetEnvironment
()
{
resetEnvironment
()
{
this
.
getCurrentProvider
().
resetEnvironment
()
this
.
getCurrentProvider
().
resetEnvironment
()
// TODO: most params here can be refactored away in txRunner
// TODO: most params here can be refactored away in txRunner
this
.
txRunner
=
new
TxRunner
(
this
.
providers
.
vm
.
accounts
,
{
// this.txRunner = new TxRunner(this.providers.vm.accounts, {
this
.
txRunner
=
new
TxRunner
(
this
.
providers
.
vm
.
RemixSimulatorProvider
.
Accounts
.
accounts
,
{
// TODO: only used to check value of doNotShowTransactionConfirmationAgain property
// TODO: only used to check value of doNotShowTransactionConfirmationAgain property
config
:
this
.
config
,
config
:
this
.
config
,
// TODO: to refactor, TxRunner already has access to executionContext
// TODO: to refactor, TxRunner already has access to executionContext
...
@@ -430,7 +431,8 @@ class Blockchain {
...
@@ -430,7 +431,8 @@ class Blockchain {
if
(
err
)
return
next
(
err
)
if
(
err
)
return
next
(
err
)
if
(
!
address
)
return
next
(
'No accounts available'
)
if
(
!
address
)
return
next
(
'No accounts available'
)
if
(
self
.
executionContext
.
isVM
()
&&
!
self
.
providers
.
vm
.
accounts
[
address
])
{
// if (self.executionContext.isVM() && !self.providers.vm.accounts[address]) {
if
(
self
.
executionContext
.
isVM
()
&&
!
self
.
providers
.
vm
.
RemixSimulatorProvider
.
Accounts
.
accounts
[
address
])
{
return
next
(
'Invalid account selected'
)
return
next
(
'Invalid account selected'
)
}
}
next
(
null
,
address
,
value
,
gasLimit
)
next
(
null
,
address
,
value
,
gasLimit
)
...
...
src/blockchain/providers/vm.js
View file @
798cac85
...
@@ -2,20 +2,32 @@ const Web3 = require('web3')
...
@@ -2,20 +2,32 @@ const Web3 = require('web3')
const
{
BN
,
privateToAddress
,
toChecksumAddress
,
isValidPrivate
,
stripHexPrefix
}
=
require
(
'ethereumjs-util'
)
const
{
BN
,
privateToAddress
,
toChecksumAddress
,
isValidPrivate
,
stripHexPrefix
}
=
require
(
'ethereumjs-util'
)
const
crypto
=
require
(
'crypto'
)
const
crypto
=
require
(
'crypto'
)
const
ethJSUtil
=
require
(
'ethereumjs-util'
)
const
ethJSUtil
=
require
(
'ethereumjs-util'
)
const
RemixSimulator
=
require
(
'remix-simulator'
)
class
VMProvider
{
class
VMProvider
{
constructor
(
executionContext
)
{
constructor
(
executionContext
)
{
this
.
executionContext
=
executionContext
this
.
executionContext
=
executionContext
this
.
RemixSimulatorProvider
=
new
RemixSimulator
.
Provider
({
executionContext
:
this
.
executionContext
})
this
.
RemixSimulatorProvider
.
init
()
this
.
web3
=
new
Web3
(
this
.
RemixSimulatorProvider
)
this
.
accounts
=
{}
this
.
accounts
=
{}
}
}
getAccounts
(
cb
)
{
getAccounts
(
cb
)
{
if
(
!
this
.
accounts
)
{
this
.
web3
.
eth
.
getAccounts
((
err
,
accounts
)
=>
{
cb
(
'No accounts?'
)
console
.
dir
(
err
)
console
.
dir
(
accounts
)
if
(
err
)
{
return
cb
(
'No accounts?'
)
return
cb
(
'No accounts?'
)
}
}
return
cb
(
null
,
Object
.
keys
(
this
.
accounts
))
return
cb
(
null
,
accounts
)
})
// if (!this.accounts) {
// cb('No accounts?')
// return cb('No accounts?')
// }
// return cb(null, Object.keys(this.accounts))
}
}
resetEnvironment
()
{
resetEnvironment
()
{
...
@@ -29,20 +41,21 @@ class VMProvider {
...
@@ -29,20 +41,21 @@ class VMProvider {
/** Add an account to the list of account (only for Javascript VM) */
/** Add an account to the list of account (only for Javascript VM) */
_addAccount
(
privateKey
,
balance
)
{
_addAccount
(
privateKey
,
balance
)
{
privateKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
this
.
RemixSimulatorProvider
.
Accounts
.
_addAccount
(
privateKey
,
balance
)
const
address
=
privateToAddress
(
privateKey
)
// privateKey = Buffer.from(privateKey, 'hex')
// const address = privateToAddress(privateKey)
//
// FIXME: we don't care about the callback, but we should still make this proper
// FIXME: we don't care about the callback, but we should still make this proper
let
stateManager
=
this
.
executionContext
.
vm
().
stateManager
//
let stateManager = this.executionContext.vm().stateManager
stateManager
.
getAccount
(
address
,
(
error
,
account
)
=>
{
//
stateManager.getAccount(address, (error, account) => {
if
(
error
)
return
console
.
log
(
error
)
//
if (error) return console.log(error)
account
.
balance
=
balance
||
'0xf00000000000000001'
//
account.balance = balance || '0xf00000000000000001'
stateManager
.
putAccount
(
address
,
account
,
(
error
)
=>
{
//
stateManager.putAccount(address, account, (error) => {
if
(
error
)
console
.
log
(
error
)
//
if (error) console.log(error)
})
//
})
})
//
})
//
this
.
accounts
[
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
//
this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
}
}
createVMAccount
(
newAccount
)
{
createVMAccount
(
newAccount
)
{
...
@@ -78,7 +91,8 @@ class VMProvider {
...
@@ -78,7 +91,8 @@ class VMProvider {
signMessage
(
message
,
account
,
_passphrase
,
cb
)
{
signMessage
(
message
,
account
,
_passphrase
,
cb
)
{
const
personalMsg
=
ethJSUtil
.
hashPersonalMessage
(
Buffer
.
from
(
message
))
const
personalMsg
=
ethJSUtil
.
hashPersonalMessage
(
Buffer
.
from
(
message
))
const
privKey
=
this
.
accounts
[
account
].
privateKey
// const privKey = this.providers.vm.accounts[account].privateKey
const
privKey
=
this
.
RemixSimulatorProvider
.
Accounts
.
accounts
[
account
].
privateKey
try
{
try
{
const
rsv
=
ethJSUtil
.
ecsign
(
personalMsg
,
privKey
)
const
rsv
=
ethJSUtil
.
ecsign
(
personalMsg
,
privKey
)
const
signedData
=
ethJSUtil
.
toRpcSig
(
rsv
.
v
,
rsv
.
r
,
rsv
.
s
)
const
signedData
=
ethJSUtil
.
toRpcSig
(
rsv
.
v
,
rsv
.
r
,
rsv
.
s
)
...
...
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