neo3/neo_protocol/responses/
neo_account_state.rs

1use std::hash::{Hash, Hasher};
2
3use crate::{
4	crypto::{PublicKeyExtension, Secp256r1PublicKey},
5	deserialize_public_key_option, serialize_public_key_option,
6};
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
10pub struct AccountState {
11	pub balance: i64,
12	pub balance_height: Option<i64>,
13	#[serde(deserialize_with = "deserialize_public_key_option")]
14	#[serde(serialize_with = "serialize_public_key_option")]
15	pub public_key: Option<Secp256r1PublicKey>,
16}
17
18impl Hash for AccountState {
19	fn hash<H: Hasher>(&self, state: &mut H) {
20		self.balance.hash(state);
21		self.balance_height.hash(state);
22
23		// Only hash the public key if it exists
24		if let Some(public_key) = &self.public_key {
25			public_key.to_vec().hash(state);
26		}
27	}
28}
29
30impl AccountState {
31	pub fn with_no_vote(balance: i64, update_height: i64) -> Self {
32		Self { balance, balance_height: Some(update_height), public_key: None }
33	}
34
35	pub fn with_no_balance() -> Self {
36		Self { balance: 0, balance_height: None, public_key: None }
37	}
38}