Skip to content

Commit

Permalink
Add workchain id to accounts producer data
Browse files Browse the repository at this point in the history
  • Loading branch information
pashinov committed Feb 9, 2024
1 parent ecec407 commit 20bc37d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ impl RpcState {
storage.update(block_id, block, shard_state)?;
}

self.ws_producer.handle_block(block).await?;
self.ws_producer
.handle_block(block_id.shard_id.workchain_id(), block)
.await?;

Ok(())
}
Expand Down
27 changes: 20 additions & 7 deletions server/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use futures_util::{SinkExt, StreamExt};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use tokio::sync::Mutex;
use ton_block::{Deserializable, HashmapAugType};
use ton_types::HashmapType;
use ton_block::{Deserializable, HashmapAugType, MsgAddressInt};
use ton_types::{AccountId, HashmapType};

use crate::server::Server;

Expand Down Expand Up @@ -47,15 +47,15 @@ async fn handle_socket(client_id: uuid::Uuid, state: Arc<Server>, socket: WebSoc

#[derive(Default)]
pub struct WsProducer {
clients: Mutex<FxHashMap<uuid::Uuid, SplitSink<WebSocket, axum::extract::ws::Message>>>,
clients: Mutex<FxHashMap<uuid::Uuid, SplitSink<WebSocket, Message>>>,
}

impl WsProducer {
pub async fn handle_block(&self, block: &ton_block::Block) -> Result<()> {
pub async fn handle_block(&self, workchain_id: i32, block: &ton_block::Block) -> Result<()> {
let extra = block.read_extra()?;
let account_blocks = extra.read_account_blocks()?;

let mut accounts = FxHashMap::default();
let mut accounts = Vec::with_capacity(account_blocks.len()?);
account_blocks.iterate_with_keys(|account, value| {
let mut lt = 0;
value.transactions().iterate_slices(|_, mut value| {
Expand All @@ -67,18 +67,31 @@ impl WsProducer {

Ok(true)
})?;
accounts.insert(account.into_vec(), lt);

let address =
MsgAddressInt::with_standart(None, workchain_id as i8, AccountId::from(account))?;

accounts.push(AccountInfo {
account: nekoton_proto::utils::addr_to_bytes(&address).to_vec(),
account_lt: lt,
});

Ok(true)
})?;

let message = bincode::serialize(&accounts)?;
let mut clients = self.clients.lock().await;
for (_, client) in clients.iter_mut() {
let message = axum::extract::ws::Message::Binary(message.clone());
let message = Message::Binary(message.clone());
client.send(message).await?;
}

Ok(())
}
}

#[derive(Clone, Serialize, Deserialize)]
struct AccountInfo {
pub account: Vec<u8>,
pub account_lt: u64,
}

0 comments on commit 20bc37d

Please sign in to comment.