use client_error::ClientError;
use data::{ImmutableData, MutableData, PermissionSet, User, Value};
use rust_sodium::crypto::sign;
use std::collections::{BTreeMap, BTreeSet};
use types::MessageId as MsgId;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum Response {
GetAccountInfo {
res: Result<AccountInfo, ClientError>,
msg_id: MsgId,
},
PutIData {
res: Result<(), ClientError>,
msg_id: MsgId,
},
GetIData {
res: Result<ImmutableData, ClientError>,
msg_id: MsgId,
},
PutMData {
res: Result<(), ClientError>,
msg_id: MsgId,
},
GetMData {
res: Result<MutableData, ClientError>,
msg_id: MsgId,
},
GetMDataVersion {
res: Result<u64, ClientError>,
msg_id: MsgId,
},
GetMDataShell {
res: Result<MutableData, ClientError>,
msg_id: MsgId,
},
ListMDataEntries {
res: Result<BTreeMap<Vec<u8>, Value>, ClientError>,
msg_id: MsgId,
},
ListMDataKeys {
res: Result<BTreeSet<Vec<u8>>, ClientError>,
msg_id: MsgId,
},
ListMDataValues {
res: Result<Vec<Value>, ClientError>,
msg_id: MsgId,
},
GetMDataValue {
res: Result<Value, ClientError>,
msg_id: MsgId,
},
MutateMDataEntries {
res: Result<(), ClientError>,
msg_id: MsgId,
},
ListMDataPermissions {
res: Result<BTreeMap<User, PermissionSet>, ClientError>,
msg_id: MsgId,
},
ListMDataUserPermissions {
res: Result<PermissionSet, ClientError>,
msg_id: MsgId,
},
SetMDataUserPermissions {
res: Result<(), ClientError>,
msg_id: MsgId,
},
DelMDataUserPermissions {
res: Result<(), ClientError>,
msg_id: MsgId,
},
ChangeMDataOwner {
res: Result<(), ClientError>,
msg_id: MsgId,
},
ListAuthKeysAndVersion {
res: Result<(BTreeSet<sign::PublicKey>, u64), ClientError>,
msg_id: MsgId,
},
InsAuthKey {
res: Result<(), ClientError>,
msg_id: MsgId,
},
DelAuthKey {
res: Result<(), ClientError>,
msg_id: MsgId,
},
}
impl Response {
pub fn priority(&self) -> u8 {
match *self {
Response::GetIData { res: Ok(_), .. } => 5,
Response::GetMDataValue { res: Ok(_), .. }
| Response::GetMDataShell { res: Ok(_), .. } => 4,
_ => 3,
}
}
pub fn message_id(&self) -> &MsgId {
use Response::*;
match *self {
GetAccountInfo { ref msg_id, .. }
| PutIData { ref msg_id, .. }
| GetIData { ref msg_id, .. }
| PutMData { ref msg_id, .. }
| GetMData { ref msg_id, .. }
| GetMDataVersion { ref msg_id, .. }
| GetMDataShell { ref msg_id, .. }
| ListMDataEntries { ref msg_id, .. }
| ListMDataKeys { ref msg_id, .. }
| ListMDataValues { ref msg_id, .. }
| GetMDataValue { ref msg_id, .. }
| MutateMDataEntries { ref msg_id, .. }
| ListMDataPermissions { ref msg_id, .. }
| ListMDataUserPermissions { ref msg_id, .. }
| SetMDataUserPermissions { ref msg_id, .. }
| DelMDataUserPermissions { ref msg_id, .. }
| ChangeMDataOwner { ref msg_id, .. }
| ListAuthKeysAndVersion { ref msg_id, .. }
| InsAuthKey { ref msg_id, .. }
| DelAuthKey { ref msg_id, .. } => msg_id,
}
}
pub fn is_cacheable(&self) -> bool {
if let Response::GetIData { .. } = *self {
true
} else {
false
}
}
}
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize, Debug)]
pub struct AccountInfo {
pub mutations_done: u64,
pub mutations_available: u64,
}