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
4ce1ecd4
Commit
4ce1ecd4
authored
Jan 07, 2020
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move createvmaccount and newaccount to their own providers
parent
bd444d40
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
19 deletions
+34
-19
blockchain.js
src/blockchain/blockchain.js
+3
-19
injected.js
src/blockchain/providers/injected.js
+6
-0
node.js
src/blockchain/providers/node.js
+9
-0
vm.js
src/blockchain/providers/vm.js
+16
-0
No files found.
src/blockchain/blockchain.js
View file @
4ce1ecd4
...
@@ -375,31 +375,15 @@ class Blockchain {
...
@@ -375,31 +375,15 @@ class Blockchain {
* Create a VM Account
* Create a VM Account
* @param {{privateKey: string, balance: string}} newAccount The new account to create
* @param {{privateKey: string, balance: string}} newAccount The new account to create
*/
*/
createVMAccount
(
newAccount
)
{
createVMAccount
(
newAccount
)
{
const
{
privateKey
,
balance
}
=
newAccount
if
(
this
.
executionContext
.
getProvider
()
!==
'vm'
)
{
if
(
this
.
executionContext
.
getProvider
()
!==
'vm'
)
{
throw
new
Error
(
'plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed'
)
throw
new
Error
(
'plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed'
)
}
}
this
.
providers
.
vm
.
_addAccount
(
privateKey
,
balance
)
return
this
.
providers
.
vm
.
createVMAccount
(
newAccount
)
const
privKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
return
'0x'
+
privateToAddress
(
privKey
).
toString
(
'hex'
)
}
}
newAccount
(
_password
,
passwordPromptCb
,
cb
)
{
newAccount
(
_password
,
passwordPromptCb
,
cb
)
{
if
(
this
.
executionContext
.
isVM
())
{
return
this
.
getCurrentProvider
().
newAccount
(
passwordPromptCb
,
cb
)
let
privateKey
do
{
privateKey
=
crypto
.
randomBytes
(
32
)
}
while
(
!
isValidPrivate
(
privateKey
))
this
.
providers
.
vm
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
return
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
}
if
(
!
this
.
config
.
get
(
'settings/personal-mode'
))
{
return
cb
(
'Not running in personal mode'
)
}
passwordPromptCb
((
passphrase
)
=>
{
this
.
executionContext
.
web3
().
personal
.
newAccount
(
passphrase
,
cb
)
})
}
}
/** Get the balance of an address, and convert wei to ether */
/** Get the balance of an address, and convert wei to ether */
...
...
src/blockchain/providers/injected.js
View file @
4ce1ecd4
...
@@ -10,6 +10,12 @@ class InjectedProvider {
...
@@ -10,6 +10,12 @@ class InjectedProvider {
return
this
.
executionContext
.
web3
().
eth
.
getAccounts
(
cb
)
return
this
.
executionContext
.
web3
().
eth
.
getAccounts
(
cb
)
}
}
newAccount
(
passwordPromptCb
,
cb
)
{
passwordPromptCb
((
passphrase
)
=>
{
this
.
executionContext
.
web3
().
personal
.
newAccount
(
passphrase
,
cb
)
})
}
resetEnvironment
()
{
resetEnvironment
()
{
}
}
...
...
src/blockchain/providers/node.js
View file @
4ce1ecd4
...
@@ -14,6 +14,15 @@ class NodeProvider {
...
@@ -14,6 +14,15 @@ class NodeProvider {
return
this
.
executionContext
.
web3
().
eth
.
getAccounts
(
cb
)
return
this
.
executionContext
.
web3
().
eth
.
getAccounts
(
cb
)
}
}
newAccount
(
passwordPromptCb
,
cb
)
{
if
(
!
this
.
config
.
get
(
'settings/personal-mode'
))
{
return
cb
(
'Not running in personal mode'
)
}
passwordPromptCb
((
passphrase
)
=>
{
this
.
executionContext
.
web3
().
personal
.
newAccount
(
passphrase
,
cb
)
})
}
resetEnvironment
()
{
resetEnvironment
()
{
}
}
...
...
src/blockchain/providers/vm.js
View file @
4ce1ecd4
...
@@ -43,6 +43,22 @@ class VMProvider {
...
@@ -43,6 +43,22 @@ class VMProvider {
this
.
accounts
[
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
this
.
accounts
[
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
}
}
createVMAccount
(
passwordPromptCb
,
cb
)
{
const
{
privateKey
,
balance
}
=
newAccount
this
.
_addAccount
(
privateKey
,
balance
)
const
privKey
=
Buffer
.
from
(
privateKey
,
'hex'
)
return
'0x'
+
privateToAddress
(
privKey
).
toString
(
'hex'
)
}
newAccount
(
_passwordPromptCb
,
cb
)
{
let
privateKey
do
{
privateKey
=
crypto
.
randomBytes
(
32
)
}
while
(
!
isValidPrivate
(
privateKey
))
this
.
providers
.
vm
.
_addAccount
(
privateKey
,
'0x56BC75E2D63100000'
)
return
cb
(
null
,
'0x'
+
privateToAddress
(
privateKey
).
toString
(
'hex'
))
}
getBalanceInEther
(
address
,
cb
)
{
getBalanceInEther
(
address
,
cb
)
{
address
=
stripHexPrefix
(
address
)
address
=
stripHexPrefix
(
address
)
...
...
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