MCPcopy
hub / github.com/Savjee/SavjeeCoin / getBalanceOfAddress

Method getBalanceOfAddress

src/blockchain.js:252–269  ·  view source on GitHub ↗

* Returns the balance of a given wallet address. * * @param {string} address * @returns {number} The balance of the wallet

(address)

Source from the content-addressed store, hash-verified

250 * @returns {number} The balance of the wallet
251 */
252 getBalanceOfAddress(address) {
253 let balance = 0;
254
255 for (const block of this.chain) {
256 for (const trans of block.transactions) {
257 if (trans.fromAddress === address) {
258 balance -= trans.amount;
259 }
260
261 if (trans.toAddress === address) {
262 balance += trans.amount;
263 }
264 }
265 }
266
267 debug('getBalanceOfAdrees: %s', balance);
268 return balance;
269 }
270
271 /**
272 * Returns a list of all transactions that happened

Callers 3

addTransactionMethod · 0.95
main.jsFile · 0.80
blockchain.test.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected