forked from nordicenergy/guardian-proof-of-stake-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountCurrencyBalance.java
103 lines (87 loc) · 3.64 KB
/
AccountCurrencyBalance.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright © 2013-2016 The Nxt Core Developers.
* Copyright © 2016-2019 Jelurida IP B.V.
*
* See the LICENSE.txt file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE.txt file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
package nxt;
import nxt.account.Account;
import nxt.blockchain.Chain;
import nxt.crypto.Crypto;
import nxt.util.Convert;
public class AccountCurrencyBalance {
private long accountId;
private long unconfirmedBalance;
private long balance;
private long unconfirmedCurrencyUnits;
private long currencyUnits;
public AccountCurrencyBalance(long unconfirmedBalance, long balance, long unconfirmedCurrencyUnits, long currencyUnits) {
this.unconfirmedBalance = unconfirmedBalance;
this.balance = balance;
this.unconfirmedCurrencyUnits = unconfirmedCurrencyUnits;
this.currencyUnits = currencyUnits;
}
public AccountCurrencyBalance(String secretPhrase, String currency, Chain chain) {
Account account = Account.getAccount(Crypto.getPublicKey(secretPhrase));
assert account != null;
accountId = account.getId();
this.unconfirmedBalance = chain.getBalanceHome().getBalance(accountId).getUnconfirmedBalance();
this.balance = chain.getBalanceHome().getBalance(accountId).getBalance();
long currencyId = Convert.parseUnsignedLong(currency);
this.unconfirmedCurrencyUnits = account.getUnconfirmedCurrencyUnits(currencyId);
this.currencyUnits = account.getCurrencyUnits(currencyId);
}
public long getAccountId() {
return accountId;
}
public long getUnconfirmedCurrencyUnits() {
return unconfirmedCurrencyUnits;
}
public long getCurrencyUnits() {
return currencyUnits;
}
public AccountCurrencyBalance diff(AccountCurrencyBalance other) {
return new AccountCurrencyBalance(unconfirmedBalance - other.unconfirmedBalance,
balance - other.balance,
unconfirmedCurrencyUnits - other.unconfirmedCurrencyUnits,
currencyUnits - other.currencyUnits);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccountCurrencyBalance that = (AccountCurrencyBalance) o;
if (balance != that.balance) return false;
if (currencyUnits != that.currencyUnits) return false;
if (unconfirmedBalance != that.unconfirmedBalance) return false;
//noinspection RedundantIfStatement
if (unconfirmedCurrencyUnits != that.unconfirmedCurrencyUnits) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (unconfirmedBalance ^ (unconfirmedBalance >>> 32));
result = 31 * result + (int) (balance ^ (balance >>> 32));
result = 31 * result + (int) (unconfirmedCurrencyUnits ^ (unconfirmedCurrencyUnits >>> 32));
result = 31 * result + (int) (currencyUnits ^ (currencyUnits >>> 32));
return result;
}
@Override
public String toString() {
return "AccountCurrencyBalance{" +
"unconfirmedBalance=" + unconfirmedBalance +
", balance=" + balance +
", unconfirmedCurrencyUnits=" + unconfirmedCurrencyUnits +
", currencyUnits=" + currencyUnits +
'}';
}
}