diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 3651085870..91a261d3a5 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -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' diff --git a/p2p/protocols/accounting_api.go b/p2p/protocols/accounting_api.go index b6a29f1148..48e2af9fea 100644 --- a/p2p/protocols/accounting_api.go +++ b/p2p/protocols/accounting_api.go @@ -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 {