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
/*use actix_web::web::Data;
use async_trait::async_trait;
use autonomi::{ScratchpadAddress, SecretKey};
use bytes::Bytes;
use indexmap::IndexMap;
use log::{debug, info};
use sha2::Digest;
use tokio::sync::Mutex;
use crate::client::client_harness::ClientHarness;
use crate::client::command::error::CommandError;
use crate::client::command::Command;
pub struct UpdatePrivateScratchpadCommand {
id: u128,
client_harness: Data<Mutex<ClientHarness>>,
owner: SecretKey,
content_type: u64,
data: Bytes,
}
impl UpdatePrivateScratchpadCommand {
pub fn new(client_harness: Data<Mutex<ClientHarness>>, owner: SecretKey, content_type: u64, data: Bytes) -> Self {
let id = rand::random::<u128>();
Self { id, client_harness, owner, content_type, data }
}
}
const STRUCT_NAME: &'static str = "UpdatePrivateScratchpadCommand";
#[async_trait]
impl Command for UpdatePrivateScratchpadCommand {
async fn execute(&self) -> Result<(), CommandError> {
let client = self.client_harness.get_ref().lock().await.get_client().await?;
let scratchpad_address_hex = ScratchpadAddress::new(self.owner.public_key()).to_hex();
debug!("updating private scratchpad at [{}] async", scratchpad_address_hex);
client.scratchpad_update(&self.owner, self.content_type, &self.data).await?;
info!("private scratchpad at address [{}] updated successfully", scratchpad_address_hex);
Ok(())
}
fn action_hash(&self) -> Vec<u8> {
let mut hasher = sha2::Sha256::new();
hasher.update(STRUCT_NAME);
hasher.update(self.owner.to_hex());
hasher.update(self.content_type.to_string());
hasher.update(self.data.clone());
hasher.finalize().to_ascii_lowercase()
}
fn id(&self) -> u128 {
self.id
}
fn name(&self) -> String {
STRUCT_NAME.to_string()
}
fn properties(&self) -> IndexMap<String, String> {
let mut properties = IndexMap::new();
properties.insert("owner".to_string(), self.owner.to_hex());
properties.insert("content_type".to_string(), self.content_type.to_string());
properties.insert("data".to_string(), "tbc".to_string()); // todo: improve
properties
}
}*/