mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
minor changes
This commit is contained in:
@@ -12,7 +12,7 @@ use drk::crypto::{
|
||||
nullifier::Nullifier,
|
||||
save_params, setup_mint_prover, setup_spend_prover,
|
||||
};
|
||||
use drk::serial::{deserialize, Decodable};
|
||||
use drk::serial::Decodable;
|
||||
use drk::service::{ClientProgramOptions, GatewayClient, Subscriber};
|
||||
use drk::state::{state_transition, ProgramState, StateUpdate};
|
||||
use drk::{tx, Result};
|
||||
@@ -131,16 +131,14 @@ pub async fn subscribe(
|
||||
mut state: State,
|
||||
) -> Result<()> {
|
||||
loop {
|
||||
let slab_data: Vec<u8>;
|
||||
slab_data = subscriber.fetch().await?;
|
||||
|
||||
let slab: Slab = deserialize(&slab_data)?;
|
||||
let slab = subscriber.fetch::<Slab>().await?;
|
||||
let tx = tx::Transaction::decode(&slab.get_payload()[..])?;
|
||||
|
||||
let update = state_transition(&state, tx)?;
|
||||
state.apply(update)?;
|
||||
|
||||
slabstore.put(slab_data)?;
|
||||
slabstore.put(slab)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,12 @@ impl SlabStore {
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn put(&self, value: Vec<u8>) -> Result<Option<u64>> {
|
||||
let slab: Slab = deserialize(&value)?;
|
||||
pub fn put(&self, slab: Slab) -> Result<Option<u64>> {
|
||||
let last_index = self.get_last_index()?;
|
||||
let key = last_index + 1;
|
||||
|
||||
if slab.get_index() == key {
|
||||
self.rocks.put(key.clone(), value)?;
|
||||
self.rocks.put(key.clone(), slab)?;
|
||||
Ok(Some(key))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
@@ -126,7 +126,7 @@ impl GatewayService {
|
||||
let slab = request.get_payload();
|
||||
|
||||
// add to slabstore
|
||||
let error = slabstore.put(slab.clone())?;
|
||||
let error = slabstore.put(deserialize(&slab)?)?;
|
||||
|
||||
let mut reply = Reply::from(&request, GatewayError::NoError as u32, vec![]);
|
||||
|
||||
@@ -228,7 +228,7 @@ impl GatewayClient {
|
||||
.await?;
|
||||
|
||||
if let Some(slab) = rep {
|
||||
self.slabstore.put(slab.clone())?;
|
||||
self.slabstore.put(deserialize(&slab)?)?;
|
||||
return Ok(Some(slab));
|
||||
}
|
||||
Ok(None)
|
||||
|
||||
@@ -249,11 +249,12 @@ impl Subscriber {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn fetch(&mut self) -> Result<Vec<u8>> {
|
||||
pub async fn fetch<T: Decodable>(&mut self) -> Result<T> {
|
||||
let data = self.socket.recv().await?;
|
||||
match data.get(0) {
|
||||
Some(d) => {
|
||||
let data = d.to_vec();
|
||||
let data: T = deserialize(&data)?;
|
||||
Ok(data)
|
||||
}
|
||||
None => Err(crate::Error::ZMQError(
|
||||
|
||||
Reference in New Issue
Block a user