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
0e1005c5
Commit
0e1005c5
authored
Jul 07, 2020
by
aniket-engg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run-many commands and minor changes
parent
3b16870f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
103 deletions
+106
-103
accounts.js
libs/remix-simulator/src/methods/accounts.js
+104
-101
package.json
package.json
+1
-1
tsconfig.json
tsconfig.json
+1
-1
No files found.
libs/remix-simulator/src/methods/accounts.js
View file @
0e1005c5
...
@@ -3,125 +3,128 @@ const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util')
...
@@ -3,125 +3,128 @@ const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util')
const
Web3
=
require
(
'web3'
)
const
Web3
=
require
(
'web3'
)
const
crypto
=
require
(
'crypto'
)
const
crypto
=
require
(
'crypto'
)
const
Accounts
=
function
(
executionContext
)
{
class
Accounts
{
this
.
web3
=
new
Web3
()
this
.
executionContext
=
executionContext
constructor
(
executionContext
)
{
// TODO: make it random and/or use remix-libs
this
.
web3
=
new
Web3
()
this
.
accountsList
=
[
this
.
executionContext
=
executionContext
this
.
web3
.
eth
.
accounts
.
create
([
'abcd'
]),
// TODO: make it random and/or use remix-libs
this
.
web3
.
eth
.
accounts
.
create
([
'ef12'
]),
this
.
accountsList
=
[
this
.
web3
.
eth
.
accounts
.
create
([
'ef34'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'abcd'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ab12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ef12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ab34'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ef34'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'cd12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ab12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'cd34'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'ab34'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'bcde'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'cd12'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'cdef'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'cd34'
]),
this
.
web3
.
eth
.
accounts
.
create
([
'1234'
])
this
.
web3
.
eth
.
accounts
.
create
([
'bcde'
]),
]
this
.
web3
.
eth
.
accounts
.
create
([
'cdef'
]),
this
.
accounts
=
{}
this
.
web3
.
eth
.
accounts
.
create
([
'1234'
])
this
.
accountsKeys
=
{}
]
this
.
accounts
=
{}
this
.
executionContext
.
init
({
get
:
()
=>
{
return
true
}})
this
.
accountsKeys
=
{}
}
this
.
executionContext
.
init
({
get
:
()
=>
{
return
true
}})
}
Accounts
.
prototype
.
init
=
async
function
()
{
async
init
()
{
let
setBalance
=
(
account
)
=>
{
let
setBalance
=
(
account
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
account
.
privateKey
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
account
.
privateKey
this
.
accounts
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
{
privateKey
:
Buffer
.
from
(
account
.
privateKey
.
replace
(
'0x'
,
''
),
'hex'
),
nonce
:
0
}
this
.
accounts
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
{
privateKey
:
Buffer
.
from
(
account
.
privateKey
.
replace
(
'0x'
,
''
),
'hex'
),
nonce
:
0
}
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
account
.
address
.
replace
(
'0x'
,
''
),
'hex'
),
(
err
,
account
)
=>
{
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
account
.
address
.
replace
(
'0x'
,
''
),
'hex'
),
(
err
,
account
)
=>
{
if
(
err
)
{
if
(
err
)
{
throw
new
Error
(
err
)
throw
new
Error
(
err
)
}
}
const
balance
=
'0x56BC75E2D63100000'
const
balance
=
'0x56BC75E2D63100000'
account
.
balance
=
balance
||
'0xf00000000000000001'
account
.
balance
=
balance
||
'0xf00000000000000001'
resolve
()
resolve
()
})
})
})
})
}
}
for
(
let
_account
of
this
.
accountsList
)
{
for
(
let
_account
of
this
.
accountsList
)
{
await
setBalance
(
_account
)
await
setBalance
(
_account
)
}
}
}
}
Accounts
.
prototype
.
resetAccounts
=
function
()
{
resetAccounts
()
{
// TODO: setting this to {} breaks the app currently, unclear why still
// TODO: setting this to {} breaks the app currently, unclear why still
// this.accounts = {}
// this.accounts = {}
// this.accountsKeys = {}
// this.accountsKeys = {}
this
.
_addAccount
(
'3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'd74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'd74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce'
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
'71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce'
,
'0x56BC75E2D63100000'
)
}
}
Accounts
.
prototype
.
_addAccount
=
function
(
privateKey
,
balance
)
{
_addAccount
(
privateKey
,
balance
)
{
privateKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
privateKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
const
address
=
ethJSUtil
.
privateToAddress
(
privateKey
)
const
address
=
ethJSUtil
.
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
[
ethJSUtil
.
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
this
.
accounts
[
ethJSUtil
.
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
'0x'
+
privateKey
.
toString
(
'hex'
)
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
'0x'
+
privateKey
.
toString
(
'hex'
)
}
}
Accounts
.
prototype
.
newAccount
=
function
(
cb
)
{
newAccount
(
cb
)
{
let
privateKey
let
privateKey
do
{
do
{
privateKey
=
crypto
.
randomBytes
(
32
)
privateKey
=
crypto
.
randomBytes
(
32
)
}
while
(
!
isValidPrivate
(
privateKey
))
}
while
(
!
isValidPrivate
(
privateKey
))
this
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
this
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
return
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
return
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
}
}
Accounts
.
prototype
.
methods
=
function
()
{
methods
()
{
return
{
return
{
eth_accounts
:
this
.
eth_accounts
.
bind
(
this
),
eth_accounts
:
this
.
eth_accounts
.
bind
(
this
),
eth_getBalance
:
this
.
eth_getBalance
.
bind
(
this
),
eth_getBalance
:
this
.
eth_getBalance
.
bind
(
this
),
eth_sign
:
this
.
eth_sign
.
bind
(
this
)
eth_sign
:
this
.
eth_sign
.
bind
(
this
)
}
}
}
}
Accounts
.
prototype
.
eth_accounts
=
function
(
_payload
,
cb
)
{
eth_accounts
(
_payload
,
cb
)
{
return
cb
(
null
,
Object
.
keys
(
this
.
accounts
))
return
cb
(
null
,
Object
.
keys
(
this
.
accounts
))
}
}
Accounts
.
prototype
.
eth_getBalance
=
function
(
payload
,
cb
)
{
eth_getBalance
(
payload
,
cb
)
{
let
address
=
payload
.
params
[
0
]
let
address
=
payload
.
params
[
0
]
address
=
ethJSUtil
.
stripHexPrefix
(
address
)
address
=
ethJSUtil
.
stripHexPrefix
(
address
)
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
(
err
,
account
)
=>
{
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
(
err
,
account
)
=>
{
if
(
err
)
{
if
(
err
)
{
return
cb
(
err
)
return
cb
(
err
)
}
}
cb
(
null
,
new
BN
(
account
.
balance
).
toString
(
10
))
cb
(
null
,
new
BN
(
account
.
balance
).
toString
(
10
))
})
})
}
}
Accounts
.
prototype
.
eth_sign
=
functio
n
(
payload
,
cb
)
{
eth_sig
n
(
payload
,
cb
)
{
const
address
=
payload
.
params
[
0
]
const
address
=
payload
.
params
[
0
]
const
message
=
payload
.
params
[
1
]
const
message
=
payload
.
params
[
1
]
const
privateKey
=
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
address
)]
const
privateKey
=
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
address
)]
if
(
!
privateKey
)
{
if
(
!
privateKey
)
{
return
cb
(
new
Error
(
'unknown account'
))
return
cb
(
new
Error
(
'unknown account'
))
}
}
const
account
=
this
.
web3
.
eth
.
accounts
.
privateKeyToAccount
(
privateKey
)
const
account
=
this
.
web3
.
eth
.
accounts
.
privateKeyToAccount
(
privateKey
)
const
data
=
account
.
sign
(
message
)
const
data
=
account
.
sign
(
message
)
cb
(
null
,
data
.
signature
)
cb
(
null
,
data
.
signature
)
}
}
}
module
.
exports
=
Accounts
module
.
exports
=
Accounts
package.json
View file @
0e1005c5
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
"start"
:
"nx start"
,
"start"
:
"nx start"
,
"serve"
:
"nx serve"
,
"serve"
:
"nx serve"
,
"build"
:
"nx build"
,
"build"
:
"nx build"
,
"build:
tslibs"
:
"nx run-many --target=build --projects=remix-analyzer,remix-astwalke
r,remix-solidity,remix-tests,remix-url-resolver"
,
"build:
libs"
:
"nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulato
r,remix-solidity,remix-tests,remix-url-resolver"
,
"test"
:
"nx test"
,
"test"
:
"nx test"
,
"test:libs"
:
"nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver"
,
"test:libs"
:
"nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver"
,
"lint"
:
"nx lint"
,
"lint"
:
"nx lint"
,
...
...
tsconfig.json
View file @
0e1005c5
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
"@remix-project/remix-analyzer"
:
[
"libs/remix-analyzer/index.ts"
],
"@remix-project/remix-analyzer"
:
[
"libs/remix-analyzer/index.ts"
],
"@remix-project/remix-astwalker"
:
[
"libs/remix-astwalker/src/index.ts"
],
"@remix-project/remix-astwalker"
:
[
"libs/remix-astwalker/src/index.ts"
],
"@remix-project/remix-debug"
:
[
"libs/remix-debug/index.js"
],
"@remix-project/remix-debug"
:
[
"libs/remix-debug/index.js"
],
"@remix-project/remix-lib"
:
[
"
dist/
libs/remix-lib/index.js"
],
"@remix-project/remix-lib"
:
[
"libs/remix-lib/index.js"
],
"@remix-project/remix-simulator"
:
[
"libs/remix-simulator/index.js"
],
"@remix-project/remix-simulator"
:
[
"libs/remix-simulator/index.js"
],
"@remix-project/remix-solidity"
:
[
"libs/remix-solidity/src/index.ts"
],
"@remix-project/remix-solidity"
:
[
"libs/remix-solidity/src/index.ts"
],
"@remix-project/remix-tests"
:
[
"libs/remix-tests/src/index.ts"
],
"@remix-project/remix-tests"
:
[
"libs/remix-tests/src/index.ts"
],
...
...
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