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
bd444d40
Commit
bd444d40
authored
Jan 07, 2020
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move/refactor getBalanceInEther to their own providers
parent
91ae8e36
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
20 deletions
+34
-20
blockchain.js
src/blockchain/blockchain.js
+1
-20
injected.js
src/blockchain/providers/injected.js
+11
-0
node.js
src/blockchain/providers/node.js
+11
-0
vm.js
src/blockchain/providers/vm.js
+11
-0
No files found.
src/blockchain/blockchain.js
View file @
bd444d40
...
@@ -404,26 +404,7 @@ class Blockchain {
...
@@ -404,26 +404,7 @@ class Blockchain {
/** Get the balance of an address, and convert wei to ether */
/** Get the balance of an address, and convert wei to ether */
getBalanceInEther
(
address
,
cb
)
{
getBalanceInEther
(
address
,
cb
)
{
address
=
stripHexPrefix
(
address
)
this
.
getCurrentProvider
().
getBalanceInEther
(
address
,
cb
)
if
(
!
this
.
executionContext
.
isVM
())
{
return
this
.
executionContext
.
web3
().
eth
.
getBalance
(
address
,
(
err
,
res
)
=>
{
if
(
err
)
{
return
cb
(
err
)
}
cb
(
null
,
Web3
.
utils
.
fromWei
(
res
.
toString
(
10
),
'ether'
))
})
}
if
(
!
this
.
providers
.
vm
.
accounts
)
{
return
cb
(
'No accounts?'
)
}
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
(
err
,
res
)
=>
{
if
(
err
)
{
return
cb
(
'Account not found'
)
}
cb
(
null
,
Web3
.
utils
.
fromWei
(
new
BN
(
res
.
balance
).
toString
(
10
),
'ether'
))
})
}
}
pendingTransactionsCount
()
{
pendingTransactionsCount
()
{
...
...
src/blockchain/providers/injected.js
View file @
bd444d40
const
Web3
=
require
(
'web3'
)
class
InjectedProvider
{
class
InjectedProvider
{
...
@@ -11,6 +12,16 @@ class InjectedProvider {
...
@@ -11,6 +12,16 @@ class InjectedProvider {
resetEnvironment
()
{
resetEnvironment
()
{
}
}
getBalanceInEther
(
address
,
cb
)
{
address
=
stripHexPrefix
(
address
)
this
.
executionContext
.
web3
().
eth
.
getBalance
(
address
,
(
err
,
res
)
=>
{
if
(
err
)
{
return
cb
(
err
)
}
cb
(
null
,
Web3
.
utils
.
fromWei
(
res
.
toString
(
10
),
'ether'
))
})
}
}
}
module
.
exports
=
InjectedProvider
module
.
exports
=
InjectedProvider
src/blockchain/providers/node.js
View file @
bd444d40
const
Web3
=
require
(
'web3'
)
class
NodeProvider
{
class
NodeProvider
{
...
@@ -15,6 +16,16 @@ class NodeProvider {
...
@@ -15,6 +16,16 @@ class NodeProvider {
resetEnvironment
()
{
resetEnvironment
()
{
}
}
getBalanceInEther
(
address
,
cb
)
{
address
=
stripHexPrefix
(
address
)
this
.
executionContext
.
web3
().
eth
.
getBalance
(
address
,
(
err
,
res
)
=>
{
if
(
err
)
{
return
cb
(
err
)
}
cb
(
null
,
Web3
.
utils
.
fromWei
(
res
.
toString
(
10
),
'ether'
))
})
}
}
}
module
.
exports
=
NodeProvider
module
.
exports
=
NodeProvider
src/blockchain/providers/vm.js
View file @
bd444d40
const
Web3
=
require
(
'web3'
)
const
{
privateToAddress
,
toChecksumAddress
}
=
require
(
'ethereumjs-util'
)
const
{
privateToAddress
,
toChecksumAddress
}
=
require
(
'ethereumjs-util'
)
class
VMProvider
{
class
VMProvider
{
...
@@ -42,6 +43,16 @@ class VMProvider {
...
@@ -42,6 +43,16 @@ class VMProvider {
this
.
accounts
[
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
this
.
accounts
[
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
))]
=
{
privateKey
,
nonce
:
0
}
}
}
getBalanceInEther
(
address
,
cb
)
{
address
=
stripHexPrefix
(
address
)
this
.
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
address
,
'hex'
),
(
err
,
res
)
=>
{
if
(
err
)
{
return
cb
(
'Account not found'
)
}
cb
(
null
,
Web3
.
utils
.
fromWei
(
new
BN
(
res
.
balance
).
toString
(
10
),
'ether'
))
})
}
}
}
module
.
exports
=
VMProvider
module
.
exports
=
VMProvider
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