add account balance to rpc

This commit is contained in:
Jerzy 2018-12-19 11:35:32 +01:00
parent 5875394cab
commit ef66beb5cc
2 changed files with 13 additions and 0 deletions

View file

@ -698,6 +698,10 @@ const Account_JS = `
web3._extend({
property: 'account',
methods: [
new web3._extend.Property({
name: 'balance',
getter: 'account_balance'
}),
new web3._extend.Property({
name: 'balanceCredit',
getter: 'account_balanceCredit'

View file

@ -20,6 +20,15 @@ func NewAccountingApi(m *AccountingMetrics) *AccountingApi {
return &AccountingApi{m}
}
// Balance returns local node balance (units credited - units debited)
func (self *AccountingApi) Balance() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
balance := mBalanceCredit.Count() - mBalanceDebit.Count()
return balance, nil
}
// BalanceCredit returns total amount of units credited by local node
func (self *AccountingApi) BalanceCredit() (int64, error) {
if self.metrics == nil {