Created
March 28, 2018 09:13
-
-
Save josemmo/be3ba7e62729bba8d822ad93c06e5563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public float getBalance(PublicKey addr) { | |
float balance = 0; | |
for (Block b : chain) { | |
// Añadir saldo de transacciones | |
for (Transaction t : b.getTransactions()) { | |
if (addr.equals(t.getFrom())) { | |
// En caso de ser el pagador | |
balance -= t.getAmount(); | |
} else if (addr.equals(t.getTo())) { | |
// En caso de ser el receptor | |
balance += t.getAmount(); | |
} | |
} | |
// Añadir saldo de comisiones | |
if (addr.equals(b.getMiner())) { | |
balance += b.getFee(); | |
} | |
} | |
return balance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment